add a period of time to a date
Modulehourglass-0.2.12Haskell2010
Data.Hourglass
Types and methods for time manipulation.
The most basic type for time representation is Elapsed, which represent a number of elapsed seconds since the unix epoch.
Every other defined types can be convert to and from Elapsed type:
timeGetElapsed (Date 1 2 3) :: Elapsed
timeFromElapsed 123 :: DateTimeLocal time is represented by any other time types (Elapsed, Date, DateTime, ..), but augmented by a Timezone offset in minutes.
localTime (Date 2014 May 4) 600 -- local time at UTC+10 of May 4th 2014- 12 types
- 5 classes
- 25 values
- Packagehourglass-0.2.12
- Exports42
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceHourglass.hs
add some time interval to a time representation and returns this new time representation
example:
t1 `timeAdd` mempty { durationHours = 12 }Convert one time representation into another one
The return type need to be infer by the context.
If the context cannot be infer through this, some specialized functions are available for built-in types:
Get the difference in seconds between two time representation
effectively:
t2 `timeDiff` t1 = t2 - t1Get the difference in seconds and nanoseconds between two time representation
effectively:
@t2 `timeDiffP` t1 = t2 - t1Get the calendar Date (year-month-day) from a time representation
specialization of timeConvert
Get the date and time of day from a time representation
specialization of timeConvert
Get the day time (hours:minutes:seconds) from a time representation
specialization of timeConvert
An amount of time in terms of constant value like hours (3600 seconds), minutes (60 seconds), seconds and nanoseconds.
Constructors
DurationdurationHours :: !Hoursnumber of hours
durationMinutes :: !Minutesnumber of minutes
durationSeconds :: !Secondsnumber of seconds
durationNs :: !NanoSecondsnumber of nanoseconds
Instances9Eq, Data, Ord, Read, Show, Semigroup, …
Eq DurationDefined in hourglass-0.2.12 · Data.Hourglass.DiffData DurationDefined in hourglass-0.2.12 · Data.Hourglass.DiffOrd DurationDefined in hourglass-0.2.12 · Data.Hourglass.DiffRead DurationDefined in hourglass-0.2.12 · Data.Hourglass.DiffShow DurationDefined in hourglass-0.2.12 · Data.Hourglass.DiffSemigroup DurationDefined in hourglass-0.2.12 · Data.Hourglass.DiffMonoid DurationDefined in hourglass-0.2.12 · Data.Hourglass.DiffNFData DurationDefined in hourglass-0.2.12 · Data.Hourglass.DiffTimeInterval DurationDefined in hourglass-0.2.12 · Data.Hourglass.Diff
An amount of conceptual calendar time in terms of years, months and days.
This allow calendar manipulation, representing things like days and months irrespective on how long those are related to timezone and daylight changes.
See Duration for the time-based equivalent to this class.
Constructors
PeriodperiodYears :: !IntperiodMonths :: !IntperiodDays :: !Int
Instances8Eq, Data, Ord, Read, Show, Semigroup, …
Eq PeriodDefined in hourglass-0.2.12 · Data.Hourglass.DiffData PeriodDefined in hourglass-0.2.12 · Data.Hourglass.DiffOrd PeriodDefined in hourglass-0.2.12 · Data.Hourglass.DiffRead PeriodDefined in hourglass-0.2.12 · Data.Hourglass.DiffShow PeriodDefined in hourglass-0.2.12 · Data.Hourglass.DiffSemigroup PeriodDefined in hourglass-0.2.12 · Data.Hourglass.DiffMonoid PeriodDefined in hourglass-0.2.12 · Data.Hourglass.DiffNFData PeriodDefined in hourglass-0.2.12 · Data.Hourglass.Diff
Represent time types that can be created from other time types.
Every conversion happens throught ElapsedP or Elapsed types.
Methods
timeFromElapsedP :: ElapsedP -> tconvert from a number of elapsed seconds and nanoseconds to another time representation
timeFromElapsed :: Elapsed -> tconvert from a number of elapsed seconds and nanoseconds to another time representation
defaults to timeFromElapsedP unless defined explicitely by an instance.
Instances7Time, …
Time CTimeDefined in hourglass-0.2.12 · Data.Hourglass.TimeTime DateDefined in hourglass-0.2.12 · Data.Hourglass.TimeTime DateTimeDefined in hourglass-0.2.12 · Data.Hourglass.TimeTime ElapsedDefined in hourglass-0.2.12 · Data.Hourglass.TimeTime ElapsedPDefined in hourglass-0.2.12 · Data.Hourglass.TimeEpoch epoch => Time (ElapsedSince epoch)Defined in hourglass-0.2.12 · Data.Hourglass.EpochEpoch epoch => Time (ElapsedSinceP epoch)Defined in hourglass-0.2.12 · Data.Hourglass.Epoch
Timeable represent every type that can be made to look like time types.
can be converted to ElapsedP and Elapsed
optionally have a timezone associated
have nanoseconds accessor (which can return 0 when the type is not more precise than seconds)
Methods
timeGetElapsedP :: t -> ElapsedPconvert a time representation to the number of elapsed seconds and nanoseconds to a specific epoch
timeGetElapsed :: t -> Elapsedconvert a time representation to the number of elapsed seconds to a specific epoch.
defaults to timeGetElapsedP unless defined explicitely by an instance
timeGetNanoSeconds :: t -> NanoSecondsreturn the number of optional nanoseconds.
If the underlaying type is not precise enough to record nanoseconds (or any variant between seconds and nanoseconds), 0 should be returned
defaults to timeGetElapsedP unless defined explicitely by an instance, for efficiency reason, it's a good idea to override this methods if you know the type is not more precise than Seconds.
Instances7Timeable, …
Timeable CTimeDefined in hourglass-0.2.12 · Data.Hourglass.TimeTimeable DateDefined in hourglass-0.2.12 · Data.Hourglass.TimeTimeable DateTimeDefined in hourglass-0.2.12 · Data.Hourglass.TimeTimeable ElapsedDefined in hourglass-0.2.12 · Data.Hourglass.TimeTimeable ElapsedPDefined in hourglass-0.2.12 · Data.Hourglass.TimeEpoch epoch => Timeable (ElapsedSince epoch)Defined in hourglass-0.2.12 · Data.Hourglass.EpochEpoch epoch => Timeable (ElapsedSinceP epoch)Defined in hourglass-0.2.12 · Data.Hourglass.Epoch
Instances9Eq, Data, Num, Ord, Read, Show, …
Eq ElapsedDefined in hourglass-0.2.12 · Time.TypesData ElapsedDefined in hourglass-0.2.12 · Time.TypesNum ElapsedDefined in hourglass-0.2.12 · Time.TypesOrd ElapsedDefined in hourglass-0.2.12 · Time.TypesRead ElapsedDefined in hourglass-0.2.12 · Time.TypesShow ElapsedDefined in hourglass-0.2.12 · Time.TypesNFData ElapsedDefined in hourglass-0.2.12 · Time.TypesTime ElapsedDefined in hourglass-0.2.12 · Data.Hourglass.TimeTimeable ElapsedDefined in hourglass-0.2.12 · Data.Hourglass.Time
A number of seconds and nanoseconds elapsed since the unix epoch.
Constructors
Instances10Eq, Data, Num, Ord, Read, Real, …
Eq ElapsedPDefined in hourglass-0.2.12 · Time.TypesData ElapsedPDefined in hourglass-0.2.12 · Time.TypesNum ElapsedPDefined in hourglass-0.2.12 · Time.TypesOrd ElapsedPDefined in hourglass-0.2.12 · Time.TypesRead ElapsedPDefined in hourglass-0.2.12 · Time.TypesReal ElapsedPDefined in hourglass-0.2.12 · Time.TypesShow ElapsedPDefined in hourglass-0.2.12 · Time.TypesNFData ElapsedPDefined in hourglass-0.2.12 · Time.TypesTime ElapsedPDefined in hourglass-0.2.12 · Data.Hourglass.TimeTimeable ElapsedPDefined in hourglass-0.2.12 · Data.Hourglass.Time
Represent any time interval that has an equivalent value to a number of seconds.
Methods
toSeconds :: i -> SecondsfromSeconds :: Seconds -> (i, Seconds)
Instances5TimeInterval
TimeInterval DurationDefined in hourglass-0.2.12 · Data.Hourglass.DiffTimeInterval HoursDefined in hourglass-0.2.12 · Time.TypesTimeInterval MinutesDefined in hourglass-0.2.12 · Time.TypesTimeInterval NanoSecondsDefined in hourglass-0.2.12 · Time.TypesTimeInterval SecondsDefined in hourglass-0.2.12 · Time.Types
module Data.Hourglass.Types
localTimeParse :: TimeFormat format=> formatthe format to use for parsing
-> Stringthe string to parse
-> Maybe (LocalTime DateTime)
Try parsing a string as time using the format explicitely specified
Unparsed characters are ignored and the error handling is simplified
for more elaborate need use localTimeParseE.
localTimeParseE :: TimeFormat format=> formatthe format to use for parsing
-> Stringthe string to parse
-> Either (TimeFormatElem, String) (LocalTime DateTime, String)
Try parsing a string as time using the format explicitely specified
On failure, the parsing function returns the reason of the failure. If parsing is successful, return the date parsed with the remaining unparsed string
localTimePrint :: (TimeFormat format, Timeable t)=> formatthe format to use for printing
-> LocalTime tthe local time to print
-> Stringthe resulting local time string
Pretty print local time to a string.
The actual output is determined by the format used.
Just like localTimeParse but the time is automatically converted to global time.
like localTimeParseE but the time value is automatically converted to global time.
timePrint :: (TimeFormat format, Timeable t)=> formatthe format to use for printing
-> tthe global time to print
-> Stringthe resulting string
Pretty print time to a string
The actual output is determined by the format used
ISO8601 Date format string.
e.g. 2014-04-05
Instances3Eq, Show, TimeFormat
Eq ISO8601_DateDefined in hourglass-0.2.12 · Data.Hourglass.FormatShow ISO8601_DateDefined in hourglass-0.2.12 · Data.Hourglass.FormatTimeFormat ISO8601_DateDefined in hourglass-0.2.12 · Data.Hourglass.Format
ISO8601 Date and Time format string.
e.g. 2014-04-05T17:25:04+00:00 2014-04-05T17:25:04Z
Instances3Eq, Show, TimeFormat
Eq ISO8601_DateAndTimeDefined in hourglass-0.2.12 · Data.Hourglass.FormatShow ISO8601_DateAndTimeDefined in hourglass-0.2.12 · Data.Hourglass.FormatTimeFormat ISO8601_DateAndTimeDefined in hourglass-0.2.12 · Data.Hourglass.Format
A generic class for anything that can be considered a Time Format string.
Methods
toFormat :: format -> TimeFormatString
Instances5TimeFormat
TimeFormat StringDefined in hourglass-0.2.12 · Data.Hourglass.FormatTimeFormat ISO8601_DateDefined in hourglass-0.2.12 · Data.Hourglass.FormatTimeFormat ISO8601_DateAndTimeDefined in hourglass-0.2.12 · Data.Hourglass.FormatTimeFormat TimeFormatStringDefined in hourglass-0.2.12 · Data.Hourglass.FormatTimeFormat [TimeFormatElem]Defined in hourglass-0.2.12 · Data.Hourglass.Format
All the various formatter that can be part of a time format string
Constructors
Format_Year22 digit years (70 is 1970, 69 is 2069)
Format_Year44 digits years
Format_Yearany digits years
Format_Monthmonths (1 to 12)
Format_Month2months padded to 2 chars (01 to 12)
Format_MonthName_Shortname of the month short (
Jan,Feb..)Format_DayYearday of the year (1 to 365, 366 for leap years)
Format_Dayday of the month (1 to 31)
Format_Day2day of the month (01 to 31)
Format_Hourhours (0 to 23)
Format_Minuteminutes (0 to 59)
Format_Secondseconds (0 to 59, 60 for leap seconds)
Format_UnixSecondnumber of seconds since 1 jan 1970. unix epoch.
Format_MilliSecondMilliseconds (000 to 999)
Format_MicroSecondMicroSeconds (000000 to 999999)
Format_NanoSecondNanoSeconds (000000000 to 999999999)
Format_Precision Intsub seconds display with a precision of N digits. with N between 1 and 9
Format_TimezoneNametimezone name (e.g. GMT, PST). not implemented yet | Format_TimezoneOffset -- ^ timeoffset offset (+02:00)
Format_TzHM_Colon_Zzero UTC offset (Z) or timeoffset with colon (+02:00)
Format_TzHM_Colontimeoffset offset with colon (+02:00)
Format_TzHMtimeoffset offset (+0200)
Format_Tz_Offsettimeoffset in minutes
Format_Spacesone or many space-like chars
Format_Text Chara verbatim char
Format_Fct TimeFormatFct
Instances3Eq, Show, TimeFormat
Eq TimeFormatElemDefined in hourglass-0.2.12 · Data.Hourglass.FormatShow TimeFormatElemDefined in hourglass-0.2.12 · Data.Hourglass.FormatTimeFormat [TimeFormatElem]Defined in hourglass-0.2.12 · Data.Hourglass.Format
A generic format function composed of a parser and a printer.
Constructors
TimeFormatFcttimeFormatFctName :: StringtimeFormatParse :: DateTime -> String -> Either String (DateTime, String)timeFormatPrint :: DateTime -> String
Instances2Eq, Show
Eq TimeFormatFctDefined in hourglass-0.2.12 · Data.Hourglass.FormatShow TimeFormatFctDefined in hourglass-0.2.12 · Data.Hourglass.Format
A time format string, composed of list of TimeFormatElem
Constructors
Instances3Eq, Show, TimeFormat
Eq TimeFormatStringDefined in hourglass-0.2.12 · Data.Hourglass.FormatShow TimeFormatStringDefined in hourglass-0.2.12 · Data.Hourglass.FormatTimeFormat TimeFormatStringDefined in hourglass-0.2.12 · Data.Hourglass.Format
Create a local time type from a timezone and a time type.
The time value is assumed to be local to the timezone offset set, so no transformation is done.
convert the local time representation to another time representation determined by context.
create a local time value from a global one
Change the timezone, and adjust the local value to represent the new local value.
Get back a global time value
Local time representation
this is a time representation augmented by a timezone to get back to a global time, the timezoneOffset needed to be added to the local time.
Instances4Functor, Eq, Ord, Show
Functor LocalTimeDefined in hourglass-0.2.12 · Data.Hourglass.LocalEq t => Eq (LocalTime t)Defined in hourglass-0.2.12 · Data.Hourglass.Local(Ord t, Time t) => Ord (LocalTime t)Defined in hourglass-0.2.12 · Data.Hourglass.LocalShow t => Show (LocalTime t)Defined in hourglass-0.2.12 · Data.Hourglass.Local
get the timezone associated with LocalTime
unwrap the LocalTime value. the time value is local.
standard representation for timezone
Methods
timezoneOffset :: tz -> Intoffset in minutes from UTC. valid values should be between -12*60 to +14*60
timezoneName :: tz -> Stringthe name of the timezone. by default will be +-HH:MM encoding.
Instances2Timezone
Timezone TimezoneMinutesDefined in hourglass-0.2.12 · Data.Hourglass.ZoneTimezone UTCDefined in hourglass-0.2.12 · Data.Hourglass.Zone
Simple timezone containing the number of minutes difference with UTC.
Valid values should be between -12*60 to +14*60
Constructors
Instances4Eq, Ord, Show, Timezone
Eq TimezoneMinutesDefined in hourglass-0.2.12 · Data.Hourglass.ZoneOrd TimezoneMinutesDefined in hourglass-0.2.12 · Data.Hourglass.ZoneShow TimezoneMinutesDefined in hourglass-0.2.12 · Data.Hourglass.ZoneTimezone TimezoneMinutesDefined in hourglass-0.2.12 · Data.Hourglass.Zone
Universal Time Coordinated. The generic computer "timezone".
Calendar misc functions
4 declarationsReturn if this year is a leap year (366 days) or not (365 days in a year)
Return the day of the week a specific date fall in
return the day of the year where Jan 1 is 0
between 0 and 364. 365 for leap years
Return the number of days in a month.