iso8601-time 0.1.1 → 0.1.2
raw patch · 3 files changed
+49/−14 lines, 3 filesdep +HUnitdep +hspecdep +iso8601-timedep ~basedep ~time
Dependencies added: HUnit, hspec, iso8601-time
Dependency ranges changed: base, time
Files
- iso8601-time.cabal +27/−11
- src/Data/Time/ISO8601.hs +5/−3
- test/Main.hs +17/−0
iso8601-time.cabal view
@@ -1,5 +1,5 @@ name: iso8601-time-version: 0.1.1+version: 0.1.2 license: MIT copyright: 2013 Niklas Hambüchen <mail@nh2.me> author: Niklas Hambüchen <mail@nh2.me>@@ -15,12 +15,6 @@ description: Conversion functions between Haskell time types and the ISO 8601 format, which is often used for printing times, e.g. JavaScript's @new Date().toISOString()@.- .- CHANGELOG- .- Version 0.1.0- .- * Initial version. source-repository head type: git@@ -28,7 +22,29 @@ library- exposed-modules: Data.Time.ISO8601- build-depends: base < 5, old-locale, time- hs-source-dirs: src- ghc-options: -Wall+ exposed-modules:+ Data.Time.ISO8601+ hs-source-dirs:+ src+ build-depends:+ base < 5+ , old-locale >= 1.0+ , time >= 1.4+ ghc-options:+ -Wall+++test-Suite tests+ type: exitcode-stdio-1.0+ hs-source-dirs:+ test+ main-is:+ Main.hs+ build-depends:+ base >= 4 && < 5+ , iso8601-time+ , hspec >= 1.3.0.1+ , HUnit >= 1.2+ , time >= 1.4+ ghc-options:+ -Wall
src/Data/Time/ISO8601.hs view
@@ -12,18 +12,19 @@ import Data.Time.Clock (UTCTime) import Data.Time.Format (formatTime, parseTime) import System.Locale (defaultTimeLocale)+import Control.Applicative ((<|>)) -- | Formats a time in ISO 8601, with up to 12 second decimals. -- -- This is the `formatTime` format @%FT%T%Q@ == @%%Y-%m-%dT%%H:%M:%S%Q@.------ For formatISO8601 :: UTCTime -> String formatISO8601 t = formatTime defaultTimeLocale "%FT%T%QZ" t -- | Pads an ISO 8601 date with trailing zeros, but lacking the trailing Z.+--+-- This is needed because `formatTime` with "%Q" does not create trailing zeros. formatPadded :: UTCTime -> String formatPadded t | length str == 19 = str ++ ".000000000000"@@ -73,4 +74,5 @@ -- | Parses an ISO 8601 string. parseISO8601 :: String -> Maybe UTCTime-parseISO8601 t = parseTime defaultTimeLocale "%FT%T%QZ" t+parseISO8601 t = parseTime defaultTimeLocale "%FT%T%QZ" t <|>+ parseTime defaultTimeLocale "%FT%T%Q%z" t
+ test/Main.hs view
@@ -0,0 +1,17 @@+import Test.Hspec++import Data.Time.ISO8601+++main :: IO ()+main = hspec $ do+ let readTest str date = parseISO8601 str `shouldBe` (Just date)++ describe "parseISO8601" $ do++ it "time zone formats" $ do+ readTest "2014-03-28T10:26:00Z" (read "2014-03-28 10:26:00 UTC")+ readTest "2014-03-28T10:26:00-0700" (read "2014-03-28 17:26:00 UTC")+ readTest "2014-03-28T10:26:00+0700" (read "2014-03-28 03:26:00 UTC")+ readTest "2014-03-28T10:26:00-07:00" (read "2014-03-28 17:26:00 UTC")+ readTest "2014-03-28T10:26:00+07:00" (read "2014-03-28 03:26:00 UTC")