git-date 0.2.2 → 0.3.0
raw patch · 3 files changed
+16/−20 lines, 3 filesdep +unexceptionalioPVP ok
version bump matches the API change (PVP)
Dependencies added: unexceptionalio
API changes (from Hackage documentation)
- Data.Time.Git: io_approxidate :: String -> IO (Maybe Integer)
- Data.Time.Git: posixToUTC :: Integer -> UTCTime
+ Data.Time.Git: approxidateIO :: (Unexceptional m) => String -> m (Maybe UTCTime)
- Data.Time.Git: approxidate :: String -> Maybe Integer
+ Data.Time.Git: approxidate :: String -> Maybe UTCTime
Files
- Data/Time/Git.hs +13/−16
- git-date.cabal +2/−1
- tests/suite.hs +1/−3
Data/Time/Git.hs view
@@ -1,14 +1,15 @@ {-# LANGUAGE ForeignFunctionInterface #-} -module Data.Time.Git (approxidate, io_approxidate, posixToUTC) where+module Data.Time.Git (approxidate, approxidateIO) where +import Data.Time (UTCTime)+import Data.Time.Clock.POSIX (posixSecondsToUTCTime) import Foreign hiding (unsafePerformIO)-import Foreign.C.Types import Foreign.C.String+import Foreign.C.Types import System.IO.Unsafe (unsafePerformIO)--import Data.Time-import Data.Time.Clock.POSIX+import UnexceptionalIO (Unexceptional)+import qualified UnexceptionalIO as UIO import qualified Data.ByteString as BS import qualified Data.ByteString.UTF8 as BS (fromString)@@ -21,22 +22,18 @@ -- | Parse a date/time string and return Just a Unix timestamp. -- Return Nothing if the string could not be interpreted. -- If no timezone is in the string, the local timezone is used.--- This is not in IO and you cannot safely ask it to parse strings like--- \"now\" and \"yesterday\".-approxidate :: String -> Maybe Integer-approxidate = unsafePerformIO . io_approxidate---- | Convert a Unix timestamp to a UTCTime-posixToUTC :: Integer -> UTCTime-posixToUTC = posixSecondsToUTCTime . realToFrac+approxidate :: String -> Maybe UTCTime+approxidate = unsafePerformIO . approxidateIO -- | Parse a date/time string and return Just a Unix timestamp. -- Return Nothing if the string could not be interpreted. -- If no timezone is in the string, the local timezone is used.--- This is in IO so that you can safely ask it to parse strings like+-- This is in IO so that you can ask it to parse strings like -- \"now\" and \"yesterday\".-io_approxidate :: String -> IO (Maybe Integer)-io_approxidate input =+approxidateIO :: (Unexceptional m) => String -> m (Maybe UTCTime)+approxidateIO input =+ (fmap . fmap) (posixSecondsToUTCTime . realToFrac) $+ UIO.unsafeFromIO $ BS.useAsCString (BS.fromString input) (\c_input -> alloca (\c_error_ret -> do poke c_error_ret 0
git-date.cabal view
@@ -1,5 +1,5 @@ name: git-date-version: 0.2.2+version: 0.3.0 cabal-version: >= 1.8 license: GPL-2 license-file: COPYING@@ -32,6 +32,7 @@ build-depends: base == 4.*, bytestring,+ unexceptionalio >= 0.3.0, utf8-string, time
tests/suite.hs view
@@ -4,7 +4,6 @@ import Data.Int import Data.Time.Git-import System.Locale import Data.Time import Data.Time.Clock.POSIX import System.IO.Unsafe@@ -38,9 +37,8 @@ prop_format :: DateFormat -> PositiveTime -> Bool prop_format (DateFormat fmt) (PositiveTime time) =- approxidate formatted == Just posix+ approxidate formatted == Just (zonedTimeToUTC time) where- posix = floor $ utcTimeToPOSIXSeconds $ zonedTimeToUTC time formatted = formatTime defaultTimeLocale fmt time tests :: [Test]