time-exts-1.1.2: Efficient Timestamps

Safe HaskellNone
LanguageHaskell2010

Data.Time.Exts.Unix

Contents

Description

Unix timestamps of varying granularity.

Synopsis

Unix Class

class Unix u where Source

The Unix timestamp type class.

Methods

unixBase :: u -> Int64 Source

Get the base component of a Unix timestamp.

Unix Timestamps

Create Unix Timestamps

createUnixDate :: Year -> Month -> Day -> UnixDate Source

Create a Unix date.

>>> createUnixDate 2013 November 03
2013-11-03

createUnixDateTime :: Year -> Month -> Day -> Hour -> Minute -> Second -> UnixDateTime Source

Create a Unix date and time.

>>> createUnixDateTime 2012 April 27 07 37 30
2012-04-27 07:37:30

createUnixDateTimeMillis :: Year -> Month -> Day -> Hour -> Minute -> Second -> Millis -> UnixDateTimeMillis Source

Create a Unix date and time with millisecond granularity.

>>> createUnixDateTimeMillis 2014 February 02 08 52 37 983
2014-02-02 08:52:37.983

createUnixDateTimeMicros :: Year -> Month -> Day -> Hour -> Minute -> Second -> Micros -> UnixDateTimeMicros Source

Create a Unix date and time with microsecond granularity.

>>> createUnixDateTimeMicros 2011 January 22 17 34 13 138563
2011-01-22 17:34:13.138563

createUnixDateTimeNanos :: Year -> Month -> Day -> Hour -> Minute -> Second -> Nanos -> UnixDateTimeNanos Source

Create a Unix date and time with nanosecond granularity.

>>> createUnixDateTimeNanos 2012 June 28 01 30 35 688279651
2012-06-28 01:30:35.688279651

createUnixDateTimePicos :: Year -> Month -> Day -> Hour -> Minute -> Second -> Picos -> UnixDateTimePicos Source

Create a Unix date and time with picosecond granularity.

>>> createUnixDateTimePicos 2014 August 02 10 57 54 809479393286
2014-08-02 10:57:54.809479393286

Get Current Unix Timestamps

getCurrentUnixDate :: IO UnixDate Source

Get the current Unix date from the system clock.

>>> getCurrentUnixDate
2013-11-03

getCurrentUnixDateTime :: IO UnixDateTime Source

Get the current Unix date and time from the system clock.

>>> getCurrentUnixDateTime
2013-11-03 23:09:38

getCurrentUnixDateTimeMillis :: IO UnixDateTimeMillis Source

Get the current Unix date and time with millisecond granularity from the system clock.

>>> getCurrentUnixDateTimeMillis
2013-11-03 23:09:51.986

getCurrentUnixDateTimeMicros :: IO UnixDateTimeMicros Source

Get the current Unix date and time with microsecond granularity from the system clock.

>>> getCurrentUnixDateTimeMicros
2013-11-03 23:10:06.498559

getCurrentUnixDateTimeNanos :: IO UnixDateTimeNanos Source

Get the current Unix date and time with nanosecond granularity from the system clock.

>>> getCurrentUnixDateTimeNanos
2013-11-03 23:10:23.697893000

Note that this functions calls gettimeofday behind the scenes. Therefore, the resultant timestamp will have nanosecond granularity, but only microsecond resolution.

getCurrentUnixDateTimePicos :: IO UnixDateTimePicos Source

Get the current Unix date and time with picosecond granularity from the system clock.

>>> getCurrentUnixDateTimePicos
2013-11-03 23:10:44.633032000000

Note that this functions calls gettimeofday behind the scenes. Therefore, the resultant timestamp will have picosecond granularity, but only microsecond resolution.

Pretty Unix Timestamps

prettyUnixDate :: (Unix d, Date d) => d -> String Source

Show a Unix date as a pretty string.

>>> prettyUnixDate $ createUnixDate 2014 August 16
"Saturday, August 16th, 2014"

prettyUnixDateTime :: (Unix dt, DateTime dt) => dt -> String Source

Show a Unix date and time as a pretty string.

>>> getCurrentUnixDateTime >>= return . prettyUnixDateTime 
"6:44 AM, Tuesday, December 31st, 2013"