packages feed

timezone-olson-th (empty) → 0.1.0.0

raw patch · 5 files changed

+160/−0 lines, 5 filesdep +basedep +template-haskelldep +timesetup-changed

Dependencies added: base, template-haskell, time, timezone-olson, timezone-series

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Petter Bergman++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Petter Bergman nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,8 @@+# timezone-olson-th+Template Haskell to load a TimeZoneSeries from an Olson file at compile time.++For Example:++    myTimeZoneSeries :: TimeZoneSeries+    myTimeZoneSeries = $(loadTZFile "/usr/share/zoneinfo/Europe/Stockholm")+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Data/Time/LocalTime/TimeZone/Olson/TH.hs view
@@ -0,0 +1,75 @@+{-# LANGUAGE TemplateHaskell #-}+-- |+-- Load TimeZoneSeries from an Olson file at compile time.+--  +-- For example:+--+-- > myTimeZoneSeries :: TimeZoneSeries+-- > myTimeZoneSeries = $(loadTZFile "/usr/share/zoneinfo/Europe/Stockholm")++module Data.Time.LocalTime.TimeZone.Olson.TH +  (+    loadTZFile+  ) where       ++import Data.Ratio                          (numerator,+                                            denominator)+import Data.Time.LocalTime.TimeZone.Olson  (getTimeZoneSeriesFromOlsonFile)+import Data.Time.LocalTime.TimeZone.Series (TimeZoneSeries(..))+import Data.Time.LocalTime                 (TimeZone(..))+import Data.Time                           (UTCTime(..),+                                            Day(..),+                                            DiffTime,+                                            secondsToDiffTime)+import Language.Haskell.TH                 (Q,+                                            runIO,+                                            Exp(..),+                                            mkName,+                                            Lit(..),+                                            litE,+                                            integerL)++-- | Make a splice of a TimeZoneSeries from an Olson file.+loadTZFile :: FilePath -- ^ Path to the Olson file.+           -> Q Exp+loadTZFile zf = +  mkTZS =<< (runIO $ getTimeZoneSeriesFromOlsonFile zf)++-- | Make a splice of a TimeZoneSeries.    +mkTZS :: TimeZoneSeries -- ^ The TimeZoneSeries to be spliced+      -> Q Exp    +mkTZS (TimeZoneSeries def tlist) = [| TimeZoneSeries $(litTimeZone def) $(mkList tlist) |]   +  +mkList :: [(UTCTime,TimeZone)] +       -> Q Exp  +mkList l = [| $(fmap ListE $ mapM mkPair l) |]    +    +mkPair :: (UTCTime,TimeZone) +       -> Q Exp           +mkPair (t,tz) = [| ($(litUTCTime t),$(litTimeZone tz)) |]+    +litUTCTime :: UTCTime +           -> Q Exp  +litUTCTime (UTCTime (ModifiedJulianDay d) s) = +  [| UTCTime (ModifiedJulianDay $(litInteger d)) +             (secondsToDiffTime $(litInteger $ diffTimeToInteger s)) |]++litInteger :: Integer+           -> Q Exp+litInteger = litE . integerL++diffTimeToInteger :: DiffTime +                  -> Integer+diffTimeToInteger s =+  let r = toRational s+      n = numerator r+      d = denominator r in+  (n `div` d)++litTimeZone :: TimeZone +            -> Q Exp+litTimeZone (TimeZone m s n) = +  [| TimeZone $(litInteger $ toInteger m)+              $(return $ ConE $ mkName $ show s)+              $(litE $ StringL n) |]+        
+ timezone-olson-th.cabal view
@@ -0,0 +1,45 @@+-- Initial timezone-olson-th.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                timezone-olson-th+version:             0.1.0.0+synopsis:            Load TimeZoneSeries from an Olson file at compile time.+description:         +  Template Haskell to load a TimeZoneSeries from an Olson file at compile time.++  For Example:++  -- > myTimeZoneSeries :: TimeZoneSeries+  -- > myTimeZoneSeries = $(loadTZFile "/usr/share/zoneinfo/Europe/Stockholm")++homepage:            http://github.com/jonpetterbergman/timezone-olson-th+bug-reports:         http://github.com/jonpetterbergman/timezone-olson-th/issues+license:             BSD3       +license-file:        LICENSE+author:              Petter Bergman+maintainer:          jon.petter.bergman@gmail.com+-- copyright:           +category:            Data+build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10+source-repository head+  type:     git+  location: http://github.com/jonpetterbergman/timezone-olson-th++source-repository this+  type:     git+  location: http://github.com/jonpetterbergman/timezone-olson-th+  tag:      v0.1.0.0++library+  exposed-modules:     Data.Time.LocalTime.TimeZone.Olson.TH+  -- other-modules:       +  -- other-extensions:    +  build-depends:       base >=4.7 && <4.8, +                       timezone-olson >=0.1 && <0.2, +                       timezone-series >=0.1 && <0.2, +                       time >=1.4 && <1.5, +                       template-haskell >=2.9 && <2.10+  hs-source-dirs:      src+  default-language:    Haskell2010