aboutsummaryrefslogtreecommitdiff
path: root/tests/test/tz.scm
blob: 00a611b33b7121e1ad2296d41e5ebfad82a09099 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
;;; Commentary:
;; Tests that datetime->unix-time correctly converts between Olssen
;; timezone definitions (e.g. Europe/Stockholm), into correct times
;; and offsets (in unix time).
;; Also indirectly tests the Zone Info Compiler (datetime zic), since
;; the zoneinfo comes from there.
;;; Code:

(define-module (test tz)
  :use-module (srfi srfi-64)
  :use-module (srfi srfi-88)
  :use-module ((datetime)
               :select (parse-ics-datetime
                        datetime
                        date
                        time
                        datetime->unix-time
                        unix-time->datetime
                        get-datetime))
  :use-module ((hnh util env) :select (let-env)))

;; London alternates between +0000 and +0100
(let-env
  ((TZ "Europe/London"))
  (test-equal
    "London winter"
    #2020-01-12T13:30:00
    (get-datetime
      (parse-ics-datetime "20200112T133000Z")))
  (test-equal
    "London summer"
    #2020-06-12T14:30:00
    (get-datetime
      (parse-ics-datetime "20200612T133000Z"))))

;; Stockholm alternates between +0100 and +0200
(let-env
  ((TZ "Europe/Stockholm"))
  (test-equal
    "Stockholm winter"
    #2020-01-12T14:30:00
    (get-datetime
      (parse-ics-datetime "20200112T133000Z")))
  (test-equal
    "Stockholm summer"
    #2020-06-12T15:30:00
    (get-datetime
      (parse-ics-datetime "20200612T133000Z"))))

(test-equal
  -10800
  (datetime->unix-time
    (parse-ics-datetime
      "19700101T000000"
      "Europe/Tallinn")))

(test-equal
  -3600
  (datetime->unix-time
    (parse-ics-datetime
      "19700101T000000"
      "Europe/Stockholm")))

(test-equal
  0
  (datetime->unix-time
    (parse-ics-datetime "19700101T000000Z")))

;; yes, really
(test-equal
  -3600
  (datetime->unix-time
    (parse-ics-datetime
      "19700101T000000"
      "Europe/London")))

(test-equal
  (datetime
    date:
    #1970-01-01
    time:
    #00:00:00
    tz:
    "UTC")
  (unix-time->datetime 0))