...
1 package main
2
3 import (
4 "fmt"
5 "golang.conradwood.net/go-easyops/utils"
6 "os"
7 "time"
8 )
9
10 func TestTime() {
11 test_one_time("2023-05-01", 1682899200)
12 test_one_time("2023-01-15", 1673740800)
13 test_one_time("14/05/2023", 1684022400)
14 test_one_time("2023-05-01 16:03:34", 1682957014)
15 test_one_time("2023-01-15 16:03:34", 1673798614)
16 test_one_time("1684234688", 1684234688)
17 test_one_time_loc("2023-05-15T14:35:00+00:00", "Europe/Paris", 1684161300)
18 test_one_time_loc("2023-05-15T14:35:00+01:00", "Europe/Paris", 1684157700)
19 test_one_time_loc("2023-05-15T14:35:00+00:00", "Europe/London", 1684161300)
20 test_one_time_loc("2023-05-15T14:35:00", "Europe/London", 1684157700)
21 test_one_time_loc("2023-05-15T14:35:00", "Europe/Paris", 1684154100)
22
23 }
24
25 func test_one_time_loc(ts, loc string, exp uint32) {
26 t, err := utils.ParseTimestampWithLocation(ts, loc)
27 if err != nil {
28 fmt.Printf("Parsing \"%s\" failed: %s\n", ts, err)
29 os.Exit(10)
30 }
31 comp_time(t, ts, exp)
32 }
33 func test_one_time(ts string, exp uint32) {
34 t, err := utils.ParseTimestamp(ts)
35 if err != nil {
36 fmt.Printf("Parsing \"%s\" failed: %s\n", ts, err)
37 os.Exit(10)
38 }
39 comp_time(t, ts, exp)
40 }
41
42 func comp_time(t uint32, ts string, exp uint32) {
43 if t != exp {
44 fmt.Printf("Parsing \"%s\" was expected to result in %d, but got %d\n", ts, exp, t)
45 os.Exit(10)
46 }
47 nt := time.Unix(int64(t), 0)
48 nts := fmt.Sprintf("DD/MM/YYYY %d/%d/%d", nt.Day(), nt.Month(), nt.Year())
49 xts := nt.Format(time.RFC850)
50 fmt.Printf("Determined that %v == %s == %s == %s\n", ts, utils.TimestampString(t), nts, xts)
51 }
52
View as plain text