Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Local time and time zones.
Synopsis
- type Hour = Int
- type Minute = Int
- pattern MV_TimeOfDay :: (MVector s Int64) -> MVector s TimeOfDay
- pattern MV_LocalTime :: (MVector s (Day, TimeOfDay)) -> MVector s LocalTime
- pattern V_TimeOfDay :: (Vector Int64) -> Vector TimeOfDay
- pattern V_LocalTime :: (Vector (Day, TimeOfDay)) -> Vector LocalTime
- data TimeOfDay = TimeOfDay {}
- data TimeZone = TimeZone {}
- type Minutes = Int
- type Hours = Int
- _timeZoneMinutes :: Lens' TimeZone Minutes
- _timeZoneSummerOnly :: Lens' TimeZone Bool
- _timeZoneName :: Lens' TimeZone String
- timeZoneOffsetString :: TimeZone -> String
- timeZoneOffsetStringColon :: TimeZone -> String
- minutesToTimeZone :: Minutes -> TimeZone
- hoursToTimeZone :: Hours -> TimeZone
- utc :: TimeZone
- getTimeZone :: UTCTime -> IO TimeZone
- getCurrentTimeZone :: IO TimeZone
- _todHour :: Lens' TimeOfDay Hour
- _todMin :: Lens' TimeOfDay Minute
- _todSec :: Lens' TimeOfDay DiffTime
- data LocalTime = LocalTime {
- localDay :: !Day
- localTimeOfDay :: !TimeOfDay
- minuteLength :: Hour -> Minute -> DiffTime
- midnight :: TimeOfDay
- midday :: TimeOfDay
- makeTimeOfDayValid :: Hour -> Minute -> DiffTime -> Maybe TimeOfDay
- timeOfDay :: Iso' DiffTime TimeOfDay
- addMinutes :: Minutes -> TimeOfDay -> (Days, TimeOfDay)
- dayFraction :: Iso' TimeOfDay Rational
- _localDay :: Lens' LocalTime Day
- _localTimeOfDay :: Lens' LocalTime TimeOfDay
- data ZonedTime = ZonedTime {}
- utcLocalTime :: TimeZone -> Iso' UTCTime LocalTime
- ut1LocalTime :: Rational -> Iso' UniversalTime LocalTime
- _zonedTimeToLocalTime :: Lens' ZonedTime LocalTime
- _zonedTimeZone :: Lens' ZonedTime TimeZone
- zonedTime :: Iso' (TimeZone, UTCTime) ZonedTime
- getZonedTime :: IO ZonedTime
- utcToLocalZonedTime :: UTCTime -> IO ZonedTime
- utcToLocalTimeOfDay :: TimeZone -> TimeOfDay -> (Days, TimeOfDay)
- localToUTCTimeOfDay :: TimeZone -> TimeOfDay -> (Days, TimeOfDay)
- timeToTimeOfDay :: DiffTime -> TimeOfDay
- timeOfDayToTime :: TimeOfDay -> DiffTime
- dayFractionToTimeOfDay :: Rational -> TimeOfDay
- timeOfDayToDayFraction :: TimeOfDay -> Rational
- utcToLocalTime :: TimeZone -> UTCTime -> LocalTime
- localTimeToUTC :: TimeZone -> LocalTime -> UTCTime
- ut1ToLocalTime :: Rational -> UniversalTime -> LocalTime
- localTimeToUT1 :: Rational -> LocalTime -> UniversalTime
- utcToZonedTime :: TimeZone -> UTCTime -> ZonedTime
- zonedTimeToUTC :: ZonedTime -> UTCTime
Documentation
Time of day in hour, minute, second.
Instances
Description of one time zone.
A TimeZone
is a whole number of minutes offset from UTC, together with
a name and a ‘summer time’ flag.
TimeZone | |
|
Instances
_timeZoneMinutes :: Lens' TimeZone Minutes Source #
_timeZoneSummerOnly :: Lens' TimeZone Bool Source #
_timeZoneName :: Lens' TimeZone String Source #
timeZoneOffsetString :: TimeZone -> String Source #
Text representing the offset of this timezone, e.g. "-0800" or
"+0400" (like %z
in formatTime
)
timeZoneOffsetStringColon :: TimeZone -> String Source #
Text representing the offset of this timezone in ISO 8601 style,
e.g. "-08:00" or
"+04:00" (like %N
in formatTime
)
minutesToTimeZone :: Minutes -> TimeZone Source #
Create a nameless non-summer timezone for this number of minutes
hoursToTimeZone :: Hours -> TimeZone Source #
Create a nameless non-summer timezone for this number of hours
getTimeZone :: UTCTime -> IO TimeZone Source #
Get the local time zone at the given time, varying as per summer time adjustments.
Performed by localtime_r or a similar call.
getCurrentTimeZone :: IO TimeZone Source #
Get the current local time zone.
getCurrentTimeZone
=getCurrentTime
>>=getTimeZone
> getCurrentTimeZone
JST
Local calendar date and time-of-day.
This type is appropriate for inputting from and outputting to the outside world.
To actually perform logic and arithmetic on local date-times, a LocalTime
should first be converted to a UTCTime
by the utcLocalTime
Iso.
See also: ZonedTime
.
LocalTime | |
|
Instances
minuteLength :: Hour -> Minute -> DiffTime Source #
The maximum possible length of a minute. Always 60s, except at 23:59 due to leap seconds.
minuteLength
23 59 =fromSeconds'
61minuteLength
_ _ =fromSeconds'
60
makeTimeOfDayValid :: Hour -> Minute -> DiffTime -> Maybe TimeOfDay Source #
Construct a TimeOfDay
from the hour, minute, and second.
Returns Nothing
if these constraints are not satisfied:
- 0 ≤
hour
≤ 23 - 0 ≤
minute
≤ 59 - 0 ≤
second
<minuteLength
hour
minute
addMinutes :: Minutes -> TimeOfDay -> (Days, TimeOfDay) Source #
Add some minutes to a TimeOfDay
; the result includes a day adjustment.
>addMinutes
10 (TimeOfDay
23 55 0) (1,00:05:00)
dayFraction :: Iso' TimeOfDay Rational Source #
Conversion between TimeOfDay
and the fraction of a day.
>TimeOfDay
6 0 0^.
dayFraction
1 % 4 >TimeOfDay
8 0 0^.
dayFraction
1 % 3 >dayFraction
#
(1 / 4) 06:00:00 >dayFraction
#
(1 / 3) 08:00:00
_localTimeOfDay :: Lens' LocalTime TimeOfDay Source #
This type is appropriate for inputting from and outputting to the outside world.
To actually perform logic and arithmetic on local date-times, a ZonedTime
should first be converted to a UTCTime
by the zonedTime
Iso.
Instances
utcLocalTime :: TimeZone -> Iso' UTCTime LocalTime Source #
Conversion between UTCTime
and LocalTime
.
> tz <-getCurrentTimeZone
>timeZoneName
tz "JST" >timeZoneOffsetString
tz "+0900" > now <-getCurrentTime
> now 2016-04-23 02:00:00.000000 UTC > let local = now^.
utcLocalTime
tz > local 2016-04-23 11:00:00.000000 >utcLocalTime
tz#
local 2016-04-23 02:00:00.000000 UTC
See also: zonedTime
.
ut1LocalTime :: Rational -> Iso' UniversalTime LocalTime Source #
Conversion between UniversalTime
and LocalTime
.
_zonedTimeToLocalTime :: Lens' ZonedTime LocalTime Source #
_zonedTimeZone :: Lens' ZonedTime TimeZone Source #
zonedTime :: Iso' (TimeZone, UTCTime) ZonedTime Source #
Conversion between (TimeZone
, UTCTime
) and ZonedTime
.
> now <-getZonedTime
> now 2016-04-04 16:00:00.000000 JST >zonedTime
#
now (JST,2016-04-04 07:00:00.000000 UTC) > (zonedTime
#
now)^.
zonedTime
2016-04-04 16:00:00.000000 JST
See also: utcLocalTime
.
getZonedTime :: IO ZonedTime Source #
Get the current local date, time, and time zone.
> getZonedTime
2016-04-23 11:57:22.516064 JST
See also: getCurrentTime
, getPOSIXTime
.
utcToLocalZonedTime :: UTCTime -> IO ZonedTime Source #
Convert a UTCTime
to a ZonedTime
according to the local time zone
returned by getTimeZone
.
See also: zonedTime
.
utcToLocalTimeOfDay :: TimeZone -> TimeOfDay -> (Days, TimeOfDay) Source #
Convert a UTC TimeOfDay
to a TimeOfDay
in some timezone, together
with a day adjustment.
utcToLocalTimeOfDay
=addMinutes
.
timeZoneMinutes
localToUTCTimeOfDay :: TimeZone -> TimeOfDay -> (Days, TimeOfDay) Source #
Convert a TimeOfDay
in some timezone to a UTC TimeOfDay
, together
with a day adjustment.
localToUTCTimeOfDay
=addMinutes
.
negate
.
timeZoneMinutes
timeToTimeOfDay :: DiffTime -> TimeOfDay Source #
Convert a DiffTime
of the duration since midnight to a TimeOfDay
.
Durations exceeding 24 hours will be treated as leap-seconds.
timeToTimeOfDay
=view
timeOfDay
timeToTimeOfDay
d ≡ d^.
timeOfDay
timeOfDayToTime :: TimeOfDay -> DiffTime Source #
Convert a TimeOfDay
to a DiffTime
of the duration since midnight.
TimeOfDay
greater than 24 hours will be treated as leap-seconds.
timeOfDayToTime
=review
timeOfDay
timeOfDayToTime
tod ≡timeOfDay
#
tod
dayFractionToTimeOfDay :: Rational -> TimeOfDay Source #
Convert a fraction of a day since midnight to a TimeOfDay
.
dayFractionToTimeOfDay
=review
dayFraction
timeOfDayToDayFraction :: TimeOfDay -> Rational Source #
Convert a TimeOfDay
to a fraction of a day since midnight.
timeOfDayToDayFraction
=view
dayFraction
utcToLocalTime :: TimeZone -> UTCTime -> LocalTime Source #
Convert a UTCTime
to a LocalTime
in the given TimeZone
.
utcToLocalTime
=view
.
utcLocalTime
localTimeToUTC :: TimeZone -> LocalTime -> UTCTime Source #
Convert a LocalTime
in the given TimeZone
to a UTCTime
.
localTimeToUTC
=review
.
utcLocalTime
ut1ToLocalTime :: Rational -> UniversalTime -> LocalTime Source #
Convert a UniversalTime
to a LocalTime
at the given medidian in
degrees East.
ut1ToLocalTime
=view
.
ut1LocalTime
localTimeToUT1 :: Rational -> LocalTime -> UniversalTime Source #
Convert a LocalTime
at the given meridian in degrees East to
a UniversalTime
.
localTimeToUT1
=review
.
ut1LocalTime
utcToZonedTime :: TimeZone -> UTCTime -> ZonedTime Source #
Convert a UTCTime
and the given TimeZone
into a ZonedTime
.
utcToZonedTime
z t =view
zonedTime
(z, t)
zonedTimeToUTC :: ZonedTime -> UTCTime Source #