aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/artifact/time.lux
blob: b227c3954ab562f7030b1ecd5d82b770878614ef (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
(.module:
  [lux #*
   ["." time]
   [abstract
    [equivalence (#+ Equivalence)]
    [monad (#+ do)]]
   [control
    ["." try (#+ Try)]
    ["<>" parser
     ["<.>" text (#+ Parser)]]]
   [data
    ["." product]
    [text
     ["%" format (#+ Format)]]]
   [time
    ["." instant (#+ Instant)]]]
  ["." / #_
   ["#." date]
   ["#." time]])

(type: #export Time
  [/date.Date /time.Time])

(def: #export epoch
  Time
  [/date.epoch time.midnight])

(def: #export (from_instant instant)
  (-> Instant (Try Time))
  (do try.monad
    [date (/date.date (instant.date instant))]
    (wrap [date
           (instant.time instant)])))

(def: #export equivalence
  (Equivalence Time)
  (product.equivalence /date.equivalence
                       time.equivalence))

(def: #export (format [date time])
  (Format Time)
  (%.format (/date.format date)
            (/time.format time)))

(def: #export parser
  (Parser Time)
  (do <>.monad
    [date /date.parser
     time /time.parser]
    (wrap [date time])))