Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.2.0.2 Lars Petersen <info@lars-petersen.net> 2018-10-12

* Resolved error about constrained class methods.
* Added more annotation about SafeHaskell.

0.2.0.1 Lars Petersen <info@lars-petersen.net> 2015-06-17

* Resolved issue with Monad/Applicative/Functor (affected only older base).
Expand All @@ -9,5 +14,5 @@
* Removed `Midnight` in favour of `Epoch`.
* Only expose module `Data.UTC` as it contains everything anyway.
* Added functions for rendering according to ISO8601.
* Use `MonadThrow` and `UtcException` instead of `Monad.fail`
(`fail` is just for pattern-match fail as I learned).
* Use `MonadThrow` and `UtcException` instead of `Monad.fail`
(`fail` is just for pattern-match fail as I learned).
7 changes: 4 additions & 3 deletions Data/UTC.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE Safe #-}
module Data.UTC
(
(
-- * Introduction
-- ** Quick Start
-- $quickstart
Expand Down Expand Up @@ -64,7 +65,7 @@ import Data.UTC.Format.Iso8601

-- $quickstart
--
-- Just import the main module and use the 'DateTime' type!
-- Just import the main module and use the 'DateTime' type!
-- It supports all functions you'll find below.
-- Use 'Maybe' for all occurences of 'm'.
--
Expand Down Expand Up @@ -127,4 +128,4 @@ import Data.UTC.Format.Iso8601
-- In reality the problem is less severe than it seems: Your system clock is most probably
-- counting unix seconds and does not know about leap seconds either. So chances are that
-- when dealing with computer generated timestamps you'll never encounter problems with
-- leap seconds.
-- leap seconds.
3 changes: 2 additions & 1 deletion Data/UTC/Class.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE Safe #-}
module Data.UTC.Class
( module Data.UTC.Class.IsDate
, module Data.UTC.Class.IsTime
Expand All @@ -10,4 +11,4 @@ import Data.UTC.Class.Epoch
import Data.UTC.Class.IsDate
import Data.UTC.Class.IsTime
import Data.UTC.Class.IsUnixTime
import Data.UTC.Class.HasUnixTime
import Data.UTC.Class.HasUnixTime
6 changes: 2 additions & 4 deletions Data/UTC/Class/HasUnixTime.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{-# LANGUAGE Safe #-}
{-# LANGUAGE ConstrainedClassMethods #-}

{-# OPTIONS_GHC -XConstrainedClassMethods #-}

module Data.UTC.Class.HasUnixTime where

Expand Down Expand Up @@ -34,7 +33,7 @@ class HasUnixTime m where
-- /Example:/
--
-- > import Data.UTC
-- >
-- >
-- > printCurrentYear :: IO ()
-- > printCurrentYear
-- > = do now <- getUnixTime :: IO DateTime
Expand All @@ -47,4 +46,3 @@ instance HasUnixTime IO where
case fromUnixSeconds ((fromIntegral s) % 1 + (fromIntegral ns) % 1000000000) of
Just t -> return t
Nothing -> throwM $ UtcException "HasUnixTime IO: getUnixTime"

2 changes: 1 addition & 1 deletion Data/UTC/Class/IsDate/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test
, (month `fmap` d) === Just 2
, (day `fmap` d) === Just 29
]
]
]
, testGroup "addDays"
[ testProperty "addDays 366 '2000-01-01'"
$ let d = setYear 2000 (epoch :: Date) >>= setMonth 1 >>= setDay 1 >>= addDays 366
Expand Down
6 changes: 3 additions & 3 deletions Data/UTC/Format/Iso8601.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE Safe #-}
module Data.UTC.Format.Iso8601 where

import Control.Monad.Catch
Expand Down Expand Up @@ -74,9 +75,9 @@ instance Iso8601Renderer TL.Text where
= renderIso8601TimeHm' t >>= return . TL.decodeUtf8

instance Iso8601Renderer [Char] where
renderIso8601CalendarDate t
renderIso8601CalendarDate t
= renderIso8601CalendarDate t >>= return . T.unpack
renderIso8601CalendarDate' t
renderIso8601CalendarDate' t
= renderIso8601CalendarDate' t >>= return . T.unpack
renderIso8601TimeHms t
= renderIso8601TimeHms t >>= return . T.unpack
Expand Down Expand Up @@ -195,4 +196,3 @@ timeDigits t
m0 = fromIntegral $ mm `div` 1 `mod` 10
s1 = fromIntegral $ ss `div` 10 `mod` 10
s0 = fromIntegral $ ss `div` 1 `mod` 10

15 changes: 8 additions & 7 deletions Data/UTC/Format/Rfc3339.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE Safe #-}
module Data.UTC.Format.Rfc3339
( -- * Parsing
Rfc3339Parser(..)
Expand Down Expand Up @@ -52,12 +53,12 @@ instance Rfc3339Parser [Char] where
parseRfc3339 s
= parseRfc3339 (T.pack s)

-- | > setYear 1987 (epoch :: DateTime)
-- > >>= setMonth 7
-- > >>= setDay 10
-- > >>= setHour 12
-- > >>= setMinute 4
-- > >>= return . (flip Local) (Just 0)
-- | > setYear 1987 (epoch :: DateTime)
-- > >>= setMonth 7
-- > >>= setDay 10
-- > >>= setHour 12
-- > >>= setMinute 4
-- > >>= return . (flip Local) (Just 0)
-- > >>= renderRfc3339 :: Maybe String
-- > > Just "1987-07-10T12:04:00Z"
class Rfc3339Renderer string where
Expand All @@ -80,5 +81,5 @@ instance Rfc3339Renderer TL.Text where
= renderRfc3339 t >>= return . TL.decodeUtf8

instance Rfc3339Renderer [Char] where
renderRfc3339 t
renderRfc3339 t
= renderRfc3339 t >>= return . T.unpack
5 changes: 3 additions & 2 deletions Data/UTC/Format/Rfc3339/Parser.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE Safe #-}
module Data.UTC.Format.Rfc3339.Parser
( rfc3339Parser
) where
Expand All @@ -15,7 +16,7 @@ import Data.UTC.Class.IsTime
import Data.UTC.Type.Local

rfc3339Parser :: (MonadThrow m, IsDate t, IsTime t) => Parser (m (Local t))
rfc3339Parser
rfc3339Parser
= do year' <- dateFullYear
_ <- char '-'
month' <- dateMonth
Expand Down Expand Up @@ -111,4 +112,4 @@ rfc3339Parser
return $ d1 * 1000
+ d2 * 100
+ d3 * 10
+ d4
+ d4
5 changes: 3 additions & 2 deletions Data/UTC/Internal.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE Safe #-}
module Data.UTC.Internal
( daysToYearMonthDay
, yearMonthDayToDays
Expand Down Expand Up @@ -120,7 +121,7 @@ daysToYearMonthDay d'
((year `mod` 400 == 0)
|| (year `mod` 100 /= 0)) then (1+) else id
doy = d - yearToDays year
(month,day)
(month,day)
| doy < 31 = ( 1, doy + 1)
| doy < ld 59 = ( 2, doy - 31 + 1)
| doy < ld 90 = ( 3, doy - ld 59 + 1)
Expand Down Expand Up @@ -189,4 +190,4 @@ decimalFraction limit r
where
r10 = r' * 10
ch = toEnum $ fromIntegral $ 48 + (truncate $ r10) `mod` (10 :: Integer)
s = r10 - (truncate r10 % 1)
s = r10 - (truncate r10 % 1)
4 changes: 2 additions & 2 deletions Data/UTC/Internal/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ testYearToDays
testDaysToYearMonthDay :: Test
testDaysToYearMonthDay
= testGroup "daysToYearMonthDay"
$ [
$ [
testProperty "daysToYearMonthDay 366 === (1,1,1)"
$ daysToYearMonthDay 366 === (1,1,1)

Expand Down Expand Up @@ -320,4 +320,4 @@ testYearMonthDayToDaysAndDaysToYearMonthDay
, testProperty ("yearMonthDayToDays (daysToYearMonthDay x) - x === 0 for -1000000 < x < 5000000")
$ forAll (choose (-1000000, 5000000)) -- 0000-01-01 to 9999-12-31
$ \x-> yearMonthDayToDays (daysToYearMonthDay x) - x === 0
]
]
1 change: 1 addition & 0 deletions Data/UTC/Type.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE Safe #-}
module Data.UTC.Type
( module Data.UTC.Type.Date
, module Data.UTC.Type.Time
Expand Down
2 changes: 1 addition & 1 deletion Data/UTC/Type/Date.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE Safe #-}
module Data.UTC.Type.Date
( Date ()
) where
Expand Down Expand Up @@ -89,4 +90,3 @@ instance IsDate Date where
= if isValidDate (year t, month t, x)
then return $ t { dDay = x }
else throwM $ UtcException $ "IsDate Date: setDay " ++ show x ++ " " ++ show t

5 changes: 3 additions & 2 deletions Data/UTC/Type/DateTime.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE Safe #-}
{-# LANGUAGE FlexibleInstances #-}
module Data.UTC.Type.DateTime
( -- * Type
Expand Down Expand Up @@ -86,7 +87,7 @@ instance IsTime DateTime where
= do tm <- setSecondFraction y (time t)
return $ t { time = tm }

-- The default implementation of addHours fails whena day flows over.
-- The default implementation of addHours fails whena day flows over.
-- For DateTimes we can let it ripple into the days.
addHours h t
= setHour hors t >>= addDays days
Expand Down Expand Up @@ -199,4 +200,4 @@ instance IsTime (Local DateTime) where
where
h' = h + (hour t)
days = h' `div` hoursPerDay
hors = h' `mod` hoursPerDay
hors = h' `mod` hoursPerDay
3 changes: 2 additions & 1 deletion Data/UTC/Type/Exception.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE Safe #-}
{-# LANGUAGE DeriveDataTypeable #-}
module Data.UTC.Type.Exception where

Expand All @@ -15,4 +16,4 @@ data UtcException
= UtcException String
deriving (Show, Typeable)

instance Exception UtcException
instance Exception UtcException
3 changes: 2 additions & 1 deletion Data/UTC/Type/Time.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE Safe #-}
module Data.UTC.Type.Time
( Time ()
) where
Expand Down Expand Up @@ -81,4 +82,4 @@ instance IsTime Time where
| otherwise = return $ t { tSecond = x }
setSecondFraction x t
| x < 0 || 1 <= x = throwM $ UtcException $ "Time: setSecondFraction " ++ show x ++ " " ++ show t
| otherwise = return $ t { tSecondFraction = x }
| otherwise = return $ t { tSecondFraction = x }
2 changes: 1 addition & 1 deletion utc.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: utc
version: 0.2.0.1
version: 0.2.0.2
stability: experimental
synopsis: A pragmatic time and date library.
description: This library aims to supply you with common
Expand Down