register: with --empty, intervals should continue to ends of the specified period
This commit is contained in:
		
							parent
							
								
									d824a982e7
								
							
						
					
					
						commit
						055080c5ca
					
				| @ -32,22 +32,28 @@ showRegisterReport :: [Opt] -> FilterSpec -> Ledger -> String | ||||
| showRegisterReport opts filterspec l = showpostings ps nullposting startbal | ||||
|     where | ||||
|       ps | interval == NoInterval = displayableps | ||||
|          | otherwise             = summarisePostings interval depth empty span displayableps | ||||
|          | otherwise             = summarisePostings interval depth empty filterspan displayableps | ||||
|       startbal = sumPostings precedingps | ||||
|       (precedingps,displayableps,_) = | ||||
|           postingsMatchingDisplayExpr (displayExprFromOpts opts) $ journalPostings $ filterJournalPostings filterspec $ journal l | ||||
|       (interval, depth, empty) = (intervalFromOpts opts, depthFromOpts opts, Empty `elem` opts) | ||||
|       span = datespan filterspec | ||||
|       filterspan = datespan filterspec | ||||
| 
 | ||||
| -- | Convert a list of postings into summary postings, one per interval. | ||||
| summarisePostings :: Interval -> Maybe Int -> Bool -> DateSpan -> [Posting] -> [Posting] | ||||
| summarisePostings interval depth empty span ps = concatMap summarisespan spans | ||||
| summarisePostings interval depth empty filterspan ps = concatMap summarisespan $ splitSpan interval reportspan | ||||
|     where | ||||
|       summarisespan s = summarisePostingsInDateSpan s depth empty (postingsinspan s) | ||||
|           where postingsinspan s = filter (isPostingInDateSpan s) ps | ||||
|       spans = splitSpan interval spantoreport | ||||
|           where spantoreport | empty = span | ||||
|                              | otherwise = postingsDateSpan ps | ||||
|       postingsinspan s = filter (isPostingInDateSpan s) ps | ||||
|       dataspan = postingsDateSpan ps | ||||
|       reportspan | empty = filterspan `orDatesFrom` dataspan | ||||
|                  | otherwise = dataspan | ||||
| 
 | ||||
| -- | Combine two datespans, filling any unspecified dates in the first | ||||
| -- with dates from the second. | ||||
| orDatesFrom (DateSpan a1 b1) (DateSpan a2 b2) = DateSpan a b | ||||
|     where a = if isJust a1 then a1 else a2 | ||||
|           b = if isJust b1 then b1 else b2 | ||||
| 
 | ||||
| -- | Date-sort and split a list of postings into three spans - postings matched | ||||
| -- by the given display expression, and the preceding and following postings. | ||||
|  | ||||
							
								
								
									
										43
									
								
								tests/reporting-intervals.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								tests/reporting-intervals.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | ||||
| # | ||||
| # monthly reporting interval, no end dates, shows just the intervals with data: | ||||
| -f- register --period 'monthly' | ||||
| <<< | ||||
| 2010/2/1 x | ||||
|   a  1 | ||||
|   b | ||||
| >>> | ||||
| 2010/02/01 - 2010/02/28         a                                 1            1 | ||||
|                                 b                                -1            0 | ||||
| # | ||||
| # with --empty, the same: | ||||
| -f- register --period 'monthly' --empty | ||||
| <<< | ||||
| 2010/2/1 x | ||||
|   a  1 | ||||
|   b | ||||
| >>> | ||||
| 2010/02/01 - 2010/02/28         a                                 1            1 | ||||
|                                 b                                -1            0 | ||||
| # | ||||
| # with --empty and start/end dates, show all intervals covering the specified period | ||||
| -f- register --period 'monthly from 2010/1/10 to 2010/3/15' --empty | ||||
| <<< | ||||
| 2010/2/1 x | ||||
|   a  1 | ||||
|   b | ||||
| >>> | ||||
| 2010/01/01 - 2010/01/31                                           0            0 | ||||
| 2010/02/01 - 2010/02/28         a                                 1            1 | ||||
|                                 b                                -1            0 | ||||
| 2010/03/01 - 2010/03/31                                           0            0 | ||||
| # | ||||
| # with just one start/end date, get the other from the data | ||||
| -f- register --period 'monthly from 2010/1/10' --empty | ||||
| <<< | ||||
| 2010/2/1 x | ||||
|   a  1 | ||||
|   b | ||||
| >>> | ||||
| 2010/01/01 - 2010/01/31                                           0            0 | ||||
| 2010/02/01 - 2010/02/28         a                                 1            1 | ||||
|                                 b                                -1            0 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user