Skip to content

Commit 31d7544

Browse files
committed
Fix BeiDou time
1 parent 2bbc360 commit 31d7544

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

rtcm3/time.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func DF004(e uint32) time.Time {
1313
}
1414

1515
func DF004Time(e uint32, start time.Time) time.Time {
16+
// TODO: GpsLeapSeconds should take a time to return leap seconds as at that time
1617
start = start.Add(rtcm.GpsLeapSeconds()) // UTC to GPS time
1718
sow := start.Truncate(time.Hour*24).AddDate(0, 0, -int(start.Weekday()))
1819
tow := time.Duration(e) * time.Millisecond
@@ -21,10 +22,10 @@ func DF004Time(e uint32, start time.Time) time.Time {
2122

2223
// BeiDou Epoch Time (TOW)
2324
func DF427(e uint32, start time.Time) time.Time {
24-
start = start.Add(rtcm.GpsLeapSeconds()) // UTC to GPS time
25-
sow := start.Truncate(time.Hour*24).AddDate(0, 0, -int(start.Weekday())).Add(-14 * time.Second)
25+
start = start.Add(rtcm.GpsLeapSeconds() - 14*time.Second) // UTC to GPS time
26+
sow := start.Truncate(time.Hour*24).AddDate(0, 0, -int(start.Weekday()))
2627
tow := time.Duration(e) * time.Millisecond
27-
return sow.Add(-(rtcm.GpsLeapSeconds())).Add(tow)
28+
return sow.Add(-(rtcm.GpsLeapSeconds())).Add(tow + 14*time.Second)
2829
}
2930

3031
// GPS Epoch Time 1s

rtcm3/time_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ func TestDF034(t *testing.T) {
2020
}
2121
}
2222

23+
func TestDF427(t *testing.T) {
24+
refTimeG0 := time.Date(2023, 2, 25, 23, 59, 42, 0, time.UTC)
25+
if time := rtcm3.DF427(604786000, refTimeG0); time != refTimeG0 {
26+
t.Errorf("DF427 time incorrect at GPS 0: %v, expected %v", time, refTimeG0)
27+
}
28+
29+
refTimeB0 := time.Date(2023, 2, 25, 23, 59, 56, 0, time.UTC)
30+
if time := rtcm3.DF427(0, refTimeB0); time != refTimeB0 {
31+
t.Errorf("DF427 time incorrect at BeiDou 0: %v, expected %v", time, refTimeB0)
32+
}
33+
34+
refTimeX := time.Date(2019, 2, 8, 00, 44, 44, 0, time.UTC)
35+
if time := rtcm3.DF034(13484000, refTimeX); time != refTimeX {
36+
t.Errorf("DF427 time incorrect: %v, expected %v", time, refTimeX)
37+
}
38+
}
39+
2340
func TestGlonassTimeMSM(t *testing.T) {
2441
midweek := time.Date(2019, 3, 28, 4, 2, 9, 0, time.UTC)
2542
if time := rtcm3.GlonassTimeMSM(562199912, midweek); time != midweek {

0 commit comments

Comments
 (0)