aboutsummaryrefslogtreecommitdiff
path: root/common/src/Common/View
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/Common/View')
-rw-r--r--common/src/Common/View/Format.hs52
1 files changed, 32 insertions, 20 deletions
diff --git a/common/src/Common/View/Format.hs b/common/src/Common/View/Format.hs
index 0597d17..5d879fa 100644
--- a/common/src/Common/View/Format.hs
+++ b/common/src/Common/View/Format.hs
@@ -3,15 +3,18 @@ module Common.View.Format
, longDay
, price
, number
+ , monthAndYear
) where
-import Data.List (intersperse)
-import Data.Maybe (fromMaybe)
+import qualified Data.List as L
+import qualified Data.Maybe as Maybe
import Data.Text (Text)
import qualified Data.Text as T
-import Data.Time.Calendar (Day, toGregorian)
+import Data.Time.Calendar (Day)
+import qualified Data.Time.Calendar as Calendar
import Common.Model (Currency (..))
+import Common.Msg (Key)
import qualified Common.Msg as Msg
shortDay :: Day -> Text
@@ -20,29 +23,38 @@ shortDay date =
day
month
(fromIntegral year)
- where (year, month, day) = toGregorian date
+ where (year, month, day) = Calendar.toGregorian date
longDay :: Day -> Text
longDay date =
Msg.get $ Msg.Date_Long
day
- (fromMaybe "−" . fmap Msg.get . monthToKey $ month)
+ (Maybe.fromMaybe "−" . fmap Msg.get . monthToKey $ month)
(fromIntegral year)
- where (year, month, day) = toGregorian date
+ where (year, month, day) = Calendar.toGregorian date
- monthToKey 1 = Just Msg.Month_January
- monthToKey 2 = Just Msg.Month_February
- monthToKey 3 = Just Msg.Month_March
- monthToKey 4 = Just Msg.Month_April
- monthToKey 5 = Just Msg.Month_May
- monthToKey 6 = Just Msg.Month_June
- monthToKey 7 = Just Msg.Month_July
- monthToKey 8 = Just Msg.Month_August
- monthToKey 9 = Just Msg.Month_September
- monthToKey 10 = Just Msg.Month_October
- monthToKey 11 = Just Msg.Month_November
- monthToKey 12 = Just Msg.Month_December
- monthToKey _ = Nothing
+monthAndYear :: Day -> Text
+monthAndYear date =
+ T.intercalate " "
+ [ Maybe.fromMaybe "" . fmap ((\t -> T.concat [t, " "]) . Msg.get) . monthToKey $ month
+ , T.pack . show $ year
+ ]
+ where (year, month, _) = Calendar.toGregorian date
+
+monthToKey :: Int -> Maybe Key
+monthToKey 1 = Just Msg.Month_January
+monthToKey 2 = Just Msg.Month_February
+monthToKey 3 = Just Msg.Month_March
+monthToKey 4 = Just Msg.Month_April
+monthToKey 5 = Just Msg.Month_May
+monthToKey 6 = Just Msg.Month_June
+monthToKey 7 = Just Msg.Month_July
+monthToKey 8 = Just Msg.Month_August
+monthToKey 9 = Just Msg.Month_September
+monthToKey 10 = Just Msg.Month_October
+monthToKey 11 = Just Msg.Month_November
+monthToKey 12 = Just Msg.Month_December
+monthToKey _ = Nothing
price :: Currency -> Int -> Text
price (Currency currency) amount = T.concat [ number amount, " ", currency ]
@@ -53,7 +65,7 @@ number n =
. (++) (if n < 0 then "-" else "")
. reverse
. concat
- . intersperse " "
+ . L.intersperse " "
. group 3
. reverse
. show