Haskell Hierarchical Libraries (time package)Source codeContentsIndex
Data.Time.LocalTime
Contents
Time zones
Time of day
Local Time
UNIX-style formatting
Synopsis
data TimeZone = TimeZone {
timeZoneMinutes :: Int
timeZoneSummerOnly :: Bool
timeZoneName :: String
}
timeZoneOffsetString :: TimeZone -> String
minutesToTimeZone :: Int -> TimeZone
hoursToTimeZone :: Int -> TimeZone
utc :: TimeZone
getTimeZone :: UTCTime -> IO TimeZone
getCurrentTimeZone :: IO TimeZone
data TimeOfDay = TimeOfDay {
todHour :: Int
todMin :: Int
todSec :: Pico
}
midnight :: TimeOfDay
midday :: TimeOfDay
utcToLocalTimeOfDay :: TimeZone -> TimeOfDay -> (Integer, TimeOfDay)
localToUTCTimeOfDay :: TimeZone -> TimeOfDay -> (Integer, TimeOfDay)
timeToTimeOfDay :: DiffTime -> TimeOfDay
timeOfDayToTime :: TimeOfDay -> DiffTime
dayFractionToTimeOfDay :: Rational -> TimeOfDay
timeOfDayToDayFraction :: TimeOfDay -> Rational
data LocalTime = LocalTime {
localDay :: Day
localTimeOfDay :: TimeOfDay
}
utcToLocalTime :: TimeZone -> UTCTime -> LocalTime
localTimeToUTC :: TimeZone -> LocalTime -> UTCTime
ut1ToLocalTime :: Rational -> UniversalTime -> LocalTime
localTimeToUT1 :: Rational -> LocalTime -> UniversalTime
data ZonedTime = ZonedTime {
zonedTimeToLocalTime :: LocalTime
zonedTimeZone :: TimeZone
}
utcToZonedTime :: TimeZone -> UTCTime -> ZonedTime
zonedTimeToUTC :: ZonedTime -> UTCTime
getZonedTime :: IO ZonedTime
utcToLocalZonedTime :: UTCTime -> IO ZonedTime
class FormatTime t where
formatCharacter :: Char -> Maybe (TimeLocale -> t -> String)
formatTime :: FormatTime t => TimeLocale -> String -> t -> String
Time zones
data TimeZone
A TimeZone is a whole number of minutes offset from UTC, together with a name and a "just for summer" flag.
Constructors
TimeZone
timeZoneMinutes :: IntThe number of minutes offset from UTC. Positive means local time will be later in the day than UTC.
timeZoneSummerOnly :: BoolIs this time zone just persisting for the summer?
timeZoneName :: StringThe name of the zone, typically a three- or four-letter acronym.
show/hide Instances
timeZoneOffsetString :: TimeZone -> String
Text representing the offset of this timezone, such as "-0800" or "+0400" (like %z in formatTime)
minutesToTimeZone :: Int -> TimeZone
Create a nameless non-summer timezone for this number of minutes
hoursToTimeZone :: Int -> TimeZone
Create a nameless non-summer timezone for this number of hours
utc :: TimeZone
The UTC time zone
getTimeZone :: UTCTime -> IO TimeZone
Get the local time-zone for a given time (varying as per summertime adjustments)
getCurrentTimeZone :: IO TimeZone
Get the current time-zone
Time of day
data TimeOfDay
Time of day as represented in hour, minute and second (with picoseconds), typically used to express local time of day.
Constructors
TimeOfDay
todHour :: Intrange 0 - 23
todMin :: Intrange 0 - 59
todSec :: PicoNote that 0 <= todSec < 61, accomodating leap seconds. Any local minute may have a leap second, since leap seconds happen in all zones simultaneously
show/hide Instances
midnight :: TimeOfDay
Hour zero
midday :: TimeOfDay
Hour twelve
utcToLocalTimeOfDay :: TimeZone -> TimeOfDay -> (Integer, TimeOfDay)
Convert a ToD in UTC to a ToD in some timezone, together with a day adjustment.
localToUTCTimeOfDay :: TimeZone -> TimeOfDay -> (Integer, TimeOfDay)
Convert a ToD in some timezone to a ToD in UTC, together with a day adjustment.
timeToTimeOfDay :: DiffTime -> TimeOfDay
Get a TimeOfDay given a time since midnight. Time more than 24h will be converted to leap-seconds.
timeOfDayToTime :: TimeOfDay -> DiffTime
Find out how much time since midnight a given TimeOfDay is.
dayFractionToTimeOfDay :: Rational -> TimeOfDay
Get a TimeOfDay given the fraction of a day since midnight.
timeOfDayToDayFraction :: TimeOfDay -> Rational
Get the fraction of a day since midnight given a TimeOfDay.
Local Time
data LocalTime
A simple day and time aggregate, where the day is of the specified parameter, and the time is a TimeOfDay. Conversion of this (as local civil time) to UTC depends on the time zone. Conversion of this (as local mean time) to UT1 depends on the longitude.
Constructors
LocalTime
localDay :: Day
localTimeOfDay :: TimeOfDay
show/hide Instances
utcToLocalTime :: TimeZone -> UTCTime -> LocalTime
show a UTC time in a given time zone as a LocalTime
localTimeToUTC :: TimeZone -> LocalTime -> UTCTime
find out what UTC time a given LocalTime in a given time zone is
ut1ToLocalTime :: Rational -> UniversalTime -> LocalTime
1st arg is observation meridian in degrees, positive is East
localTimeToUT1 :: Rational -> LocalTime -> UniversalTime
1st arg is observation meridian in degrees, positive is East
data ZonedTime
A local time together with a TimeZone.
Constructors
ZonedTime
zonedTimeToLocalTime :: LocalTime
zonedTimeZone :: TimeZone
show/hide Instances
utcToZonedTime :: TimeZone -> UTCTime -> ZonedTime
zonedTimeToUTC :: ZonedTime -> UTCTime
getZonedTime :: IO ZonedTime
utcToLocalZonedTime :: UTCTime -> IO ZonedTime
UNIX-style formatting
class FormatTime t where
Methods
formatCharacter :: Char -> Maybe (TimeLocale -> t -> String)
show/hide Instances
formatTime :: FormatTime t => TimeLocale -> String -> t -> String

Substitute various time-related information for each %-code in the string, as per formatCharacter.

For all types (note these three are done here, not by formatCharacter):

%%
%
%t
tab
%n
newline

For TimeZone (and ZonedTime and UTCTime):

%z
timezone offset
%Z
timezone name

For LocalTime (and ZonedTime and UTCTime):

%c
as dateTimeFmt locale (e.g. %a %b %e %H:%M:%S %Z %Y)

For TimeOfDay (and LocalTime and ZonedTime and UTCTime):

%R
same as %H:%M
%T
same as %H:%M:%S
%X
as timeFmt locale (e.g. %H:%M:%S)
%r
as time12Fmt locale (e.g. %I:%M:%S %p)
%P
day half from (amPm locale), converted to lowercase, am, pm
%p
day half from (amPm locale), AM, PM
%H
hour, 24-hour, leading 0 as needed, 00 - 23
%I
hour, 12-hour, leading 0 as needed, 01 - 12
%k
hour, 24-hour, leading space as needed, 0 - 23
%l
hour, 12-hour, leading space as needed, 1 - 12
%M
minute, 00 - 59
%S
second with decimal part if not an integer, 00 - 60.999999999999

For UTCTime and ZonedTime:

%s
number of seconds since the Unix epoch

For Day (and LocalTime and ZonedTime and UTCTime):

%D
same as %m/%d/%y
%F
same as %Y-%m-%d
%x
as dateFmt locale (e.g. %m/%d/%y)
%Y
year
%y
last two digits of year, 00 - 99
%C
century (being the first two digits of the year), 00 - 99
%B
month name, long form (fst from months locale), January - December
%b, %h
month name, short form (snd from months locale), Jan - Dec
%m
month of year, leading 0 as needed, 01 - 12
%d
day of month, leading 0 as needed, 01 - 31
%e
day of month, leading space as needed, 1 - 31
%j
day of year for Ordinal Date format, 001 - 366
%G
year for Week Date format
%g
last two digits of year for Week Date format, 00 - 99
%V
week for Week Date format, 01 - 53
%u
day for Week Date format, 1 - 7
%a
day of week, short form (snd from wDays locale), Sun - Sat
%A
day of week, long form (fst from wDays locale), Sunday - Saturday
%U
week number of year, where weeks start on Sunday (as sundayStartWeek), 01 - 53
%w
day of week number, 0 (= Sunday) - 6 (= Saturday)
%W
week number of year, where weeks start on Monday (as mondayStartWeek), 01 - 53
Produced by Haddock version 0.8