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 :: Day -> String
|
||||||
showDate = formatTime defaultTimeLocale "%C%y/%m/%d"
|
showDate = formatTime defaultTimeLocale "%C%y/%m/%d"
|
||||||
|
|
||||||
|
-- | Get the current local date.
|
||||||
getCurrentDay :: IO Day
|
getCurrentDay :: IO Day
|
||||||
getCurrentDay = do
|
getCurrentDay = do
|
||||||
t <- getZonedTime
|
t <- getZonedTime
|
||||||
return $ localDay (zonedTimeToLocalTime t)
|
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 :: Fractional a => UTCTime -> UTCTime -> a
|
||||||
elapsedSeconds t1 = realToFrac . diffUTCTime t1
|
elapsedSeconds t1 = realToFrac . diffUTCTime t1
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import Text.ParserCombinators.Parsec
|
|||||||
|
|
||||||
import Hledger.Data.Types (Journal, JournalContext(..), Commodity, JournalUpdate)
|
import Hledger.Data.Types (Journal, JournalContext(..), Commodity, JournalUpdate)
|
||||||
import Hledger.Data.Utils
|
import Hledger.Data.Utils
|
||||||
|
import Hledger.Data.Dates (getCurrentYear)
|
||||||
import Hledger.Data.Journal (nullctx, nulljournal, journalFinalise)
|
import Hledger.Data.Journal (nullctx, nulljournal, journalFinalise)
|
||||||
|
|
||||||
|
|
||||||
@ -25,7 +26,8 @@ parseJournalWith :: (GenParser Char JournalContext (JournalUpdate,JournalContext
|
|||||||
parseJournalWith p f s = do
|
parseJournalWith p f s = do
|
||||||
tc <- liftIO getClockTime
|
tc <- liftIO getClockTime
|
||||||
tl <- liftIO getCurrentLocalTime
|
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
|
Right (updates,ctx) -> do
|
||||||
j <- updates `ap` return nulljournal
|
j <- updates `ap` return nulljournal
|
||||||
case journalFinalise tc tl f s ctx j of
|
case journalFinalise tc tl f s ctx j of
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user