lib: get effective report start/end dates
This commit is contained in:
		
							parent
							
								
									ce8046bdb4
								
							
						
					
					
						commit
						7dcfcb05ec
					
				| @ -22,6 +22,9 @@ module Hledger.Reports.ReportOptions ( | ||||
|   queryOptsFromOpts, | ||||
|   transactionDateFn, | ||||
|   postingDateFn, | ||||
|   reportStartDate, | ||||
|   reportEndDate, | ||||
|   reportStartEndDates, | ||||
| 
 | ||||
|   tests_Hledger_Reports_ReportOptions | ||||
| ) | ||||
| @ -354,6 +357,33 @@ tests_queryOptsFromOpts = [ | ||||
|                                                              }) | ||||
|  ] | ||||
| 
 | ||||
| -- | The effective report start date is the one specified by options or queries, | ||||
| -- otherwise the earliest transaction or posting date in the journal, | ||||
| -- otherwise (for an empty journal) nothing. | ||||
| -- Needs IO to parse smart dates in options/queries. | ||||
| reportStartDate :: Journal -> ReportOpts -> IO (Maybe Day) | ||||
| reportStartDate j ropts = (fst <$>) <$> reportStartEndDates j ropts | ||||
| 
 | ||||
| -- | The effective report end date is the one specified by options or queries, | ||||
| -- otherwise the latest transaction or posting date in the journal, | ||||
| -- otherwise (for an empty journal) nothing. | ||||
| -- Needs IO to parse smart dates in options/queries. | ||||
| reportEndDate :: Journal -> ReportOpts -> IO (Maybe Day) | ||||
| reportEndDate j ropts = (fst <$>) <$> reportStartEndDates j ropts | ||||
| 
 | ||||
| reportStartEndDates :: Journal -> ReportOpts -> IO (Maybe (Day,Day)) | ||||
| reportStartEndDates j ropts = do | ||||
|   today <- getCurrentDay | ||||
|   let | ||||
|     q = queryFromOpts today ropts | ||||
|     mrequestedstartdate = queryStartDate False q | ||||
|     mrequestedenddate = queryEndDate False q | ||||
|   return $ | ||||
|     case journalDateSpan False j of  -- don't bother with secondary dates | ||||
|       DateSpan (Just journalstartdate) (Just journalenddate) -> | ||||
|         Just (fromMaybe journalstartdate mrequestedstartdate, fromMaybe journalenddate mrequestedenddate) | ||||
|       _ -> Nothing | ||||
| 
 | ||||
| 
 | ||||
| tests_Hledger_Reports_ReportOptions :: Test | ||||
| tests_Hledger_Reports_ReportOptions = TestList $ | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user