Guest User

Untitled

a guest
Apr 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. {-# LANGUAGE TemplateHaskell #-}
  2.  
  3. module Main (main) where
  4.  
  5. import Data.Foldable (for_)
  6. import Data.Time (TimeZone, UTCTime(..), fromGregorian)
  7. import Data.Time.Zones (diffForPOSIX, timeZoneForPOSIX)
  8. import Data.Time.Zones.Internal (utcTimeToInt64)
  9. import Data.Time.Zones.TH (includeTZFromDB)
  10. import Data.Time.Zones.Types (TZ)
  11. import Text.Printf (printf)
  12.  
  13. newtype Minutes = Minutes Int
  14. instance Show Minutes where
  15. show (Minutes n) = printf "%d:%02d" (n `div` 60) (n `mod` 60)
  16.  
  17. tzHaworth :: TZ
  18. tzHaworth = $(includeTZFromDB "Europe/London")
  19.  
  20. tzBothell :: TZ
  21. tzBothell = $(includeTZFromDB "America/Los_Angeles")
  22.  
  23. tzOffsetInfo :: TZ -> UTCTime -> (Minutes, TimeZone)
  24. tzOffsetInfo tz utcTime =
  25. let posixTime = utcTimeToInt64 utcTime
  26. tzInEffect = timeZoneForPOSIX tz posixTime
  27. offset = Minutes $ (diffForPOSIX tz posixTime) `div` 60
  28. in (offset, tzInEffect)
  29.  
  30. minutesDiff :: Minutes -> Minutes -> Minutes
  31. minutesDiff (Minutes a) (Minutes b) = Minutes (a - b)
  32.  
  33. main :: IO ()
  34. main = do
  35. let startDay = fromGregorian 2018 1 1
  36. for_ (take 365 [startDay..]) $ \day -> do
  37. let time = UTCTime day 0
  38. (offsetBothell, tzInEffectBothell) = tzOffsetInfo tzBothell time
  39. (offsetHaworth, tzInEffectHaworth) = tzOffsetInfo tzHaworth time
  40. diff = offsetBothell `minutesDiff` offsetHaworth
  41. putStrLn $
  42. printf
  43. "%s: %s vs %s %s"
  44. (show day)
  45. (show tzInEffectBothell)
  46. (show tzInEffectHaworth)
  47. (show diff)
Add Comment
Please, Sign In to add comment