mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-13 06:05:17 +03:00
journal: json: Add source positions to forecast transactions
This commit is contained in:
parent
eff29ac10d
commit
9443fe0e0d
@ -61,6 +61,7 @@ instance Show PeriodicTransaction where
|
||||
("ptperiodexpr=" ++ show ptperiodexpr)
|
||||
("ptinterval=" ++ show ptinterval)
|
||||
("ptspan=" ++ show (show ptspan))
|
||||
("ptsourcepos=" ++ show ptsourcepos)
|
||||
("ptstatus=" ++ show (show ptstatus))
|
||||
("ptcode=" ++ show ptcode)
|
||||
("ptdescription=" ++ show ptdescription)
|
||||
@ -236,7 +237,8 @@ runPeriodicTransaction PeriodicTransaction{..} requestedspan =
|
||||
[ t{tdate=d} | (DateSpan (Just d) _) <- alltxnspans, spanContainsDate requestedspan d ]
|
||||
where
|
||||
t = nulltransaction{
|
||||
tstatus = ptstatus
|
||||
tsourcepos = ptsourcepos
|
||||
,tstatus = ptstatus
|
||||
,tcode = ptcode
|
||||
,tdescription = ptdescription
|
||||
,tcomment = ptcomment
|
||||
|
@ -455,6 +455,7 @@ data PeriodicTransaction = PeriodicTransaction {
|
||||
ptinterval :: Interval, -- ^ the interval at which this transaction recurs
|
||||
ptspan :: DateSpan, -- ^ the (possibly unbounded) period during which this transaction recurs. Contains a whole number of intervals.
|
||||
--
|
||||
ptsourcepos :: (SourcePos, SourcePos), -- ^ the file position where the period expression starts, and where the last posting ends
|
||||
ptstatus :: Status, -- ^ some of Transaction's fields
|
||||
ptcode :: Text,
|
||||
ptdescription :: Text,
|
||||
@ -467,6 +468,7 @@ nullperiodictransaction = PeriodicTransaction{
|
||||
ptperiodexpr = ""
|
||||
,ptinterval = def
|
||||
,ptspan = def
|
||||
,ptsourcepos = (SourcePos "" (mkPos 1) (mkPos 1), SourcePos "" (mkPos 1) (mkPos 1))
|
||||
,ptstatus = Unmarked
|
||||
,ptcode = ""
|
||||
,ptdescription = ""
|
||||
|
@ -708,6 +708,7 @@ transactionmodifierp = do
|
||||
-- relative to Y/1/1. If not, they are calculated related to today as usual.
|
||||
periodictransactionp :: MonadIO m => JournalParser m PeriodicTransaction
|
||||
periodictransactionp = do
|
||||
startpos <- getSourcePos
|
||||
|
||||
-- first line
|
||||
char '~' <?> "periodic transaction"
|
||||
@ -752,10 +753,14 @@ periodictransactionp = do
|
||||
-- next lines; use same year determined above
|
||||
postings <- postingsp (Just $ first3 $ toGregorian refdate)
|
||||
|
||||
endpos <- getSourcePos
|
||||
let sourcepos = (startpos, endpos)
|
||||
|
||||
return $ nullperiodictransaction{
|
||||
ptperiodexpr=periodtxt
|
||||
,ptinterval=interval
|
||||
,ptspan=spn
|
||||
,ptsourcepos=sourcepos
|
||||
,ptstatus=status
|
||||
,ptcode=code
|
||||
,ptdescription=description
|
||||
@ -892,6 +897,7 @@ tests_JournalReader = testGroup "JournalReader" [
|
||||
ptperiodexpr = "monthly from 2018/6"
|
||||
,ptinterval = Months 1
|
||||
,ptspan = DateSpan (Just $ fromGregorian 2018 6 1) Nothing
|
||||
,ptsourcepos = (SourcePos "" (mkPos 1) (mkPos 1), SourcePos "" (mkPos 2) (mkPos 1))
|
||||
,ptdescription = ""
|
||||
,ptcomment = "In 2019 we will change this\n"
|
||||
}
|
||||
@ -902,6 +908,7 @@ tests_JournalReader = testGroup "JournalReader" [
|
||||
ptperiodexpr = "monthly from 2018/6"
|
||||
,ptinterval = Months 1
|
||||
,ptspan = DateSpan (Just $ fromGregorian 2018 6 1) Nothing
|
||||
,ptsourcepos = (SourcePos "" (mkPos 1) (mkPos 1), SourcePos "" (mkPos 2) (mkPos 1))
|
||||
,ptdescription = "In 2019 we will change this"
|
||||
,ptcomment = ""
|
||||
}
|
||||
@ -912,6 +919,7 @@ tests_JournalReader = testGroup "JournalReader" [
|
||||
ptperiodexpr = "monthly"
|
||||
,ptinterval = Months 1
|
||||
,ptspan = DateSpan Nothing Nothing
|
||||
,ptsourcepos = (SourcePos "" (mkPos 1) (mkPos 1), SourcePos "" (mkPos 2) (mkPos 1))
|
||||
,ptdescription = "Next year blah blah"
|
||||
,ptcomment = ""
|
||||
}
|
||||
@ -922,6 +930,7 @@ tests_JournalReader = testGroup "JournalReader" [
|
||||
ptperiodexpr = "2019-01-04"
|
||||
,ptinterval = NoInterval
|
||||
,ptspan = DateSpan (Just $ fromGregorian 2019 1 4) (Just $ fromGregorian 2019 1 5)
|
||||
,ptsourcepos = (SourcePos "" (mkPos 1) (mkPos 1), SourcePos "" (mkPos 2) (mkPos 1))
|
||||
,ptdescription = ""
|
||||
,ptcomment = ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user