mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [datetime] use local zone for zero hour timestamps (#415)
* fix(package): [datetime] use local zone for zero hour timestamps * test(package): [datetime] cover zero hour timestamps in other zones
This commit is contained in:
1 parent
b09d6af4a4
commit
5839ab33a9
2 files changed
+27
-4
No files matched your search
@@ -943,3 +943,28 @@ func TestBetweenSeconds(t *testing.T) {
|
||||
assert.Equal(int64(86400), result1)
|
||||
assert.Equal(int64(-86400), result2)
|
||||
}
|
||||
|
||||
func TestGetZeroHourAndNightTimestampLocalZone(t *testing.T) {
|
||||
// not parallel: this test replaces time.Local
|
||||
assert := internal.NewAssert(t, "TestGetZeroHourAndNightTimestampLocalZone")
|
||||
|
||||
oldLocal := time.Local
|
||||
defer func() { time.Local = oldLocal }()
|
||||
|
||||
for _, offset := range []int{-5 * 3600, 0, 8 * 3600, 9 * 3600} {
|
||||
time.Local = time.FixedZone("test", offset)
|
||||
|
||||
before := time.Now()
|
||||
zero := GetZeroHourTimestamp()
|
||||
night := GetNightTimestamp()
|
||||
after := time.Now()
|
||||
|
||||
if before.Day() != after.Day() {
|
||||
continue
|
||||
}
|
||||
|
||||
assert.Equal(BeginOfDay(before).Unix(), zero)
|
||||
assert.Equal(EndOfDay(before).Unix(), night)
|
||||
assert.Equal(int64(86399), night-zero)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user