packages feed

dates 0.2.1.0 → 0.2.1.1

raw patch · 3 files changed

+43/−19 lines, 3 filesdep ~parsecPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependency ranges changed: parsec

API changes (from Hackage documentation)

+ Data.Dates: tryReadInt :: Num a => String -> Parsec String st a
+ Data.Dates.Internal: tryReadInt :: Num a => String -> Parsec String st a

Files

Data/Dates.hs view
@@ -8,7 +8,7 @@    pDate, pDateTime, pTime,    pDateInterval,    getCurrentDateTime,-   tryRead,+   tryRead, tryReadInt,    DateIntervalType (..),    DateInterval (..),    dayToDateTime, dateTimeToDay,@@ -32,6 +32,7 @@ import Text.Parsec import Text.Parsec.String import Data.Generics+import Data.Char (toLower)  import Data.Dates.Types import Data.Dates.Internal@@ -285,7 +286,12 @@ pDateIntervalType ∷ Parsec String st DateIntervalType pDateIntervalType = do   s ← choice $ map maybePlural ["day", "week", "month", "year"]-  tryRead s+  case head s of+    'd' → return Day+    'w' → return Week+    'm' → return Month+    'y' → return Year+    _ → fail $ "Unknown date interval type: " ++ s  pDateInterval ∷ Parsec String st DateInterval pDateInterval = do@@ -293,10 +299,10 @@   spaces   tp ← pDateIntervalType   case tp of-    Day →   Days   `fmap` tryRead n-    Week →  Weeks  `fmap` tryRead n-    Month → Months `fmap` tryRead n-    Year →  Years  `fmap` tryRead n+    Day →   Days   `fmap` tryReadInt n+    Week →  Weeks  `fmap` tryReadInt n+    Month → Months `fmap` tryReadInt n+    Year →  Years  `fmap` tryReadInt n  pRelDate ∷ DateTime → Parsec String st DateTime pRelDate date = do@@ -354,7 +360,15 @@ pWeekDay ∷ Parsec String st WeekDay pWeekDay = do   w ← many1 (oneOf "mondaytueswnhrfi")-  tryRead (capitalize w)+  case map toLower w of+    "monday"    → return Monday+    "tuesday"   → return Tuesday+    "wednesday" → return Wednesday+    "thursday"  → return Thursday+    "friday"    → return Friday+    "saturday"  → return Saturday+    "sunday"    → return Sunday+    _           → fail $ "Unknown weekday: " ++ w  futureDate ∷ Parsec String st DateInterval futureDate = do@@ -363,10 +377,10 @@   char ' '   tp ← pDateIntervalType   case tp of-    Day →   Days   `fmap` tryRead n-    Week →  Weeks  `fmap` tryRead n-    Month → Months `fmap` tryRead n-    Year →  Years  `fmap` tryRead n+    Day →   Days   `fmap` tryReadInt n+    Week →  Weeks  `fmap` tryReadInt n+    Month → Months `fmap` tryReadInt n+    Year →  Years  `fmap` tryReadInt n  passDate ∷ Parsec String st DateInterval passDate = do@@ -375,10 +389,10 @@   tp ← pDateIntervalType   string " ago"   case tp of-    Day →   (Days   . negate) `fmap` tryRead n-    Week →  (Weeks  . negate) `fmap` tryRead n-    Month → (Months . negate) `fmap` tryRead n-    Year →  (Years  . negate) `fmap` tryRead n+    Day →   (Days   . negate) `fmap` tryReadInt n+    Week →  (Weeks  . negate) `fmap` tryReadInt n+    Month → (Months . negate) `fmap` tryReadInt n+    Year →  (Years  . negate) `fmap` tryReadInt n  today ∷ Parsec String st DateInterval today = do
Data/Dates/Internal.hs view
@@ -2,6 +2,8 @@  module Data.Dates.Internal where +import Data.Char+ import Text.Parsec import Text.Parsec.String @@ -12,6 +14,12 @@     [(res, "")] -> return res     _ -> fail $ "Cannot read: " ++ str +tryReadInt ∷ Num a ⇒ String → Parsec String st a+tryReadInt str =+  if all isDigit str+    then return $ fromIntegral $ foldl (\a b → 10*a+b) 0 $ map digitToInt str+    else fail $ "Cannot read: " ++ str+ -- | Apply parser N times times ∷ Int      → Parsec String st t@@ -30,7 +38,7 @@        → Int   -- ^ Maximum value        → Parsec String st Int number n m = do-  t ← tryRead =<< (n `times` digit)+  t ← tryReadInt =<< (n `times` digit)   if t > m     then fail "number too large"     else return t
dates.cabal view
@@ -1,5 +1,5 @@ name:                dates-version:             0.2.1.0+version:             0.2.1.1 synopsis:            Small library for parsing different dates formats. description:         This package allows to parse many different formats                      of dates. Both absolute and relative dates are supported.@@ -40,12 +40,14 @@                        Data.Dates.Types,                        Data.Dates.Formats,                        Data.Dates.Internal-  -- other-modules:       +   build-depends:       base >=4 && < 5,                        base-unicode-symbols ==0.2.*,                        time >= 1.4,-                       parsec ==3.1.*,+                       parsec >=3.1,                        syb ==0.3.*++  GHC-Options:         -O2  Source-repository head   type:     git