mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-12 19:08:34 +03:00
fix parseTime warnings with time 1.5+ (#239)
This commit is contained in:
parent
e838ed0637
commit
f8a24ccead
@ -427,13 +427,23 @@ nthdayofweekcontaining n d | d1 >= d = d1
|
||||
-- parseTime defaultTimeLocale "%Y-%m-%d %H:%M:%S" s
|
||||
-- ]
|
||||
|
||||
parsetime :: ParseTime t => TimeLocale -> String -> String -> Maybe t
|
||||
parsetime =
|
||||
#if MIN_VERSION_time(1,5,0)
|
||||
parseTimeM True
|
||||
#else
|
||||
parseTime
|
||||
#endif
|
||||
|
||||
|
||||
-- | Parse a couple of date string formats to a time type.
|
||||
parsedateM :: String -> Maybe Day
|
||||
parsedateM s = firstJust [
|
||||
parseTime defaultTimeLocale "%Y/%m/%d" s,
|
||||
parseTime defaultTimeLocale "%Y-%m-%d" s
|
||||
parsetime defaultTimeLocale "%Y/%m/%d" s,
|
||||
parsetime defaultTimeLocale "%Y-%m-%d" s
|
||||
]
|
||||
|
||||
|
||||
-- -- | Parse a date-time string to a time type, or raise an error.
|
||||
-- parsedatetime :: String -> LocalTime
|
||||
-- parsedatetime s = fromMaybe (error' $ "could not parse timestamp \"" ++ s ++ "\"")
|
||||
@ -447,7 +457,7 @@ parsedate s = fromMaybe (error' $ "could not parse date \"" ++ s ++ "\"")
|
||||
-- | Parse a time string to a time type using the provided pattern, or
|
||||
-- return the default.
|
||||
parsetimewith :: ParseTime t => String -> String -> t -> t
|
||||
parsetimewith pat s def = fromMaybe def $ parseTime defaultTimeLocale pat s
|
||||
parsetimewith pat s def = fromMaybe def $ parsetime defaultTimeLocale pat s
|
||||
|
||||
{-|
|
||||
Parse a date in any of the formats allowed in ledger's period expressions,
|
||||
|
@ -14,7 +14,7 @@ import Data.Time.Calendar
|
||||
import Data.Time.Clock
|
||||
import Data.Time.Format
|
||||
import Data.Time.LocalTime
|
||||
#if !MIN_VERSION_time(1,5,0)
|
||||
#if !(MIN_VERSION_time(1,5,0))
|
||||
import System.Locale (defaultTimeLocale)
|
||||
#endif
|
||||
import Test.HUnit
|
||||
@ -112,7 +112,12 @@ tests_Hledger_Data_TimeLog = TestList [
|
||||
nowstr = showtime now
|
||||
yesterday = prevday today
|
||||
clockin = TimeLogEntry nullsourcepos In
|
||||
mktime d = LocalTime d . fromMaybe midnight . parseTime defaultTimeLocale "%H:%M:%S"
|
||||
mktime d = LocalTime d . fromMaybe midnight .
|
||||
#if MIN_VERSION_time(1,5,0)
|
||||
parseTimeM True defaultTimeLocale "%H:%M:%S"
|
||||
#else
|
||||
parseTime defaultTimeLocale "%H:%M:%S"
|
||||
#endif
|
||||
showtime = formatTime defaultTimeLocale "%H:%M"
|
||||
assertEntriesGiveStrings name es ss = assertEqual name ss (map tdescription $ timeLogEntriesToTransactions now es)
|
||||
|
||||
|
@ -32,10 +32,10 @@ import Data.List
|
||||
import Data.Maybe
|
||||
import Data.Ord
|
||||
import Data.Time.Calendar (Day)
|
||||
import Data.Time.Format (parseTime)
|
||||
#if MIN_VERSION_time(1,5,0)
|
||||
import Data.Time.Format (defaultTimeLocale)
|
||||
import Data.Time.Format (parseTimeM, defaultTimeLocale)
|
||||
#else
|
||||
import Data.Time.Format (parseTime)
|
||||
import System.Locale (defaultTimeLocale)
|
||||
#endif
|
||||
import Safe
|
||||
@ -720,7 +720,13 @@ renderTemplate rules record t = regexReplaceBy "%[A-z0-9]+" replace t
|
||||
parseDateWithFormatOrDefaultFormats :: Maybe DateFormat -> String -> Maybe Day
|
||||
parseDateWithFormatOrDefaultFormats mformat s = firstJust $ map parsewith formats
|
||||
where
|
||||
parsewith = flip (parseTime defaultTimeLocale) s
|
||||
parsetime =
|
||||
#if MIN_VERSION_time(1,5,0)
|
||||
parseTimeM True
|
||||
#else
|
||||
parseTime
|
||||
#endif
|
||||
parsewith = flip (parsetime defaultTimeLocale) s
|
||||
formats = maybe
|
||||
["%Y/%-m/%-d"
|
||||
,"%Y-%-m-%-d"
|
||||
|
Loading…
Reference in New Issue
Block a user