timelog cleanups
This commit is contained in:
		
							parent
							
								
									dff086a69d
								
							
						
					
					
						commit
						ea41778948
					
				| @ -25,43 +25,40 @@ instance Show TimeLog where | |||||||
| 
 | 
 | ||||||
| -- | Convert a time log to a ledger. | -- | Convert a time log to a ledger. | ||||||
| ledgerFromTimeLog :: TimeLog -> RawLedger | ledgerFromTimeLog :: TimeLog -> RawLedger | ||||||
| ledgerFromTimeLog tl =  | ledgerFromTimeLog tl = RawLedger [] [] (entriesFromTimeLogEntries $ timelog_entries tl) "" | ||||||
|     RawLedger [] [] (entriesFromTimeLogEntries $ timelog_entries tl) "" |  | ||||||
| 
 | 
 | ||||||
| -- | Convert time log entries to ledger entries. | -- | Convert time log entries to ledger entries. | ||||||
| entriesFromTimeLogEntries :: [TimeLogEntry] -> [Entry] | entriesFromTimeLogEntries :: [TimeLogEntry] -> [Entry] | ||||||
|  | entriesFromTimeLogEntries [] = [] | ||||||
|  | entriesFromTimeLogEntries [i] = entriesFromTimeLogEntries [i, clockoutFor i] | ||||||
|  | entriesFromTimeLogEntries (i:o:rest) = [entryFromTimeLogInOut i o] ++ entriesFromTimeLogEntries rest | ||||||
| 
 | 
 | ||||||
| -- | When there is a trailing clockin entry, provide the missing clockout. | -- | When there is a trailing clockin entry, provide the missing clockout. | ||||||
| -- "Now" would be ideal but requires IO, for now we make it the same as | -- "Now" would be preferable but requires IO, for now use the clockin time. | ||||||
| -- clockin time. | clockoutFor (TimeLogEntry _ t _) = TimeLogEntry 'o' t "" | ||||||
| entriesFromTimeLogEntries [clockin@(TimeLogEntry _ t _)] =  |  | ||||||
|     entriesFromTimeLogEntries [clockin, (TimeLogEntry 'o' t "")] |  | ||||||
| 
 | 
 | ||||||
| entriesFromTimeLogEntries [clockin,clockout] = | -- | Convert a timelog clockin and clockout entry to an equivalent ledger | ||||||
|     [ | -- entry, representing the time expenditure. | ||||||
|      Entry { | entryFromTimeLogInOut :: TimeLogEntry -> TimeLogEntry -> Entry | ||||||
|        edate         = indate, | entryFromTimeLogInOut i o = | ||||||
|        estatus       = True, |     Entry { | ||||||
|        ecode         = "", |       edate         = indate, -- ledger uses outdate | ||||||
|        edescription  = accountname, |       estatus       = True, | ||||||
|        ecomment      = "", |       ecode         = "", | ||||||
|        etransactions = [ |       edescription  = acctname, | ||||||
|         RawTransaction accountname amount "", |       ecomment      = "", | ||||||
|         RawTransaction "assets:TIME" (-amount) "" |       etransactions = txns, | ||||||
|        ], |       epreceding_comment_lines="" | ||||||
|        epreceding_comment_lines=""} |     } | ||||||
|     ] |  | ||||||
|     where |     where | ||||||
|       accountname = tlcomment clockin |       acctname = tlcomment i | ||||||
|       indate      = showDateFrom intime |       indate   = showDateFrom intime | ||||||
|       intime      = parsedatetime $ tldatetime clockin |       outdate  = showDateFrom outtime | ||||||
|       outtime     = parsedatetime $ tldatetime clockout |       intime   = parsedatetime $ tldatetime i | ||||||
|       hours       = fromRational (toRational (diffUTCTime outtime intime) / 3600) -- whatever |       outtime  = parsedatetime $ tldatetime o | ||||||
|       amount      = Amount (getcurrency "h") hours 1 |       hours    = fromRational (toRational (diffUTCTime outtime intime) / 3600) -- whatever.. | ||||||
| 
 |       amount   = Amount (getcurrency "h") hours 1 | ||||||
| entriesFromTimeLogEntries many = |       txns     = [RawTransaction acctname amount "", RawTransaction "assets:TIME" (-amount) ""] | ||||||
|     (entriesFromTimeLogEntries $ take 2 many) ++ |  | ||||||
|     (entriesFromTimeLogEntries $ drop 2 many) |  | ||||||
| 
 | 
 | ||||||
| showDateFrom :: UTCTime -> String | showDateFrom :: UTCTime -> String | ||||||
| showDateFrom = formatTime defaultTimeLocale "%Y/%m/%d" | showDateFrom = formatTime defaultTimeLocale "%Y/%m/%d" | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user