-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffset_test.go
More file actions
72 lines (56 loc) · 1.79 KB
/
Copy pathoffset_test.go
File metadata and controls
72 lines (56 loc) · 1.79 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package time_test
import (
"testing"
"github.com/tinywasm/time"
)
func TestTimeZoneOffset(t *testing.T) {
// Default should be detected or 0
initial := time.GetTimeZoneOffset()
t.Logf("Initial detected offset: %d", initial)
// Set manual offset
time.SetTimeZoneOffset(-3)
if time.GetTimeZoneOffset() != -3 {
t.Errorf("SetTimeZoneOffset(-3) failed, got %d", time.GetTimeZoneOffset())
}
time.SetTimeZoneOffset(5)
if time.GetTimeZoneOffset() != 5 {
t.Errorf("SetTimeZoneOffset(5) failed, got %d", time.GetTimeZoneOffset())
}
// Restore something reasonable
time.SetTimeZoneOffset(0)
}
func TestFormatWithOffset(t *testing.T) {
// 2021-01-01 00:00:00 UTC
nano := int64(1609459200 * 1000000000)
// In UTC
time.SetTimeZoneOffset(0)
if time.FormatTime(nano) != "00:00:00" {
t.Errorf("FormatTime(UTC) = %s, want 00:00:00", time.FormatTime(nano))
}
// In UTC-3
time.SetTimeZoneOffset(-3)
if time.FormatTime(nano) != "21:00:00" {
t.Errorf("FormatTime(UTC-3) = %s, want 21:00:00", time.FormatTime(nano))
}
// In UTC+1
time.SetTimeZoneOffset(1)
if time.FormatTime(nano) != "01:00:00" {
t.Errorf("FormatTime(UTC+1) = %s, want 01:00:00", time.FormatTime(nano))
}
}
func TestIsTodayWithOffset(t *testing.T) {
// Near midnight UTC
// 2021-01-02 01:00:00 UTC
nano := int64(1609549200 * 1000000000)
// If it's 2021-01-02 01:00:00 UTC
// In UTC-3 it's 2021-01-01 22:00:00 (Previous day)
// We need a reference "now" to test IsToday, but Now() changes.
// So we'll just verify FormatDate behaves correctly for today's logic.
time.SetTimeZoneOffset(0)
dateUTC := time.FormatDate(nano)
time.SetTimeZoneOffset(-3)
dateLocal := time.FormatDate(nano)
if dateUTC == dateLocal {
t.Errorf("FormatDate should differ near midnight UTC with offset: UTC=%s, UTC-3=%s", dateUTC, dateLocal)
}
}