aboutsummaryrefslogtreecommitdiff
path: root/test/02-api.janet
blob: ff367db1b7222e69381fcc27af91588fd848f952 (plain) (blame)
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
(import ../date)

(def now (date/time))
(assert (date/time? now))

(def gmt (:gmtime now))
(def loc (:localtime now))
(assert (date/tm? gmt))
(assert (date/tm? loc))
(assert (= (:mktime loc) (:timegm gmt)))

(def before (date/update-time* now {:sec -1 :min dec}))
(def after  (date/update-time  now  :sec 61 :min inc))
(assert (> after now before))

# default format
(assert (date/format now))
# utc default format
(assert (date/format now :default true))
# format string
(assert (date/format now :%c))

# ensure tm + gmtime are spec-compliant
(def u (date/utc   {:year 1970}))
(def l (date/local {:year 1970}))
(assert (= u
           (:gmtime (:timegm u))))
(assert (= l
           (:localtime (:mktime l))))