aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/artifact/time/time.lux
blob: 5fca26062d250b94b224c56b96f9dc0daa4a7fc4 (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
(.module:
  [library
   [lux "*"
    ["." time]
    [abstract
     [monad {"+" [do]}]]
    [control
     ["<>" parser
      ["<.>" text {"+" [Parser]}]]]
    [data
     [text
      ["%" format]]]
    [math
     [number
      ["n" nat]]]]]
  ["." // "_"
   ["#" date]])

(type: .public Time
  time.Time)

(def: .public (format value)
  (%.Format Time)
  (let [(^slots [#time.hour #time.minute #time.second]) (time.clock value)]
    (%.format (//.pad hour)
              (//.pad minute)
              (//.pad second))))

(def: .public parser
  (<text>.Parser Time)
  (do <>.monad
    [hour (<>.codec n.decimal (<text>.exactly 2 <text>.decimal))
     minute (<>.codec n.decimal (<text>.exactly 2 <text>.decimal))
     second (<>.codec n.decimal (<text>.exactly 2 <text>.decimal))]
    (<>.lifted (time.time
                [#time.hour hour
                 #time.minute minute
                 #time.second second
                 #time.milli_second 0]))))