{-# LANGUAGE OverloadedStrings #-}
module Text.HTML.Form.WebApp.Ginger.TZ(tzdata) where
import Text.Ginger.GVal as V (GVal, orderedDict, (~>), list)
import qualified Data.Map.Strict as M
import Data.Time.Zones.All (tzNameLabelMap, tzByLabel)
import Data.Time.Zones (diffForPOSIX)
import Data.Int (Int64)
tzdata :: Int64 -> GVal m
tzdata now = list [orderedDict [
"label" ~> label,
"value" ~> (diffForPOSIX tz' now `div` 60),
"offset" ~> formatOffset (diffForPOSIX tz' now `div` 60)
] | (label, tz) <- M.toList tzNameLabelMap, let tz' = tzByLabel tz]
formatOffset :: (Show a, Integral a) => a -> [Char]
formatOffset offset = (show hours ++ ':': show minutes)
where
hours = offset `div` 60
minutes = abs $ offset `rem` 60