Z-IO-0.4.0.0: Simple and high performance IO toolkit for Haskell
Copyright(c) Dong Han 2020
(c) Kazu Yamamoto 2019
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Z.IO.Time

Description

This module provides functions directly work on SystemTime type, a compact time type from time library. For advanced time editing, use time library.

Synopsis

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.

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.