-
Notifications
You must be signed in to change notification settings - Fork 5
/
template.elm
110 lines (76 loc) · 2.29 KB
/
template.elm
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
module TimeZone exposing
( version
, getZone, Error(..)
, zones
, ZONE_IDS
)
{-| This library provides time zone data from the `VERSION` release of the IANA
Time Zone Database.
@docs version
## Local zone
@docs getZone, Error
## Zones
@docs zones
---
Each unevaluated zone is named after its zone name (e.g.
`America/New_York`), where slashes are replaced by `__`, dashes are replaced
by `_`, and the name is lowercased. For example, `America/Port-au-Prince`
becomes `america__port_au_prince`.
@docs ZONE_IDS
-}
import Dict exposing (Dict)
import Task exposing (Task)
import Time exposing (Month(..), Weekday(..))
import TimeZone.Specification exposing (Clock(..), DateTime, DayOfMonth(..), Rule, Zone, ZoneRules(..), ZoneState)
{-| What release of the IANA Time Zone Database is this data from?
-}
version : String
version =
"VERSION"
minYear : Int
minYear =
MIN_YEAR
maxYear : Int
maxYear =
MAX_YEAR
fromSpecification : Zone -> Time.Zone
fromSpecification zone =
let
( descending, bottom ) =
zone |> TimeZone.Specification.toOffsets minYear maxYear
in
Time.customZone bottom descending
{-| Represents an error that may occur when trying to get the local zone.
-}
type Error
= NoZoneName
| NoDataForZoneName String
{-| Try to get the local time zone. If the task succeeds, then you get the zone
name along with the `Time.Zone`.
-}
getZone : Task Error ( String, Time.Zone )
getZone =
Time.getZoneName
|> Task.andThen
(\nameOrOffset ->
case nameOrOffset of
Time.Name zoneName ->
case Dict.get zoneName zones of
Just zone ->
Task.succeed ( zoneName, zone () )
Nothing ->
Task.fail (NoDataForZoneName zoneName)
Time.Offset _ ->
Task.fail NoZoneName
)
{-| You can look up an unevaluated zone by its zone name in the `zones` dictionary.
import Dict
import TimeZone exposing (zones, america__new_york)
Dict.get "America/New_York" zones
-- Just america__new_york
-}
zones : Dict String (() -> Time.Zone)
zones =
[ ZONE_NAME_ID_PAIRS
]
|> Dict.fromList