-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moments-in-time: minor formatting changes
- Loading branch information
1 parent
6d35324
commit 18c0bb2
Showing
1 changed file
with
19 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
import Data.Time.Clock | ||
import Data.Time.Clock.POSIX | ||
import Data.Time.Format | ||
import qualified Data.Time as T | ||
import qualified Data.Time.Clock.POSIX as T | ||
|
||
render format time = | ||
formatTime defaultTimeLocale format time | ||
timeToString format time = | ||
T.formatTime T.defaultTimeLocale format time | ||
|
||
parse format str = | ||
parseTimeM acceptExtraWhitespace defaultTimeLocale format str | ||
|
||
acceptExtraWhitespace = False | ||
stringToTime format string = | ||
T.parseTimeM acceptExtraWhitespace | ||
T.defaultTimeLocale format string | ||
where | ||
acceptExtraWhitespace = False | ||
|
||
main = | ||
do | ||
now_utc :: UTCTime <- getCurrentTime | ||
(now_utc :: T.UTCTime) <- T.getCurrentTime | ||
putStrLn ("Now (UTC): " ++ show now_utc) | ||
|
||
now_posix :: POSIXTime <- getPOSIXTime | ||
(now_posix :: T.POSIXTime) <- T.getPOSIXTime | ||
putStrLn ("Now (POSIX): " ++ show now_posix) | ||
|
||
let t1_string = "2038-01-19 03:14:07" | ||
t1_utc :: UTCTime <- parse "%Y-%m-%d %H:%M:%S" t1_string | ||
(t1_utc :: T.UTCTime) <- | ||
stringToTime "%Y-%m-%d %H:%M:%S" t1_string | ||
putStrLn (show t1_utc) | ||
|
||
putStrLn (render "%Y-%m-%d" t1_utc) | ||
putStrLn (render "%I:%M %p" t1_utc) | ||
putStrLn (timeToString "%Y-%m-%d" t1_utc) | ||
putStrLn (timeToString "%I:%M %p" t1_utc) | ||
|
||
let t2_utc :: UTCTime = addUTCTime 15 t1_utc | ||
let (t2_utc :: T.UTCTime) = T.addUTCTime 15 t1_utc | ||
putStrLn (show t2_utc) | ||
putStrLn (show (t1_utc < t2_utc)) | ||
|
||
let diff :: NominalDiffTime = diffUTCTime t2_utc t1_utc | ||
let (diff :: T.NominalDiffTime) = T.diffUTCTime t2_utc t1_utc | ||
putStrLn (show diff) | ||
|
||
let t1_posix :: POSIXTime = utcTimeToPOSIXSeconds t1_utc | ||
let (t1_posix :: T.POSIXTime) = T.utcTimeToPOSIXSeconds t1_utc | ||
putStrLn (show t1_posix) | ||
putStrLn (show (posixSecondsToUTCTime t1_posix)) | ||
putStrLn (show (T.posixSecondsToUTCTime t1_posix)) |