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
| package test
import (
"testing"
"time"
)
func TestCompareTime(t *testing.T) {
at := time.Now()
t1, t2 := "2023-01-31", "2099-01-31"
v1, _ := time.ParseInLocation("2006-01-02", t1, time.Local)
v2, _ := time.ParseInLocation("2006-01-02", t2, time.Local)
if at.Before(v1) && at.After(v2) {
t.Errorf("%s is between %s and %s", at, v1, v2)
}
t3, t4 := "2099-01-01 12:00:00", "2099-01-31 12:00:00"
v3, _ := time.ParseInLocation("2006-01-02 15:04:05", t3, time.Local)
v4, _ := time.ParseInLocation("2006-01-02 15:04:05", t4, time.Local)
if at.Before(v4) && at.After(v3) {
t.Errorf("%s is between %s and %s", at, v3, v4)
}
t5, t6 := "2099-01-01 12:00:00", "2099-01-01 12:00:00"
v5, _ := time.ParseInLocation("2006-01-02 15:04:05", t5, time.Local)
v6, _ := time.ParseInLocation("2006-01-02 15:04:05", t6, time.Local)
if !v5.Equal(v6) {
t.Errorf("%s is equal to %s", v5, v6)
}
}
|