diff --git a/hledger-lib/Hledger/Data/Dates.hs b/hledger-lib/Hledger/Data/Dates.hs index cf151b7c8..065324435 100644 --- a/hledger-lib/Hledger/Data/Dates.hs +++ b/hledger-lib/Hledger/Data/Dates.hs @@ -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 diff --git a/hledger-lib/Hledger/Read/Utils.hs b/hledger-lib/Hledger/Read/Utils.hs index ddcb76c3f..d95d5a1dd 100644 --- a/hledger-lib/Hledger/Read/Utils.hs +++ b/hledger-lib/Hledger/Read/Utils.hs @@ -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