mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-26 20:02:27 +03:00
parsing: assume current year when transaction dates have no year and there is no default year
This commit is contained in:
parent
151f549450
commit
5f1ebc694a
@ -35,11 +35,18 @@ import Hledger.Data.Utils
|
||||
showDate :: Day -> String
|
||||
showDate = formatTime defaultTimeLocale "%C%y/%m/%d"
|
||||
|
||||
-- | Get the current local date.
|
||||
getCurrentDay :: IO Day
|
||||
getCurrentDay = do
|
||||
t <- getZonedTime
|
||||
return $ localDay (zonedTimeToLocalTime t)
|
||||
|
||||
-- | Get the current local year.
|
||||
getCurrentYear :: IO Integer
|
||||
getCurrentYear = do
|
||||
(y,_,_) <- toGregorian `fmap` getCurrentDay
|
||||
return y
|
||||
|
||||
elapsedSeconds :: Fractional a => UTCTime -> UTCTime -> a
|
||||
elapsedSeconds t1 = realToFrac . diffUTCTime t1
|
||||
|
||||
|
@ -13,6 +13,7 @@ import Text.ParserCombinators.Parsec
|
||||
|
||||
import Hledger.Data.Types (Journal, JournalContext(..), Commodity, JournalUpdate)
|
||||
import Hledger.Data.Utils
|
||||
import Hledger.Data.Dates (getCurrentYear)
|
||||
import Hledger.Data.Journal (nullctx, nulljournal, journalFinalise)
|
||||
|
||||
|
||||
@ -25,7 +26,8 @@ parseJournalWith :: (GenParser Char JournalContext (JournalUpdate,JournalContext
|
||||
parseJournalWith p f s = do
|
||||
tc <- liftIO getClockTime
|
||||
tl <- liftIO getCurrentLocalTime
|
||||
case runParser p nullctx f s of
|
||||
y <- liftIO getCurrentYear
|
||||
case runParser p nullctx{ctxYear=Just y} f s of
|
||||
Right (updates,ctx) -> do
|
||||
j <- updates `ap` return nulljournal
|
||||
case journalFinalise tc tl f s ctx j of
|
||||
|
Loading…
Reference in New Issue
Block a user