Safe Haskell | None |
---|
Local timestamps of varying granularity.
- class Local u where
- data LocalDate = LocalDate {
- _ld_day_base :: !Int32
- _ld_day_zone :: !Word8
- data LocalDateTime = LocalDateTime {
- _ldt_sec_base :: !Int64
- _ldt_sec_zone :: !Word8
- data LocalDateTimeMillis = LocalDateTimeMillis {
- _ldt_mil_base :: !Int64
- _ldt_mil_zone :: !Word8
- data LocalDateTimeMicros = LocalDateTimeMicros {
- _ldt_mic_base :: !Int64
- _ldt_mic_zone :: !Word8
- data LocalDateTimeNanos = LocalDateTimeNanos {
- _ldt_nan_base :: !Int64
- _ldt_nan_nano :: !Int16
- _ldt_nan_zone :: !Word8
- data LocalDateTimePicos = LocalDateTimePicos {
- _ldt_pic_base :: !Int64
- _ldt_pic_pico :: !Int32
- _ldt_pic_zone :: !Word8
- createLocalDate :: Year -> Month -> Day -> TimeZone -> LocalDate
- createLocalDateTime :: Year -> Month -> Day -> Hour -> Minute -> Second -> TimeZone -> LocalDateTime
- createLocalDateTimeMillis :: Year -> Month -> Day -> Hour -> Minute -> Second -> Millis -> TimeZone -> LocalDateTimeMillis
- createLocalDateTimeMicros :: Year -> Month -> Day -> Hour -> Minute -> Second -> Micros -> TimeZone -> LocalDateTimeMicros
- createLocalDateTimeNanos :: Year -> Month -> Day -> Hour -> Minute -> Second -> Nanos -> TimeZone -> LocalDateTimeNanos
- createLocalDateTimePicos :: Year -> Month -> Day -> Hour -> Minute -> Second -> Picos -> TimeZone -> LocalDateTimePicos
- getCurrentLocalDate :: City -> IO LocalDate
- getCurrentLocalDateTime :: City -> IO LocalDateTime
- getCurrentLocalDateTimeMillis :: City -> IO LocalDateTimeMillis
- getCurrentLocalDateTimeMicros :: City -> IO LocalDateTimeMicros
- getCurrentLocalDateTimeNanos :: City -> IO LocalDateTimeNanos
- getCurrentLocalDateTimePicos :: City -> IO LocalDateTimePicos
- newtype Transition = Transition {}
- getTransitions :: City -> IO [Transition]
- lastTransition :: (DateTime dt, Unix dt) => City -> dt -> IO (Maybe Transition)
- getCurrentLocalDate' :: [Transition] -> IO LocalDate
- getCurrentLocalDateTime' :: [Transition] -> IO LocalDateTime
- getCurrentLocalDateTimeMillis' :: [Transition] -> IO LocalDateTimeMillis
- getCurrentLocalDateTimeMicros' :: [Transition] -> IO LocalDateTimeMicros
- getCurrentLocalDateTimeNanos' :: [Transition] -> IO LocalDateTimeNanos
- getCurrentLocalDateTimePicos' :: [Transition] -> IO LocalDateTimePicos
- prettyLocalDate :: LocalDate -> String
- prettyLocalDateTime :: DateTimeZone dtz => dtz -> String
- baseUnixToUTC :: Int64 -> Int64
- baseUTCToUnix :: Int64 -> (Int64, Double)
Local Class
The local timestamp type class.
Get the base component of a local timestamp.
Get the zone component of a local timestamp.
Local Timestamps
Days since Unix epoch.
LocalDate | |
|
data LocalDateTime Source
Seconds since Unix epoch (including leap seconds).
data LocalDateTimeMillis Source
Milliseconds since Unix epoch (including leap seconds).
data LocalDateTimeMicros Source
Microseconds since Unix epoch (including leap seconds).
data LocalDateTimeNanos Source
Nanoseconds since Unix epoch (including leap seconds).
LocalDateTimeNanos | |
|
data LocalDateTimePicos Source
Picoseconds since Unix epoch (including leap seconds).
LocalDateTimePicos | |
|
Create Local Timestamps
createLocalDate :: Year -> Month -> Day -> TimeZone -> LocalDateSource
Create a local date.
>>> createLocalDate 2013 November 03 Pacific_Standard_Time 2013-11-03 PST
createLocalDateTime :: Year -> Month -> Day -> Hour -> Minute -> Second -> TimeZone -> LocalDateTimeSource
Create a local date and time.
>>> createLocalDateTime 2013 November 03 22 55 52 South_Africa_Standard_Time 2013-11-03 22:55:52 SAST
createLocalDateTimeMillis :: Year -> Month -> Day -> Hour -> Minute -> Second -> Millis -> TimeZone -> LocalDateTimeMillisSource
Create a local date and time with millisecond granularity.
>>> createLocalDateTimeMillis 2013 November 03 13 57 43 830 Mountain_Standard_Time 2013-11-03 13:57:43.830 MST
createLocalDateTimeMicros :: Year -> Month -> Day -> Hour -> Minute -> Second -> Micros -> TimeZone -> LocalDateTimeMicrosSource
Create a local date and time with microsecond granularity.
>>> createLocalDateTimeMicros 2013 November 03 21 01 42 903539 Coordinated_Universal_Time 2013-11-03 21:01:42.903539 UTC
createLocalDateTimeNanos :: Year -> Month -> Day -> Hour -> Minute -> Second -> Nanos -> TimeZone -> LocalDateTimeNanosSource
Create a local date and time with nanosecond granularity.
>>> createLocalDateTimeNanos 2013 November 04 06 05 07 016715087 Japan_Standard_Time 2013-11-04 06:05:07.016715087 JST
createLocalDateTimePicos :: Year -> Month -> Day -> Hour -> Minute -> Second -> Picos -> TimeZone -> LocalDateTimePicosSource
Create a local date and time with picosecond granularity.
>>> createLocalDateTimePicos 2013 November 03 23 13 56 838238648311 Eastern_European_Time 2013-11-03 23:13:56.838238648311 EET
Get Current Local Timestamps
getCurrentLocalDate :: City -> IO LocalDateSource
Get the current local date from the system clock.
>>> getCurrentLocalDate London 2013-11-03 GMT
getCurrentLocalDateTime :: City -> IO LocalDateTimeSource
Get the current local date and time from the system clock.
>>> getCurrentLocalDateTime New_York 2013-11-03 16:38:16 EST
getCurrentLocalDateTimeMillis :: City -> IO LocalDateTimeMillisSource
Get the current local date and time with millisecond granularity from the system clock.
>>> getCurrentLocalDateTimeMillis Auckland 2013-11-04 10:46:13.123 NZDT
getCurrentLocalDateTimeMicros :: City -> IO LocalDateTimeMicrosSource
Get the current local date and time with microsecond granularity from the system clock.
>>> getCurrentLocalDateTimeMicros Tel_Aviv 2013-11-03 23:55:30.935387 IST
getCurrentLocalDateTimeNanos :: City -> IO LocalDateTimeNanosSource
Get the current local date and time with nanosecond granularity from the system clock.
>>> getCurrentLocalDateTimeNanos Brussels 2013-11-03 23:01:07.337488000 CET
Note that this functions calls gettimeofday
behind the scenes. Therefore, the resultant
timestamp will have nanosecond granularity, but only microsecond resolution.
getCurrentLocalDateTimePicos :: City -> IO LocalDateTimePicosSource
Get the current local date and time with picosecond granularity from the system clock.
>>> getCurrentLocalDateTimePicos Karachi 2013-11-04 22:05:17.556043000000 PKT
Note that this functions calls gettimeofday
behind the scenes. Therefore, the resultant
timestamp will have picosecond granularity, but only microsecond resolution.
Time Zone Transition Times
newtype Transition Source
Time zone transition time.
getTransitions :: City -> IO [Transition]Source
Get a list of time zone transition times for the given city.
lastTransition :: (DateTime dt, Unix dt) => City -> dt -> IO (Maybe Transition)Source
Get the last time zone transition time for the given city and time.
Get Current Local Timestamps Using Preloaded Time Zone Transitions Times
getCurrentLocalDate' :: [Transition] -> IO LocalDateSource
Get the current local date from the system clock using preloaded transition times.
>>> ttimes <- getTransitions Tokyo >>> getCurrentLocalDate' ttimes 2013-11-04 JST
Use this function if you need to get the current local date more than once. The use of preloaded transition times will avoid unnecessary parsing of Olson files.
getCurrentLocalDateTime' :: [Transition] -> IO LocalDateTimeSource
Get the current local date and time from the system clock using preloaded transition times.
>>> ttimes <- getTransitions Moscow >>> getCurrentLocalDateTime' ttimes 2013-11-04 01:41:50 MSK
Use this function if you need to get the current local date and time more than once. The use of preloaded transition times will avoid unnecessary parsing of Olson files.
getCurrentLocalDateTimeMillis' :: [Transition] -> IO LocalDateTimeMillisSource
Get the current local date and time with millisecond granularity from the system clock using preloaded transition times.
>>> ttimes <- getTransitions Tehran >>> getCurrentLocalDateTimeMillis' ttimes 2013-11-04 01:20:49.435 IRST
Use this function if you need to get the current local date and time with millisecond granularity more than once. The use of preloaded transition times will avoid unnecessary parsing of Olson files.
getCurrentLocalDateTimeMicros' :: [Transition] -> IO LocalDateTimeMicrosSource
Get the current local date and time with microsecond granularity from the system clock using preloaded transition times.
>>> ttimes <- getTransitions Sao_Paulo >>> getCurrentLocalDateTimeMicros' ttimes 2013-11-03 19:58:50.405806 BRST
Use this function if you need to get the current local date and time with microsecond granularity more than once. The use of preloaded transition times will avoid unnecessary parsing of Olson files.
getCurrentLocalDateTimeNanos' :: [Transition] -> IO LocalDateTimeNanosSource
Get the current local date and time with nanosecond granularity from the system clock using preloaded transition times.
>>> ttimes <- getTransitions Mogadishu >>> getCurrentLocalDateTimeNanos' ttimes 2013-11-04 01:15:08.664426000 EAT
Use this function if you need to get the current local date and time with nanosecond granularity more than once. The use of preloaded transition times will avoid unnecessary parsing of Olson files.
Note that this functions calls gettimeofday
behind the scenes. Therefore, the resultant
timestamp will have nanosecond granularity, but only microsecond resolution.
getCurrentLocalDateTimePicos' :: [Transition] -> IO LocalDateTimePicosSource
Get the current local date and time with picosecond granularity from the system clock using preloaded transition times.
>>> ttimes <- getTransitions Baghdad >>> getCurrentLocalDateTimePicos' ttimes 2013-11-04 01:20:57.502906000000 AST
Use this function if you need to get the current local date and time with picosecond granularity more than once. The use of preloaded transition times will avoid unnecessary parsing of Olson files.
Note that this functions calls gettimeofday
behind the scenes. Therefore, the resultant
timestamp will have picosecond granularity, but only microsecond resolution.
Pretty Local Timestamps
prettyLocalDate :: LocalDate -> StringSource
Show a local date as a pretty string.
>>> prettyLocalDate $ createLocalDate 2014 September 25 Japan_Standard_Time "Thursday, September 25th, 2014 (JST)"
prettyLocalDateTime :: DateTimeZone dtz => dtz -> StringSource
Show a local date and time as a pretty string.
>>> getCurrentLocalDateTime Los_Angeles >>= return . prettyLocalDateTime "2:17 AM, Wednesday, January 1st, 2014 (PST)"
Base Conversions
baseUnixToUTC :: Int64 -> Int64Source
Convert Unix seconds into a UTC seconds.
baseUTCToUnix :: Int64 -> (Int64, Double)Source
Convert UTC seconds into Unix and leap seconds.