forked from rluiten/elm-date-extra
/
ExampleConfigFormat.elm
86 lines (64 loc) · 1.86 KB
/
ExampleConfigFormat.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
module Main exposing (main)
{-| An example of adjusting the Config for Format.
Configure the month name produced when formatting dates.
This example modifies an existing Config but you can create
your own Config without using existing ones as well.
You can also use existing translations in the Date.Config.I18n namespace if
they match your language needs for your own config.
Copyright (c) 2016-2018 Robin Luiten
-}
import Browser
import Html exposing (Html, div, text)
import String
import Time exposing (utc)
import Time.Format exposing (format)
import Time.Format.Config.Config_en_au exposing (config)
{-| Modify the i18n in config to change month names so they area reversed.
-}
configReverseMonthName =
let
i18nCurrent =
config.i18n
i18nUpdated =
{ i18nCurrent
| monthName = String.reverse << i18nCurrent.monthName
}
in
{ config
| i18n = i18nUpdated
}
{-| See [DocFormat.md](../DocFormat.md) for token meanings.
-}
myDateFormat =
"%A, %e %B %Y"
formatOriginal =
format config myDateFormat
formatReverseMonthName =
format configReverseMonthName myDateFormat
{-| Time 1407833631161.0 in utc is "2014-08-12 08:53:51.161"
-}
testDate1 =
Time.millisToPosix 1407833631161
main =
Browser.sandbox
{ init = ()
, view = view
, update = \_ model -> model
}
view _ =
div []
[ div []
[ text
("formatOriginal en_au config with utc time zone \""
++ formatOriginal utc testDate1
++ "\". "
)
]
, div []
[ text
("formatReverseMonthName en_au config with utc time zone \""
++ formatReverseMonthName utc testDate1
++ "\". "
)
]
]