unix-time-0.1.5: Unix time parser/formatter and utilities

Safe HaskellNone

Data.UnixTime

Contents

Synopsis

Data structure

data UnixTime Source

Data structure for Unix time.

Constructors

UnixTime 

Fields

utSeconds :: !CTime

Seconds from 1st Jan 1970

utMicroSeconds :: !Int32

Micro seconds (i.e. 10^(-6))

Getting time

Parsing and formatting time

parseUnixTime :: Format -> ByteString -> UnixTimeSource

Parsing ByteString to UnixTime 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.

parseUnixTimeGMT :: Format -> ByteString -> UnixTimeSource

Parsing ByteString to UnixTime interpreting as GMT. This is a wrapper for strptime_l().

>>> parseUnixTimeGMT webDateFormat "Thu, 01 Jan 1970 00:00:00 GMT"
UnixTime {utSeconds = 0, utMicroSeconds = 0}

formatUnixTime :: Format -> UnixTime -> ByteStringSource

Formatting UnixTime to ByteString in local time. This is a wrapper for strftime_l().

formatUnixTimeGMT :: Format -> UnixTime -> ByteStringSource

Formatting UnixTime to ByteString in GMT. This is a wrapper for strftime_l().

>>> formatUnixTimeGMT webDateFormat $ UnixTime 0 0
"Thu, 01 Jan 1970 00:00:00 GMT"

Fromat

type Format = ByteStringSource

Format of the strptime()/strftime() style.

webDateFormat :: FormatSource

Format for web (RFC 2616). The value is "%a, %d %b %Y %H:%M:%S GMT". This should be used with formatUnixTimeGMT and parseUnixTimeGMT.

mailDateFormat :: FormatSource

Format for e-mail (RFC 5322). The value is "%a, %d %b %Y %H:%M:%S %z". This should be used with formatUnixTime and parseUnixTime.

Difference time

data UnixDiffTime Source

Data structure for UnixTime diff.

>>> (3 :: UnixDiffTime) + 2
UnixDiffTime 5 0
>>> (2 :: UnixDiffTime) - 5
UnixDiffTime (-3) 0
>>> (3 :: UnixDiffTime) * 2
UnixDiffTime 6 0

Instances

Eq UnixDiffTime 
Num UnixDiffTime

Arithmetic operations where (1::UnixDiffTime) means 1 second.

Ord UnixDiffTime 
Real UnixDiffTime 
Show UnixDiffTime 

diffUnixTime :: UnixTime -> UnixTime -> UnixDiffTimeSource

Calculating difference between two UnixTime.

>>> UnixTime 100 2000 `diffUnixTime` UnixTime 98 2100
UnixDiffTime 1 999900

addUnixDiffTime :: UnixTime -> UnixDiffTime -> UnixTimeSource

Adding difference to UnixTime.

>>> UnixTime 100 2000 `addUnixDiffTime` microSecondsToUnixDiffTime (-1003000)
UnixTime {utSeconds = 98, utMicroSeconds = 999000}

secondsToUnixDiffTime :: Integral a => a -> UnixDiffTimeSource

Creating difference from seconds.

>>> secondsToUnixDiffTime 100
UnixDiffTime 100 0

microSecondsToUnixDiffTime :: Integral a => a -> UnixDiffTimeSource

Creating difference from micro seconds.

>>> microSecondsToUnixDiffTime 12345678
UnixDiffTime 12 345678
>>> microSecondsToUnixDiffTime (-12345678)
UnixDiffTime (-12) (-345678)

Translating time