use longer but standard and clearer getCurrentTime/Day
This commit is contained in:
		
							parent
							
								
									b0178b88cc
								
							
						
					
					
						commit
						44cbed59cb
					
				| @ -42,14 +42,11 @@ showDate d = formatTime defaultTimeLocale "%Y/%m/%d" d | ||||
| mkUTCTime :: Day -> TimeOfDay -> UTCTime | ||||
| mkUTCTime day tod = localTimeToUTC utc (LocalTime day tod) | ||||
| 
 | ||||
| today :: IO Day | ||||
| today = do | ||||
| getCurrentDay :: IO Day | ||||
| getCurrentDay = do | ||||
|     t <- getZonedTime | ||||
|     return $ localDay (zonedTimeToLocalTime t) | ||||
| 
 | ||||
| now :: IO UTCTime | ||||
| now = getCurrentTime  | ||||
| 
 | ||||
| elapsedSeconds :: Fractional a => UTCTime -> UTCTime -> a | ||||
| elapsedSeconds t1 t2 = realToFrac $ diffUTCTime t1 t2 | ||||
| 
 | ||||
| @ -231,7 +228,7 @@ Assumes any text in the parse stream has been lowercased. | ||||
| -} | ||||
| smartdate :: GenParser Char st SmartDate | ||||
| smartdate = do | ||||
|   let dateparsers = [yyyymmdd, ymd, ym, md, y, d, month, mon, today', yesterday, tomorrow, | ||||
|   let dateparsers = [yyyymmdd, ymd, ym, md, y, d, month, mon, today, yesterday, tomorrow, | ||||
|                      lastthisnextthing | ||||
|                     ] | ||||
|   (y,m,d) <- choice $ map try dateparsers | ||||
| @ -310,8 +307,8 @@ mon = do | ||||
|   let i = monIndex m | ||||
|   return ("",show i,"") | ||||
| 
 | ||||
| today',yesterday,tomorrow :: GenParser Char st SmartDate | ||||
| today'    = string "today"     >> return ("","","today") | ||||
| today,yesterday,tomorrow :: GenParser Char st SmartDate | ||||
| today     = string "today"     >> return ("","","today") | ||||
| yesterday = string "yesterday" >> return ("","","yesterday") | ||||
| tomorrow  = string "tomorrow"  >> return ("","","tomorrow") | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										12
									
								
								Options.hs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								Options.hs
									
									
									
									
									
								
							| @ -147,14 +147,14 @@ parseArguments = do | ||||
| -- based on today's date. | ||||
| fixOptDates :: [Opt] -> IO [Opt] | ||||
| fixOptDates opts = do | ||||
|   t <- today | ||||
|   return $ map (fixopt t) opts | ||||
|   d <- getCurrentDay | ||||
|   return $ map (fixopt d) opts | ||||
|   where | ||||
|     fixopt t (Begin s)   = Begin $ fixSmartDateStr t s | ||||
|     fixopt t (End s)     = End $ fixSmartDateStr t s | ||||
|     fixopt t (Display s) = -- hacky | ||||
|     fixopt d (Begin s)   = Begin $ fixSmartDateStr d s | ||||
|     fixopt d (End s)     = End $ fixSmartDateStr d s | ||||
|     fixopt d (Display s) = -- hacky | ||||
|         Display $ gsubRegexPRBy "\\[.+?\\]" fixbracketeddatestr s | ||||
|         where fixbracketeddatestr s = "[" ++ (fixSmartDateStr t $ init $ tail s) ++ "]" | ||||
|         where fixbracketeddatestr s = "[" ++ (fixSmartDateStr d $ init $ tail s) ++ "]" | ||||
|     fixopt _ o            = o | ||||
| 
 | ||||
| -- | Figure out the overall date span we should report on, based on any | ||||
|  | ||||
							
								
								
									
										2
									
								
								Utils.hs
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Utils.hs
									
									
									
									
									
								
							| @ -41,7 +41,7 @@ ledgerfromfilewithopts :: [Opt] -> [String] -> FilePath -> IO Ledger | ||||
| ledgerfromfilewithopts opts args f = do | ||||
|   s <- readFile f  | ||||
|   rl <- rawledgerfromstring s | ||||
|   reftime <- now | ||||
|   reftime <- getCurrentTime | ||||
|   return $ prepareLedger opts args reftime s rl | ||||
|             | ||||
| -- | Get a Ledger from your default ledger file, or raise an error. | ||||
|  | ||||
| @ -97,6 +97,6 @@ parseLedgerAndDo opts args cmd = do | ||||
|   -- and, doesn't work with stdin. kludge it, stdin won't work with ui command | ||||
|   let f' = if f == "-" then "/dev/null" else f | ||||
|   rawtext <- readFile f' | ||||
|   reftime <- now | ||||
|   reftime <- getCurrentTime | ||||
|   let runcmd = cmd opts args . prepareLedger opts args reftime rawtext | ||||
|   return f >>= runErrorT . parseLedgerFile >>= either (hPutStrLn stderr) runcmd | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user