From 127c1212d7704392363e3614f339627bf514cfcf Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 15 Feb 2017 19:04:57 +0100 Subject: Timezones --- lib/Postdelay/TimeSpec/Units.hs | 4 +--- lib/Postdelay/TimeSpec/Utils.hs | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/Postdelay/TimeSpec') diff --git a/lib/Postdelay/TimeSpec/Units.hs b/lib/Postdelay/TimeSpec/Units.hs index 0062460..a094ea3 100644 --- a/lib/Postdelay/TimeSpec/Units.hs +++ b/lib/Postdelay/TimeSpec/Units.hs @@ -62,10 +62,8 @@ rational :: forall s m n. (StringParser s m, Fractional n, Num n) => m n rational = combine <$> some digitChar <*> option [] (char '.' *> many digitChar) "Decimal number" where combine :: [Char] -> [Char] -> n - combine (map asN -> whole) (map asN -> fractional) + combine (map fromDigit -> whole) (map fromDigit -> fractional) = foldl' (\i l -> i * 10 + l) 0 whole + (foldr' (\h t -> h + t / 10) 0 fractional) / 10 - asN :: Char -> n - asN c = fromIntegral $ fromEnum c - fromEnum '0' timeUnit :: StringParser s m => m Time timeUnit = label "Unit of time" . choice $ diff --git a/lib/Postdelay/TimeSpec/Utils.hs b/lib/Postdelay/TimeSpec/Utils.hs index 85ac299..83a271d 100644 --- a/lib/Postdelay/TimeSpec/Utils.hs +++ b/lib/Postdelay/TimeSpec/Utils.hs @@ -35,3 +35,6 @@ sign :: (StringParser s m, AdditiveGroup n) => m (n -> n) sign = label "sign" $ choice [ char '+' $> id , char '-' $> negateV ] + +fromDigit :: Num n => Char -> n +fromDigit c = fromIntegral $ fromEnum c - fromEnum '0' -- cgit v1.2.3