dates 0.2.2.2 → 0.2.3.0
raw patch · 3 files changed
+79/−10 lines, 3 filesdep +datesdep +hspecdep ~basedep ~parsecdep ~sybPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: dates, hspec
Dependency ranges changed: base, parsec, syb, time
API changes (from Hackage documentation)
+ Data.Dates: parseDateTime :: DateTime -> String -> Either ParseError DateTime
- Data.Dates.Internal: times :: (Stream s m Char) => Int -> ParsecT s st m t -> ParsecT s st m [t]
+ Data.Dates.Internal: times :: Stream s m Char => Int -> ParsecT s st m t -> ParsecT s st m [t]
Files
- Data/Dates.hs +13/−3
- dates.cabal +15/−7
- tests/Spec.hs +51/−0
Data/Dates.hs view
@@ -4,7 +4,7 @@ (DateTime (..), Time (..), WeekDay (..),- parseDate,+ parseDate, parseDateTime, pDate, pDateTime, pTime, pDateInterval, getCurrentDateTime,@@ -27,8 +27,12 @@ import Data.Char (toUpper) import Data.List import Data.Time.Calendar-import Data.Time.Calendar.WeekDate+ ( Day, toGregorian, fromGregorian, addDays, addGregorianMonthsClip+ , addGregorianYearsClip, toModifiedJulianDay )+import Data.Time.Calendar.WeekDate (toWeekDate) import Data.Time.LocalTime+ ( getZonedTime, zonedTimeToLocalTime, localDay, localTimeOfDay+ , todHour, todMin, todSec ) import Text.Parsec import Data.Generics import Data.Char (toLower)@@ -432,9 +436,15 @@ <|> (try $ pByWeek date) <|> (try $ pAbsDate $ year date) --- | Parse date/time+-- | Parse date parseDate ∷ DateTime -- ^ Current date / time, to use as base for relative dates → String -- ^ String to parse → Either ParseError DateTime parseDate date s = runParser (pDate date) () "" s++-- | Parse date and time+parseDateTime ∷ DateTime -- ^ Current date / time, to use as base for relative dates+ → String -- ^ String to parse+ → Either ParseError DateTime+parseDateTime date s = runParser (pDateTime date) () "" s
dates.cabal view
@@ -1,5 +1,5 @@ name: dates-version: 0.2.2.2+version: 0.2.3.0 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.@@ -25,7 +25,7 @@ User-specified date formats are supported by Data.Dates.Formats module. -homepage: http://redmine.iportnov.ru/projects/dates/+homepage: https://github.com/portnov/dates license: BSD3 license-file: LICENSE author: IlyaPortnov@@ -41,14 +41,22 @@ Data.Dates.Formats, Data.Dates.Internal - build-depends: base >=4 && < 4.12,+ build-depends: base >=4.9 && < 4.13, base-unicode-symbols ==0.2.*,- time >= 1.4,- parsec >=3.1,- syb >=0.3.7+ time >= 1.4 && < 1.10,+ parsec ==3.1.*,+ syb >=0.3.7 && < 0.8 GHC-Options: -O2 +Test-suite main+ type: exitcode-stdio-1.0+ build-depends: base >= 4.9 && < 4.13,+ hspec,+ dates+ hs-source-dirs: tests+ main-is: Spec.hs+ Source-repository head type: git- location: git://redmine.iportnov.ru/dates.git+ location: https://github.com/portnov/dates.git
+ tests/Spec.hs view
@@ -0,0 +1,51 @@++import Test.Hspec+import Data.Dates++todayString :: String+todayString = "27 June 2019, 19:55:11"++main :: IO ()+main = hspec $ describe "test suite" $ do+ it "parses full absolute date specification" $ do+ let Right today = parseDateTime undefined todayString+ today `shouldBe` DateTime 2019 6 27 19 55 11++ it "parses simple absolute format #1" $ do+ let Right day = parseDate undefined "2019/06/27"+ day `shouldBe` DateTime 2019 6 27 0 0 0++ it "parses simple absolute format #2" $ do+ let Right day = parseDate undefined "27.06.2019"+ day `shouldBe` DateTime 2019 6 27 0 0 0++ it "parses absolute format #3" $ do+ let Right day = parseDate undefined "27 June 2019"+ day `shouldBe` DateTime 2019 6 27 0 0 0++ it "parses simple relative formats" $ do+ let Right today = parseDateTime undefined todayString+ Right today1 = parseDate today "today"+ Right yesterday = parseDate today "yesterday"+ Right tomorrow = parseDate today "tomorrow"++ today1 `shouldBe` DateTime 2019 6 27 19 55 11+ yesterday `shouldBe` DateTime 2019 6 26 19 55 11+ tomorrow `shouldBe` DateTime 2019 6 28 19 55 11++ it "parses more complex relative formats" $ do+ let Right today = parseDateTime undefined todayString+ Right inTwoDays = parseDate today "in 2 days"+ Right threeWeeksAgo = parseDate today "3 weeks ago"+ Right lastMonday = parseDate today "last monday"+ Right nextFriday = parseDate today "next friday"+ Right lastMonth = parseDate today "last month"+ Right nextYear = parseDate today "next year"++ inTwoDays `shouldBe` DateTime 2019 6 29 19 55 11+ threeWeeksAgo `shouldBe` DateTime 2019 6 6 19 55 11+ lastMonday `shouldBe` DateTime 2019 6 24 19 55 11+ nextFriday `shouldBe` DateTime 2019 6 28 19 55 11+ lastMonth `shouldBe` DateTime 2019 6 1 19 55 11+ nextYear `shouldBe` DateTime 2020 1 1 19 55 11+