hourglass 0.1.0 → 0.1.1
raw patch · 3 files changed
+42/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +2/−2
- hourglass.cabal +4/−3
- tests/TimeDB.hs +36/−0
README.md view
@@ -44,7 +44,7 @@ ------- with hourglass import System.Hourglass- ptime <- getCurrentElapsed+ ptime <- timeCurrent * getting current date year: @@ -56,7 +56,7 @@ ------- with hourglass import System.Hourglass import Data.Time- currentYear <- dateYear . timeGetDate <$> getCurrentElapsed+ currentYear <- dateYear . timeGetDate <$> timeCurrent * creating a time representation of "4th May 1970 15:12:24"
hourglass.cabal view
@@ -1,5 +1,5 @@ Name: hourglass-Version: 0.1.0+Version: 0.1.1 Synopsis: simple performant time related library Description: Simple time library focusing on simple but powerful and performant API@@ -16,9 +16,10 @@ Category: Time Stability: experimental Build-Type: Simple-Homepage: http://github.com/vincenthz/hs-hourglass+Homepage: https://github.com/vincenthz/hs-hourglass Cabal-Version: >=1.10 extra-source-files: README.md+ , tests/TimeDB.hs Library Exposed-modules: Data.Hourglass@@ -83,4 +84,4 @@ source-repository head type: git- location: git://github.com/vincenthz/hs-hourglass+ location: https://github.com/vincenthz/hs-hourglass
+ tests/TimeDB.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE BangPatterns #-}+module TimeDB (parseTimeConv) where++import Data.Char (isDigit)+import Data.Int+import Data.Hourglass++r :: (Read a, Num a) => String -> a+r !s+ | isNumber s = case reads s of+ [(n,"")] -> fromIntegral (n :: Int64)+ [] -> error ("cannot parse anything: " ++ show s)+ _ -> error ("cannot parse anything: " ++ show s)+ | otherwise = error ("not a num: " ++ s)+ where+ isNumber [] = False+ isNumber ('-':xs) = allNum xs+ isNumber n@(_:_) = allNum n++ allNum = and . map isDigit++wordsWhen :: (Char -> Bool) -> String -> [String]+wordsWhen p s = case dropWhile p s of+ "" -> []+ s' -> w : wordsWhen p s''+ where (w, s'') = break p s'++parseTimeConv :: String -> (Elapsed, DateTime, WeekDay, Int)+parseTimeConv v =+ case wordsWhen (== ':') v of+ ts:y:m:d:h:n:s:wd:doy:[] ->+ ( r ts+ , DateTime (Date (r y) (toEnum $ r m - 1) (r d)) (TimeOfDay (r h) (r n) (r s) 0)+ , read wd+ , r doy)+ l -> error ("invalid line: " ++ show l)