{-# LANGUAGE ExistentialQuantification #-}
module Data.Hourglass.Zone
( Timezone(..)
, UTC(..)
, TimezoneMinutes(..)
) where
class Timezone tz where
timezoneOffset :: tz -> Int
timezoneName :: tz -> String
timezoneName = tzMinutesPrint . timezoneOffset
newtype TimezoneMinutes = TimezoneMinutes Int
deriving (Show,Eq,Ord)
data UTC = UTC
deriving (Show,Eq,Ord)
instance Timezone UTC where
timezoneOffset _ = 0
timezoneName _ = "UTC"
instance Timezone TimezoneMinutes where
timezoneOffset (TimezoneMinutes minutes) = minutes
tzMinutesPrint :: Int -> String
tzMinutesPrint offset =
(if offset > 0 then '+' else '-')
: (pad0 h ++ ":" ++ pad0 m)
where (h,m) = abs offset `divMod` 60
pad0 v
| v < 10 = '0':show v
| otherwise = show v