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
- diffForAbbr :: TZ -> String -> Maybe Int
Documentation
Universal -> Local direction
diffForPOSIX :: TZ -> Int64 -> Int Source #
Returns the time difference (in seconds) for TZ at the given POSIX time.
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 #
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.
Note, this is unlikely to work on non-posix systems (e.g.,
Windows), use loadTZFromDB
or loadTZFromFile
instead.
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.
Utilities
diffForAbbr :: TZ -> String -> Maybe Int Source #
Returns a time difference (in seconds) corresponding to the abbreviation in the given time zone.
If there are multiple time differences associated with the same abbreviation, the one corresponding to the latest use is returned. (The latest use might be in the past or the future depending on whether the abbreviation is still in use.)
This function is here for informational purpose only, do not use it
for time conversion. (Instead, use localTimeToUTCFull
, and if the
result is ambiguous disambiguate between the possible results based
on the abbreviation.)