~alcinnz/bureaucromancy

ref: 93bfa89a9d3a01b22e5ebac4171280bc72760042 bureaucromancy/src/Text/HTML/Form/WebApp/Ginger/TZ.hs -rw-r--r-- 760 bytes
93bfa89a — Adrian Cochrane Add a timezone menu! 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{-# 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