Safe Haskell | None |
---|---|
Language | Haskell2010 |
Local timestamps of varying granularity.
- class Local u where
- data LocalDate = LocalDate {
- _loc_day_base :: !Int32
- _loc_day_zone :: !Word8
- data LocalDateTime = LocalDateTime {
- _loc_sec_base :: !Int64
- _loc_sec_zone :: !Word8
- data LocalDateTimeMillis = LocalDateTimeMillis {
- _loc_mil_base :: !Int64
- _loc_mil_zone :: !Word8
- data LocalDateTimeMicros = LocalDateTimeMicros {
- _loc_mic_base :: !Int64
- _loc_mic_zone :: !Word8
- data LocalDateTimeNanos = LocalDateTimeNanos {
- _loc_nan_base :: !Int64
- _loc_nan_nano :: !Int16
- _loc_nan_zone :: !Word8
- data LocalDateTimePicos = LocalDateTimePicos {
- _loc_pic_base :: !Int64
- _loc_pic_pico :: !Int32
- _loc_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
Local Class
The local timestamp type class.
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 -> LocalDate Source
Create a local date.
>>> createLocalDate 2013 November 03 Pacific_Standard_Time 2013-11-03 PST
createLocalDateTime :: Year -> Month -> Day -> Hour -> Minute -> Second -> TimeZone -> LocalDateTime Source
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 -> LocalDateTimeMillis Source
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 -> LocalDateTimeMicros Source
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 -> LocalDateTimeNanos Source
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 -> LocalDateTimePicos Source
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 LocalDate Source
Get the current local date from the system clock.
>>> getCurrentLocalDate London 2013-11-03 GMT
getCurrentLocalDateTime :: City -> IO LocalDateTime Source
Get the current local date and time from the system clock.
>>> getCurrentLocalDateTime New_York 2013-11-03 16:38:16 EST
getCurrentLocalDateTimeMillis :: City -> IO LocalDateTimeMillis Source
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 LocalDateTimeMicros Source
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 LocalDateTimeNanos Source
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 LocalDateTimePicos Source
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 LocalDate Source
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 LocalDateTime Source
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 LocalDateTimeMillis Source
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 LocalDateTimeMicros Source
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 LocalDateTimeNanos Source
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 LocalDateTimePicos Source
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 -> String Source
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 -> String Source
Show a local date and time as a pretty string.
>>> getCurrentLocalDateTime Los_Angeles >>= return . prettyLocalDateTime "2:17 AM, Wednesday, January 1st, 2014 (PST)"