handle "from ... to ..." period expressions
This commit is contained in:
parent
c3bec2a3de
commit
dd93418784
@ -54,13 +54,17 @@ dayToUTC :: Day -> UTCTime
|
|||||||
dayToUTC d = localTimeToUTC utc (LocalTime d midnight)
|
dayToUTC d = localTimeToUTC utc (LocalTime d midnight)
|
||||||
|
|
||||||
-- | Convert a period expression to a date span using the provided reference date.
|
-- | Convert a period expression to a date span using the provided reference date.
|
||||||
spanFromPeriodExpr refdate = spanFromSmartDateString refdate
|
spanFromPeriodExpr refdate = fromparse . parsewith (periodexpr refdate)
|
||||||
|
|
||||||
-- | Convert a smart date string to a date span using the provided reference date.
|
-- | Convert a smart date string to a date span using the provided reference date.
|
||||||
spanFromSmartDateString :: Day -> String -> DateSpan
|
spanFromSmartDateString :: Day -> String -> DateSpan
|
||||||
spanFromSmartDateString refdate s = DateSpan (Just b) (Just e)
|
spanFromSmartDateString refdate s = spanFromSmartDate refdate sdate
|
||||||
where
|
where
|
||||||
sdate = fromparse $ parsewith smartdate s
|
sdate = fromparse $ parsewith smartdate s
|
||||||
|
|
||||||
|
spanFromSmartDate :: Day -> SmartDate -> DateSpan
|
||||||
|
spanFromSmartDate refdate sdate = DateSpan (Just b) (Just e)
|
||||||
|
where
|
||||||
(ry,rm,rd) = toGregorian refdate
|
(ry,rm,rd) = toGregorian refdate
|
||||||
(b,e) = span sdate
|
(b,e) = span sdate
|
||||||
span :: SmartDate -> (Day,Day)
|
span :: SmartDate -> (Day,Day)
|
||||||
@ -288,3 +292,21 @@ lastthisnextthing = do
|
|||||||
]
|
]
|
||||||
return ("",r,p)
|
return ("",r,p)
|
||||||
|
|
||||||
|
periodexpr :: Day -> Parser DateSpan
|
||||||
|
periodexpr rdate = try (doubledateperiod rdate) <|> (singledateperiod rdate)
|
||||||
|
|
||||||
|
doubledateperiod :: Day -> Parser DateSpan
|
||||||
|
doubledateperiod rdate = do
|
||||||
|
string "from"
|
||||||
|
many spacenonewline
|
||||||
|
b <- smartdate
|
||||||
|
many spacenonewline
|
||||||
|
string "to"
|
||||||
|
many spacenonewline
|
||||||
|
e <- smartdate
|
||||||
|
let span = DateSpan (Just $ fixSmartDate rdate b) (Just $ fixSmartDate rdate e)
|
||||||
|
return span
|
||||||
|
|
||||||
|
singledateperiod :: Day -> Parser DateSpan
|
||||||
|
singledateperiod rdate = smartdate >>= return . spanFromSmartDate rdate
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ instance Show ModifierEntry where
|
|||||||
show e = "= " ++ (valueexpr e) ++ "\n" ++ unlines (map show (m_transactions e))
|
show e = "= " ++ (valueexpr e) ++ "\n" ++ unlines (map show (m_transactions e))
|
||||||
|
|
||||||
instance Show PeriodicEntry where
|
instance Show PeriodicEntry where
|
||||||
show e = "~ " ++ (periodexpr e) ++ "\n" ++ unlines (map show (p_transactions e))
|
show e = "~ " ++ (periodicexpr e) ++ "\n" ++ unlines (map show (p_transactions e))
|
||||||
|
|
||||||
nullentry = Entry {
|
nullentry = Entry {
|
||||||
edate=parsedate "1900/1/1",
|
edate=parsedate "1900/1/1",
|
||||||
|
|||||||
@ -56,7 +56,7 @@ data ModifierEntry = ModifierEntry {
|
|||||||
|
|
||||||
-- | a ledger "periodic" entry. Currently ignored.
|
-- | a ledger "periodic" entry. Currently ignored.
|
||||||
data PeriodicEntry = PeriodicEntry {
|
data PeriodicEntry = PeriodicEntry {
|
||||||
periodexpr :: String,
|
periodicexpr :: String,
|
||||||
p_transactions :: [RawTransaction]
|
p_transactions :: [RawTransaction]
|
||||||
} deriving (Eq)
|
} deriving (Eq)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user