From 27e11b20b06f2f2dbfb56c0998a63169b4b8abc4 Mon Sep 17 00:00:00 2001 From: Joris Date: Wed, 8 Nov 2017 23:47:26 +0100 Subject: Use a better project structure --- common/src/Common/View/Format.hs | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 common/src/Common/View/Format.hs (limited to 'common/src/Common/View') diff --git a/common/src/Common/View/Format.hs b/common/src/Common/View/Format.hs new file mode 100644 index 0000000..7165965 --- /dev/null +++ b/common/src/Common/View/Format.hs @@ -0,0 +1,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(..)) + +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)) -- cgit v1.2.3 From 5a63f7be9375e3ab888e4232dd7ef72c2f1ffae1 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 13 Nov 2017 23:56:40 +0100 Subject: Setup stylish-haskell --- common/src/Common/View/Format.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'common/src/Common/View') diff --git a/common/src/Common/View/Format.hs b/common/src/Common/View/Format.hs index 7165965..783ad67 100644 --- a/common/src/Common/View/Format.hs +++ b/common/src/Common/View/Format.hs @@ -7,15 +7,15 @@ module Common.View.Format , 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 Data.List (intersperse) +import Data.Maybe (fromMaybe) +import Data.Text (Text) +import qualified Data.Text as T +import Data.Time.Calendar (Day, toGregorian) -import qualified Common.Message as Message +import qualified Common.Message as Message import qualified Common.Message.Key as Key -import Common.Model (Currency(..)) +import Common.Model (Currency (..)) shortDay :: Day -> Text shortDay date = @@ -45,7 +45,7 @@ longDay date = monthToKey 10 = Just Key.Month_October monthToKey 11 = Just Key.Month_November monthToKey 12 = Just Key.Month_December - monthToKey _ = Nothing + monthToKey _ = Nothing price :: Currency -> Int -> Text price (Currency currency) amount = T.concat [ number amount, " ", currency ] -- cgit v1.2.3 From 7194cddb28656c721342c2ef604f9f9fb0692960 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 19 Nov 2017 00:20:25 +0100 Subject: Show payment count and partition - Also fixes exceedingPayer in back by using only punctual payments --- common/src/Common/View/Format.hs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'common/src/Common/View') diff --git a/common/src/Common/View/Format.hs b/common/src/Common/View/Format.hs index 783ad67..0597d17 100644 --- a/common/src/Common/View/Format.hs +++ b/common/src/Common/View/Format.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} - module Common.View.Format ( shortDay , longDay @@ -13,13 +11,12 @@ import Data.Text (Text) import qualified Data.Text as T import Data.Time.Calendar (Day, toGregorian) -import qualified Common.Message as Message -import qualified Common.Message.Key as Key import Common.Model (Currency (..)) +import qualified Common.Msg as Msg shortDay :: Day -> Text shortDay date = - Message.get $ Key.Date_Short + Msg.get $ Msg.Date_Short day month (fromIntegral year) @@ -27,24 +24,24 @@ shortDay date = longDay :: Day -> Text longDay date = - Message.get $ Key.Date_Long + Msg.get $ Msg.Date_Long day - (fromMaybe "−" . fmap Message.get . monthToKey $ month) + (fromMaybe "−" . fmap Msg.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 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 -- cgit v1.2.3 From 47c2a4d6b68c54eed5f7b45671b1ccaf8c0db200 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 20 Jan 2020 19:47:23 +0100 Subject: Show payment stats --- common/src/Common/View/Format.hs | 52 ++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'common/src/Common/View') 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 -- cgit v1.2.3