blob: a7fa4e3c98d8abe107a34664145a4cb05989826b (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
{-# LANGUAGE OverloadedStrings #-}
module Common.View.Format
( shortDay
, longDay
, price
, number
) where
import Data.Text (Text)
import qualified Data.Text as T
import Data.List (intersperse)
import Data.Maybe (fromMaybe)
import Data.Time.Calendar (Day, toGregorian)
import qualified Common.Message as Message
import qualified Common.Message.Key as Key
import Common.Model.Currency (Currency(..))
shortDay :: Day -> Text
shortDay date =
Message.get $ Key.Date_Short
day
month
(fromIntegral year)
where (year, month, day) = toGregorian date
longDay :: Day -> Text
longDay date =
Message.get $ Key.Date_Long
day
(fromMaybe "−" . fmap Message.get . monthToKey $ month)
(fromIntegral year)
where (year, month, day) = toGregorian date
monthToKey 1 = Just Key.Month_January
monthToKey 2 = Just Key.Month_February
monthToKey 3 = Just Key.Month_March
monthToKey 4 = Just Key.Month_April
monthToKey 5 = Just Key.Month_May
monthToKey 6 = Just Key.Month_June
monthToKey 7 = Just Key.Month_July
monthToKey 8 = Just Key.Month_August
monthToKey 9 = Just Key.Month_September
monthToKey 10 = Just Key.Month_October
monthToKey 11 = Just Key.Month_November
monthToKey 12 = Just Key.Month_December
monthToKey _ = Nothing
price :: Currency -> Int -> Text
price (Currency currency) amount = T.concat [ number amount, " ", currency ]
number :: Int -> Text
number n =
T.pack
. (++) (if n < 0 then "-" else "")
. reverse
. concat
. intersperse " "
. group 3
. reverse
. show
. abs $ n
group :: Int -> [a] -> [[a]]
group n xs =
if length xs <= n
then [xs]
else (take n xs) : (group n (drop n xs))
|