Safe Haskell | None |
---|
- data UnixTime = UnixTime {
- utSeconds :: !CTime
- utMicroSeconds :: !Int32
- getUnixTime :: IO UnixTime
- parseUnixTime :: Format -> ByteString -> UnixTime
- parseUnixTimeGMT :: Format -> ByteString -> UnixTime
- formatUnixTime :: Format -> UnixTime -> ByteString
- formatUnixTimeGMT :: Format -> UnixTime -> ByteString
- type Format = ByteString
- webDateFormat :: Format
- mailDateFormat :: Format
- data UnixDiffTime
- diffUnixTime :: UnixTime -> UnixTime -> UnixDiffTime
- addUnixDiffTime :: UnixTime -> UnixDiffTime -> UnixTime
- secondsToUnixDiffTime :: Integral a => a -> UnixDiffTime
- microSecondsToUnixDiffTime :: Integral a => a -> UnixDiffTime
- fromEpochTime :: EpochTime -> UnixTime
- toEpochTime :: UnixTime -> EpochTime
- fromClockTime :: ClockTime -> UnixTime
- toClockTime :: UnixTime -> ClockTime
Data structure
Data structure for Unix time.
UnixTime | |
|
Getting time
getUnixTime :: IO UnixTimeSource
Getting UnixTime
from OS.
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.
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
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
fromEpochTime :: EpochTime -> UnixTimeSource
From EpochTime
to UnixTime
setting utMicroSeconds
to 0.
toEpochTime :: UnixTime -> EpochTimeSource
From UnixTime
to EpochTime
ignoring utMicroSeconds
.