2026-05-01 22:38:44 +08:00
|
|
|
package basic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"math"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2026-09-23 18:55:12 +08:00
|
|
|
func TestGetNowJDUsesSingleTimestamp(t *testing.T) {
|
2026-05-01 22:38:44 +08:00
|
|
|
oldTimeNow := timeNow
|
|
|
|
|
defer func() {
|
|
|
|
|
timeNow = oldTimeNow
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
calls := 0
|
|
|
|
|
first := time.Date(2026, 4, 29, 23, 59, 59, 0, time.FixedZone("CST", 8*3600))
|
|
|
|
|
second := first.Add(2 * time.Second)
|
|
|
|
|
timeNow = func() time.Time {
|
|
|
|
|
calls++
|
|
|
|
|
if calls == 1 {
|
|
|
|
|
return first
|
|
|
|
|
}
|
|
|
|
|
return second
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-23 18:55:12 +08:00
|
|
|
got := GetNowJD()
|
|
|
|
|
want := Date2JD(first)
|
2026-05-01 22:38:44 +08:00
|
|
|
if calls != 1 {
|
2026-09-23 18:55:12 +08:00
|
|
|
t.Fatalf("GetNowJD should read current time once, got %d calls", calls)
|
2026-05-01 22:38:44 +08:00
|
|
|
}
|
|
|
|
|
if math.Float64bits(got) != math.Float64bits(want) {
|
2026-09-23 18:55:12 +08:00
|
|
|
t.Fatalf("GetNowJD mismatch: got %.15f want %.15f", got, want)
|
2026-05-01 22:38:44 +08:00
|
|
|
}
|
|
|
|
|
}
|