Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Time.Exts.Unix
Contents
Description
Unix timestamps of varying granularity.
- class Unix u where
- newtype UnixDate = UnixDate {}
- newtype UnixTime = UnixTime {}
- newtype UnixTimeMillis = UnixTimeMillis {}
- newtype UnixTimeMicros = UnixTimeMicros {}
- newtype UnixTimeNanos = UnixTimeNanos {}
- newtype UnixTimePicos = UnixTimePicos {}
- newtype UnixDateTime = UnixDateTime {}
- newtype UnixDateTimeMillis = UnixDateTimeMillis {}
- newtype UnixDateTimeMicros = UnixDateTimeMicros {}
- data UnixDateTimeNanos = UnixDateTimeNanos {
- _udt_nan_base :: !Int64
- _udt_nan_nano :: !Int16
- data UnixDateTimePicos = UnixDateTimePicos {
- _udt_pic_base :: !Int64
- _udt_pic_pico :: !Int32
- createUnixDate :: Year -> Month -> Day -> UnixDate
- createUnixTime :: Hour -> Minute -> Second -> UnixTime
- createUnixTimeMillis :: Hour -> Minute -> Second -> Millis -> UnixTimeMillis
- createUnixTimeMicros :: Hour -> Minute -> Second -> Micros -> UnixTimeMicros
- createUnixTimeNanos :: Hour -> Minute -> Second -> Nanos -> UnixTimeNanos
- createUnixTimePicos :: Hour -> Minute -> Second -> Picos -> UnixTimePicos
- createUnixDateTime :: Year -> Month -> Day -> Hour -> Minute -> Second -> UnixDateTime
- createUnixDateTimeMillis :: Year -> Month -> Day -> Hour -> Minute -> Second -> Millis -> UnixDateTimeMillis
- createUnixDateTimeMicros :: Year -> Month -> Day -> Hour -> Minute -> Second -> Micros -> UnixDateTimeMicros
- createUnixDateTimeNanos :: Year -> Month -> Day -> Hour -> Minute -> Second -> Nanos -> UnixDateTimeNanos
- createUnixDateTimePicos :: Year -> Month -> Day -> Hour -> Minute -> Second -> Picos -> UnixDateTimePicos
- getCurrentUnixDate :: IO UnixDate
- getCurrentUnixTime :: IO UnixTime
- getCurrentUnixTimeMillis :: IO UnixTimeMillis
- getCurrentUnixTimeMicros :: IO UnixTimeMicros
- getCurrentUnixTimeNanos :: IO UnixTimeNanos
- getCurrentUnixTimePicos :: IO UnixTimePicos
- getCurrentUnixDateTime :: IO UnixDateTime
- getCurrentUnixDateTimeMillis :: IO UnixDateTimeMillis
- getCurrentUnixDateTimeMicros :: IO UnixDateTimeMicros
- getCurrentUnixDateTimeNanos :: IO UnixDateTimeNanos
- getCurrentUnixDateTimePicos :: IO UnixDateTimePicos
- prettyUnixDate :: (Unix d, Date d) => d -> String
- prettyUnixTime :: (Unix t, Time t) => t -> String
- prettyUnixDateTime :: (Unix dt, DateTime dt) => dt -> String
Unix Class
The Unix timestamp type class.
Methods
Get the base component of a Unix timestamp.
Get the normalized base component of a Unix timestamp.
Unix Timestamps
Days since Unix epoch.
Constructors
UnixDate | |
Fields |
Instances
Seconds since midnight (excluding leap seconds).
Constructors
UnixTime | |
Fields |
Instances
newtype UnixTimeMillis Source
Milliseconds since midnight (excluding leap seconds).
Constructors
UnixTimeMillis | |
Fields |
Instances
newtype UnixTimeMicros Source
Microseconds since midnight (excluding leap seconds).
Constructors
UnixTimeMicros | |
Fields |
Instances
newtype UnixTimeNanos Source
Nanoseconds since midnight (excluding leap seconds).
Constructors
UnixTimeNanos | |
Fields |
Instances
newtype UnixTimePicos Source
Picoseconds since midnight (excluding leap seconds).
Constructors
UnixTimePicos | |
Fields |
Instances
newtype UnixDateTime Source
Seconds since Unix epoch (excluding leap seconds).
Constructors
UnixDateTime | |
Fields |
Instances
newtype UnixDateTimeMillis Source
Milliseconds since Unix epoch (excluding leap seconds).
Constructors
UnixDateTimeMillis | |
Fields |
Instances
newtype UnixDateTimeMicros Source
Microseconds since Unix epoch (excluding leap seconds).
Constructors
UnixDateTimeMicros | |
Fields |
Instances
data UnixDateTimeNanos Source
Nanoseconds since Unix epoch (excluding leap seconds).
Constructors
UnixDateTimeNanos | |
Fields
|
Instances
data UnixDateTimePicos Source
Picoseconds since Unix epoch (excluding leap seconds).
Constructors
UnixDateTimePicos | |
Fields
|
Instances
Create Unix Timestamps
createUnixDate :: Year -> Month -> Day -> UnixDate Source
Create a Unix date.
>>> createUnixDate 2013 November 3 2013-11-03
createUnixTime :: Hour -> Minute -> Second -> UnixTime Source
Create a Unix time.
>>> createUnixTime 4 52 7 04:52:07
createUnixTimeMillis :: Hour -> Minute -> Second -> Millis -> UnixTimeMillis Source
Create a Unix time with millisecond granularity.
>>> createUnixTimeMillis 15 22 47 2 15:22:47.002
createUnixTimeMicros :: Hour -> Minute -> Second -> Micros -> UnixTimeMicros Source
Create a Unix time with microsecond granularity.
>>> createUnixTimeMicros 10 6 33 575630 10:06:33.575630
createUnixTimeNanos :: Hour -> Minute -> Second -> Nanos -> UnixTimeNanos Source
Create a Unix time with nanosecond granularity.
>>> createUnixTimeNanos 23 19 54 465837593 23:19:54.465837593
createUnixTimePicos :: Hour -> Minute -> Second -> Picos -> UnixTimePicos Source
Create a Unix time with picosecond granularity.
>>> createUnixTimePicos 17 25 36 759230473534 17:25:36.759230473534
createUnixDateTime :: Year -> Month -> Day -> Hour -> Minute -> Second -> UnixDateTime Source
Create a Unix date and time.
>>> createUnixDateTime 2012 April 27 7 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 2 8 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 1 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 2 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
getCurrentUnixTime :: IO UnixTime Source
Get the current Unix time from the system clock.
>>> getCurrentUnixTime 05:45:06
getCurrentUnixTimeMillis :: IO UnixTimeMillis Source
Get the current Unix time with millisecond granularity from the system clock.
>>> getCurrentUnixTimeMillis 06:30:08.840
getCurrentUnixTimeMicros :: IO UnixTimeMicros Source
Get the current Unix time with microsecond granularity from the system clock.
>>> getCurrentUnixTimeMicros 06:40:39.102910
getCurrentUnixTimeNanos :: IO UnixTimeNanos Source
Get the current Unix time with nanosecond granularity from the system clock.
>>> getCurrentUnixTimeNanos 06:40:45.903610000
Note that this functions calls gettimeofday
behind the scenes. Therefore,
the resultant timestamp will have nanosecond granularity, but only microsecond
resolution.
getCurrentUnixTimePicos :: IO UnixTimePicos Source
Get the current Unix time with picosecond granularity from the system clock.
>>> getCurrentUnixTimePicos 06:47:15.379247000000
Note that this functions calls gettimeofday
behind the scenes. Therefore,
the resultant timestamp will have picosecond granularity, but only microsecond
resolution.
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 nanosecond 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"
prettyUnixTime :: (Unix t, Time t) => t -> String Source
Show a Unix time as a pretty string.
>>> getCurrentUnixTime >>= putStrLn . prettyUnixTime 9:12 AM
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"