aboutsummaryrefslogtreecommitdiff
path: root/common/src/Common/View/Format.hs
diff options
context:
space:
mode:
authorJoris2021-01-03 13:40:40 +0100
committerJoris2021-01-03 13:54:20 +0100
commit11052951b74b9ad4b6a9412ae490086235f9154b (patch)
tree64526ac926c1bf470ea113f6cac8a33158684e8d /common/src/Common/View/Format.hs
parent371449b0e312a03162b78797b83dee9d81706669 (diff)
downloadbudget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.gz
budget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.bz2
budget-11052951b74b9ad4b6a9412ae490086235f9154b.zip
Rewrite in Rust
Diffstat (limited to 'common/src/Common/View/Format.hs')
-rw-r--r--common/src/Common/View/Format.hs78
1 files changed, 0 insertions, 78 deletions
diff --git a/common/src/Common/View/Format.hs b/common/src/Common/View/Format.hs
deleted file mode 100644
index 5d879fa..0000000
--- a/common/src/Common/View/Format.hs
+++ /dev/null
@@ -1,78 +0,0 @@
-module Common.View.Format
- ( shortDay
- , longDay
- , price
- , number
- , monthAndYear
- ) where
-
-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)
-import qualified Data.Time.Calendar as Calendar
-
-import Common.Model (Currency (..))
-import Common.Msg (Key)
-import qualified Common.Msg as Msg
-
-shortDay :: Day -> Text
-shortDay date =
- Msg.get $ Msg.Date_Short
- day
- month
- (fromIntegral year)
- where (year, month, day) = Calendar.toGregorian date
-
-longDay :: Day -> Text
-longDay date =
- Msg.get $ Msg.Date_Long
- day
- (Maybe.fromMaybe "−" . fmap Msg.get . monthToKey $ month)
- (fromIntegral year)
- where (year, month, day) = Calendar.toGregorian date
-
-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 ]
-
-number :: Int -> Text
-number n =
- T.pack
- . (++) (if n < 0 then "-" else "")
- . reverse
- . concat
- . L.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))