From 86a96decdb8892b10c5314eb916ef15a64204450 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 13 Nov 2016 00:49:32 +0100 Subject: Send weekly activity at start of week about previous week --- src/server/View/Format.hs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/server/View/Format.hs (limited to 'src/server/View/Format.hs') diff --git a/src/server/View/Format.hs b/src/server/View/Format.hs new file mode 100644 index 0000000..354d46a --- /dev/null +++ b/src/server/View/Format.hs @@ -0,0 +1,33 @@ +{-# LANGUAGE OverloadedStrings #-} + +module View.Format + ( price + ) where + +import Data.Text (Text) +import qualified Data.Text as T +import Data.List (intersperse) + +import Conf (Conf) +import qualified Conf + +price :: Conf -> Int -> Text +price conf amount = T.concat [number amount, " ", Conf.currency conf] + +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