Copyright | (c) Dong Han 2020 (c) Kazu Yamamoto 2019 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This module provides functions directly work on SystemTime
type, a compact time type from time
library.
For advanced time editing, use time
library.
Synopsis
- data SystemTime = MkSystemTime {}
- getSystemTime' :: HasCallStack => IO SystemTime
- parseSystemTime :: TimeFormat -> CBytes -> IO SystemTime
- parseSystemTimeGMT :: TimeFormat -> CBytes -> SystemTime
- formatSystemTime :: TimeFormat -> SystemTime -> IO CBytes
- formatSystemTimeGMT :: TimeFormat -> SystemTime -> CBytes
- type TimeFormat = CBytes
- simpleDateFormat :: TimeFormat
- iso8061DateFormat :: TimeFormat
- webDateFormat :: TimeFormat
- mailDateFormat :: TimeFormat
SystemTime
data SystemTime #
SystemTime
is time returned by system clock functions.
Its semantics depends on the clock function, but the epoch is typically the beginning of 1970.
Note that systemNanoseconds
of 1E9 to 2E9-1 can be used to represent leap seconds.
Instances
Eq SystemTime | |
Defined in Data.Time.Clock.Internal.SystemTime (==) :: SystemTime -> SystemTime -> Bool # (/=) :: SystemTime -> SystemTime -> Bool # | |
Ord SystemTime | |
Defined in Data.Time.Clock.Internal.SystemTime compare :: SystemTime -> SystemTime -> Ordering # (<) :: SystemTime -> SystemTime -> Bool # (<=) :: SystemTime -> SystemTime -> Bool # (>) :: SystemTime -> SystemTime -> Bool # (>=) :: SystemTime -> SystemTime -> Bool # max :: SystemTime -> SystemTime -> SystemTime # min :: SystemTime -> SystemTime -> SystemTime # | |
Show SystemTime | |
Defined in Data.Time.Clock.Internal.SystemTime showsPrec :: Int -> SystemTime -> ShowS # show :: SystemTime -> String # showList :: [SystemTime] -> ShowS # | |
NFData SystemTime | |
Defined in Data.Time.Clock.Internal.SystemTime rnf :: SystemTime -> () # |
getSystemTime' :: HasCallStack => IO SystemTime Source #
A alternative version of getSystemTime'
based on libuv's uv_gettimeofday
, which also doesn't use pinned allocation.
Parsing
parseSystemTime :: TimeFormat -> CBytes -> IO SystemTime Source #
Parsing CBytes
to SystemTime
interpreting as localtime.
This is a wrapper for strptime_l().
Many implementations of strptime_l() do not support %Z and
some implementations of strptime_l() do not support %z, either.
systemNanoSeconds
is always set to 0.
The result depends on the TZ environment variable.
> setEnv TZ "Africa/Algiers" parseSystemTime simpleDateFormat "1970-01-01 00:00:00" MkSystemTime {systemSeconds = 0, systemNanoseconds = 0} > setEnv TZ "Asia/Shanghai" parseSystemTime simpleDateFormat "1970-01-01 00:00:00" MkSystemTime {systemSeconds = -28800, systemNanoseconds = 0}
parseSystemTimeGMT :: TimeFormat -> CBytes -> SystemTime Source #
Parsing CBytes
to SystemTime
interpreting as GMT.
This is a wrapper for strptime_l().
systemNanoSeconds
is always set to 0.
>>>
parseSystemTimeGMT webDateFormat "Thu, 01 Jan 1970 00:00:00 GMT"
MkSystemTime {systemSeconds = 0, systemNanoseconds = 0}
Formatting
formatSystemTime :: TimeFormat -> SystemTime -> IO CBytes Source #
Formatting SystemTime
to CBytes
in local time.
This is a wrapper for strftime_l(), systemNanoseconds
is ignored.
The result depends on the TZ environment variable.
formatSystemTimeGMT :: TimeFormat -> SystemTime -> CBytes Source #
Formatting SystemTime
to CBytes
in GMT.
This is a wrapper for strftime_l(), systemNanoseconds
is ignored.
>>>
formatSystemTimeGMT webDateFormat $ MkSystemTime 0 0
"Thu, 01 Jan 1970 00:00:00 GMT">>>
let ut = MkSystemTime 100 200
>>>
let str = formatSystemTimeGMT "%s" ut
>>>
let ut' = parseSystemTimeGMT "%s" str
>>>
((==) `on` systemSeconds) ut ut'
True>>>
((==) `on` systemNanoseconds) ut ut'
False
Format
type TimeFormat = CBytes Source #
strftime time format.
simpleDateFormat :: TimeFormat Source #
Simple format 2020-10-16 03:15:29
.
The value is "%Y-%m-%d %H:%M:%S".
This should be used with formatSystemTime
and parseSystemTime
.
iso8061DateFormat :: TimeFormat Source #
Simple format 2020-10-16T03:15:29
.
The value is "%Y-%m-%dT%H:%M:%S%z".
This should be used with formatSystemTime
and parseSystemTime
.
webDateFormat :: TimeFormat Source #
Format for web (RFC 2616).
The value is "%a, %d %b %Y %H:%M:%S GMT".
This should be used with formatSystemTimeGMT
and parseSystemTimeGMT
.
mailDateFormat :: TimeFormat Source #
Format for e-mail (RFC 5322).
The value is "%a, %d %b %Y %H:%M:%S %z".
This should be used with formatSystemTime
and parseSystemTime
.