Copyright | (C) 2014 Mihaly Barasz |
---|---|
License | Apache-2.0, see LICENSE |
Maintainer | Mihaly Barasz <klao@nilcons.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
- data TZ
- utcTZ :: TZ
- diffForPOSIX :: TZ -> Int64 -> Int
- timeZoneForPOSIX :: TZ -> Int64 -> TimeZone
- timeZoneForUTCTime :: TZ -> UTCTime -> TimeZone
- utcToLocalTimeTZ :: TZ -> UTCTime -> LocalTime
- data LocalToUTCResult
- = LTUNone { }
- | LTUUnique { }
- | LTUAmbiguous { }
- localTimeToUTCFull :: TZ -> LocalTime -> LocalToUTCResult
- localTimeToUTCTZ :: TZ -> LocalTime -> UTCTime
- data FromLocal
- localToPOSIX :: TZ -> Int64 -> FromLocal
- loadTZFromFile :: FilePath -> IO TZ
- loadTZFromDB :: String -> IO TZ
- loadSystemTZ :: String -> IO TZ
- loadLocalTZ :: IO TZ
Documentation
Universal -> Local direction
diffForPOSIX :: TZ -> Int64 -> Int Source
Returns the time difference (in seconds) for TZ at the given POSIX time.
timeZoneForPOSIX :: TZ -> Int64 -> TimeZone Source
timeZoneForUTCTime :: TZ -> UTCTime -> TimeZone Source
utcToLocalTimeTZ :: TZ -> UTCTime -> LocalTime Source
Returns the LocalTime
corresponding to the given UTCTime
in TZ
.
utcToLocalTimeTZ tz ut
is equivalent to
except when the time difference is not
an integral number of minutesutcToLocalTime
(timeZoneForPOSIX
tz ut) ut
Local -> Universal direction
data LocalToUTCResult Source
Fully descriptive result of a LocalTime to UTCTime conversion.
In case of LTUAmbiguous the first result is always earlier than the second one. Generally this only happens during the daylight saving -> standard time transition (ie. summer -> winter). So, the first result corresponds to interpreting the LocalTime as a daylight saving time and the second result as standard time in the given location.
But, if the location had some kind of administrative time
transition during which the clocks jumped back, then both results
can correspond to standard times (or daylight saving times) just
before and after the transition. You can always inspect the
timeZoneSummerOnly
field of the returned TimeZone
s to get an
idea what kind of transition was taking place.
TODO(klao): document the LTUNone behavior.
localTimeToUTCFull :: TZ -> LocalTime -> LocalToUTCResult Source
localTimeToUTCTZ :: TZ -> LocalTime -> UTCTime Source
localToPOSIX :: TZ -> Int64 -> FromLocal Source
Acquiring TZ
information
loadTZFromFile :: FilePath -> IO TZ Source
Reads and parses a time zone information file (in tzfile(5)
aka. Olson file format) and returns the corresponding TZ data
structure.
loadTZFromDB :: String -> IO TZ Source
Reads the corresponding file from the time zone database shipped with this package.
loadSystemTZ :: String -> IO TZ Source
Looks for the time zone file in the system timezone directory, which is
/usr/share/zoneinfo
, or if the TZDIR
environment variable is
set, then there.
loadLocalTZ :: IO TZ Source
Returns the local TZ
based on the TZ
and TZDIR
environment variables.
See tzset(3)
for details, but basically:
- If
TZ
environment variable is unset, weloadTZFromFile "/etc/localtime"
. - If
TZ
is set, but empty, weloadSystemTZ "UTC"
. - Otherwise, we just
loadSystemTZ
it.
Note, this means we don't support POSIX-style TZ
variables (like
"EST5EDT"
), only those that are explicitly present in the time
zone database.