various utilities & doc updates - commodities, daysInSpan, underline
This commit is contained in:
		
							parent
							
								
									3ebc4cca48
								
							
						
					
					
						commit
						fe5498f6c2
					
				| @ -67,6 +67,11 @@ splitspan startof next s@(DateSpan (Just b) (Just e)) | ||||
|               | b >= e = [] | ||||
|               | otherwise = [DateSpan (Just $ startof b) (Just $ next $ startof b)]  | ||||
|                             ++ splitspan' startof next (DateSpan (Just $ next $ startof b) (Just e)) | ||||
| 
 | ||||
| -- | Count the days in a DateSpan, or if it is open-ended return Nothing. | ||||
| daysInSpan :: DateSpan -> Maybe Integer | ||||
| daysInSpan (DateSpan (Just d1) (Just d2)) = Just $ diffDays d2 d1 | ||||
| daysInSpan _ = Nothing | ||||
|      | ||||
| -- | Parse a period expression to an Interval and overall DateSpan using | ||||
| -- the provided reference date. | ||||
|  | ||||
| @ -156,7 +156,7 @@ ledgerSubAccounts :: Ledger -> Account -> [Account] | ||||
| ledgerSubAccounts l Account{aname=a} =  | ||||
|     map (ledgerAccount l) $ filter (`isSubAccountNameOf` a) $ accountnames l | ||||
| 
 | ||||
| -- | List a ledger's transactions. | ||||
| -- | List a ledger's "transactions", ie postings with transaction info attached. | ||||
| ledgerTransactions :: Ledger -> [Transaction] | ||||
| ledgerTransactions l = rawLedgerTransactions $ rawledger l | ||||
| 
 | ||||
| @ -168,7 +168,7 @@ ledgerAccountTree depth l = treemap (ledgerAccount l) $ treeprune depth $ accoun | ||||
| ledgerAccountTreeAt :: Ledger -> Account -> Maybe (Tree Account) | ||||
| ledgerAccountTreeAt l acct = subtreeat acct $ ledgerAccountTree 9999 l | ||||
| 
 | ||||
| -- | The date span containing all the ledger's (filtered) transactions, | ||||
| -- | The (fully specified) date span containing all the ledger's (filtered) transactions, | ||||
| -- or DateSpan Nothing Nothing if there are none. | ||||
| ledgerDateSpan :: Ledger -> DateSpan | ||||
| ledgerDateSpan l | ||||
| @ -199,6 +199,9 @@ subaccounts = ledgerSubAccounts | ||||
| transactions :: Ledger -> [Transaction] | ||||
| transactions = ledgerTransactions | ||||
| 
 | ||||
| commodities :: Ledger -> [Commodity] | ||||
| commodities = nub . rawLedgerCommodities . rawledger | ||||
| 
 | ||||
| accounttree :: Int -> Ledger -> Tree Account | ||||
| accounttree = ledgerAccountTree | ||||
| 
 | ||||
|  | ||||
| @ -164,7 +164,7 @@ rawLedgerConvertTimeLog t l0 = l0 { ledger_txns = convertedTimeLog ++ ledger_txn | ||||
|     where convertedTimeLog = entriesFromTimeLogEntries t $ open_timelog_entries l0 | ||||
| 
 | ||||
| 
 | ||||
| -- | The date span containing all the raw ledger's transactions, | ||||
| -- | The (fully specified) date span containing all the raw ledger's transactions, | ||||
| -- or DateSpan Nothing Nothing if there are none. | ||||
| rawLedgerDateSpan :: RawLedger -> DateSpan | ||||
| rawLedgerDateSpan rl | ||||
|  | ||||
| @ -63,6 +63,12 @@ elideRight width s = | ||||
|       True -> take (width - 2) s ++ ".." | ||||
|       False -> s | ||||
| 
 | ||||
| underline :: String -> String | ||||
| underline s = s' ++ replicate (length s) '-' ++ "\n" | ||||
|     where s' | ||||
|             | last s == '\n' = s | ||||
|             | otherwise = s ++ "\n" | ||||
| 
 | ||||
| -- | Join multi-line strings as side-by-side rectangular strings of the same height, top-padded. | ||||
| concatTopPadded :: [String] -> String | ||||
| concatTopPadded strs = intercalate "\n" $ map concat $ transpose padded | ||||
|  | ||||
							
								
								
									
										3
									
								
								Tests.hs
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								Tests.hs
									
									
									
									
									
								
							| @ -444,6 +444,9 @@ tests = [ | ||||
|    "use the greatest precision" ~: do | ||||
|     (rawLedgerPrecisions $ canonicaliseAmounts False $ rawLedgerWithAmounts ["1","2.00"]) `is` [2,2] | ||||
| 
 | ||||
|   ,"commodities" ~: do | ||||
|     commodities ledger7 `is` [Commodity {symbol="$", side=L, spaced=False, comma=False, precision=2}] | ||||
| 
 | ||||
|   ,"dateSpanFromOpts" ~: do | ||||
|     let todaysdate = parsedate "2008/11/26" | ||||
|     let opts `gives` spans = show (dateSpanFromOpts todaysdate opts) `is` spans | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user