-- | Date functions.
module Byg.Types.Date
  ( Date(..)
  , formatDate
  , formatDateShort
  ) where

import Text.Printf (printf)
import Data.Text (Text)
import qualified Data.Text as T

data Date = Date Int Int Int
  deriving (Eq, Ord, Show)

formatDate :: Date -> Text
formatDate (Date year month day) =
  T.concat [ "den "
           , T.pack (show day)
           , ". "
           , months !! (month - 1)
           , " "
           , T.pack (show year)
           ]
  where months = [ "januar"
                 , "februar"
                 , "marts"
                 , "april"
                 , "maj"
                 , "juni"
                 , "juli"
                 , "august"
                 , "september"
                 , "oktober"
                 , "november"
                 , "december"
                 ]

formatDateShort :: Date -> Text
formatDateShort (Date year month day) =
  T.concat [ T.pack (show year), "-", T.pack (printf "%02d" month), "-", T.pack (printf "%02d" day) ]
