-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgps_time.go
43 lines (34 loc) · 969 Bytes
/
gps_time.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package timex
import (
"time"
)
// A GpsTime represents an instant in time with nanosecond precision.
type GpsTime time.Time
// Gps returns the local Time corresponding to the given GPS offset.
func Gps(offset time.Duration) GpsTime {
return GpsTime(toUtcTime(offset))
}
// Gps returns t as a GPS time, a Duration from GPS epoch.
func (t GpsTime) Gps() time.Duration {
value := toGpsTime(time.Time(t))
return time.Duration(value)
}
func (t GpsTime) String() string {
return time.Time(t).String()
}
// ToUTC returns t as a time.Time in UTC.
func (t GpsTime) ToUTC() time.Time {
return toUtcTime(t.Gps())
}
// Add returns the time t+d.
func (t GpsTime) Add(d time.Duration) GpsTime {
return Gps(t.Gps() + d)
}
// Sub returns the duration t-u.
func (t GpsTime) Sub(u GpsTime) time.Duration {
return t.Gps() - u.Gps()
}
// Equal reports whether t and u represent the same time instant.
func (t GpsTime) Equal(u GpsTime) bool {
return t.Gps() == u.Gps()
}