| Copyright | (C) 2017 Jason Johnson |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Jason Johnson <jason.johnson.081@gmail.com> |
| Stability | experimental |
| Portability | POSIX, Windows |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Data.HodaTime.CalendarDateTime
Contents
Description
This is the module for CalendarDateTime. A CalendarDateTime represents a date and time within the calendar system that is part of its type. It has no reference to a particular time zone and is therefor not
a globally unique value as June 3rd 2020 10:05pm occurred at different Instants around the world.
Construction
To construct one of these types you will need a CalendarDate and a LocalTime
Synopsis
- data CalendarDateTime calendar
- class IsCalendar cal where
- data Date cal
- data DayOfWeek cal
- data Month cal
- fromDays :: Int32 -> Date cal
- toDays :: Date cal -> Int32
- toYmd :: Date cal -> (Int32, Word8, Word8)
- day' :: Functor f => (DayOfMonth -> f DayOfMonth) -> Date cal -> f (Date cal)
- month' :: Date cal -> Month cal
- monthl' :: Functor f => (Int -> f Int) -> Date cal -> f (Date cal)
- year' :: Functor f => (Year -> f Year) -> Date cal -> f (Date cal)
- dayOfWeek' :: Date cal -> DayOfWeek cal
- next' :: Int -> DayOfWeek cal -> Date cal -> Date cal
- previous' :: Int -> DayOfWeek cal -> Date cal -> Date cal
- class HasDate d where
- type DoW d
- type MoY d
- day :: Functor f => (DayOfMonth -> f DayOfMonth) -> d -> f d
- month :: d -> MoY d
- monthl :: Functor f => (Int -> f Int) -> d -> f d
- year :: Functor f => (Year -> f Year) -> d -> f d
- dayOfWeek :: d -> DoW d
- next :: Int -> DoW d -> d -> d
- previous :: Int -> DoW d -> d -> d
- yearMonthDay :: d -> (Year, MoY d, DayOfMonth)
- on :: LocalTime -> CalendarDate cal -> CalendarDateTime cal
- at :: Date cal -> LocalTime -> CalendarDateTime cal
- atStartOfDay :: CalendarDate cal -> CalendarDateTime cal
Types
data CalendarDateTime calendar Source #
Represents a specific date and time within its calendar system. NOTE: a CalendarDateTime does *not* represent a specific time on the global time line because e.g. "10.March.2006 4pm" is a different instant in most time zones. Convert it to a ZonedDateTime first if you wish to convert to an instant (or use a convenience function).
Instances
class IsCalendar cal where Source #
Associated Types
The per-calendar date representation. Each calendar picks whatever packing is most natural/efficient for it.
Methods
fromDays :: Int32 -> Date cal Source #
Build a date from a flat, epoch-relative day count (the calendar's own epoch).
toDays :: Date cal -> Int32 Source #
Extract the flat, epoch-relative day count from a date.
toYmd :: Date cal -> (Int32, Word8, Word8) Source #
Decode a date to (year, zero-based month, day-of-month). The year is signed so calendars can represent
pre-epoch (e.g. BC) years without wraparound.
day' :: Functor f => (DayOfMonth -> f DayOfMonth) -> Date cal -> f (Date cal) Source #
month' :: Date cal -> Month cal Source #
monthl' :: Functor f => (Int -> f Int) -> Date cal -> f (Date cal) Source #
year' :: Functor f => (Year -> f Year) -> Date cal -> f (Date cal) Source #
dayOfWeek' :: Date cal -> DayOfWeek cal Source #
next' :: Int -> DayOfWeek cal -> Date cal -> Date cal Source #
previous' :: Int -> DayOfWeek cal -> Date cal -> Date cal Source #
Instances
| IsCalendar Coptic Source # | |||||||||||||
Defined in Data.HodaTime.Calendar.Coptic Associated Types
Methods fromDays :: Int32 -> Date Coptic Source # toDays :: Date Coptic -> Int32 Source # toYmd :: Date Coptic -> (Int32, Word8, Word8) Source # day' :: Functor f => (DayOfMonth -> f DayOfMonth) -> Date Coptic -> f (Date Coptic) Source # month' :: Date Coptic -> Month Coptic Source # monthl' :: Functor f => (Int -> f Int) -> Date Coptic -> f (Date Coptic) Source # year' :: Functor f => (Year -> f Year) -> Date Coptic -> f (Date Coptic) Source # dayOfWeek' :: Date Coptic -> DayOfWeek Coptic Source # next' :: Int -> DayOfWeek Coptic -> Date Coptic -> Date Coptic Source # previous' :: Int -> DayOfWeek Coptic -> Date Coptic -> Date Coptic Source # | |||||||||||||
| IsCalendar Gregorian Source # | |||||||||||||
Defined in Data.HodaTime.Calendar.Gregorian.Internal Associated Types
Methods fromDays :: Int32 -> Date Gregorian Source # toDays :: Date Gregorian -> Int32 Source # toYmd :: Date Gregorian -> (Int32, Word8, Word8) Source # day' :: Functor f => (DayOfMonth -> f DayOfMonth) -> Date Gregorian -> f (Date Gregorian) Source # month' :: Date Gregorian -> Month Gregorian Source # monthl' :: Functor f => (Int -> f Int) -> Date Gregorian -> f (Date Gregorian) Source # year' :: Functor f => (Year -> f Year) -> Date Gregorian -> f (Date Gregorian) Source # dayOfWeek' :: Date Gregorian -> DayOfWeek Gregorian Source # next' :: Int -> DayOfWeek Gregorian -> Date Gregorian -> Date Gregorian Source # previous' :: Int -> DayOfWeek Gregorian -> Date Gregorian -> Date Gregorian Source # | |||||||||||||
| IsCalendar Julian Source # | |||||||||||||
Defined in Data.HodaTime.Calendar.Julian Associated Types
Methods fromDays :: Int32 -> Date Julian Source # toDays :: Date Julian -> Int32 Source # toYmd :: Date Julian -> (Int32, Word8, Word8) Source # day' :: Functor f => (DayOfMonth -> f DayOfMonth) -> Date Julian -> f (Date Julian) Source # month' :: Date Julian -> Month Julian Source # monthl' :: Functor f => (Int -> f Int) -> Date Julian -> f (Date Julian) Source # year' :: Functor f => (Year -> f Year) -> Date Julian -> f (Date Julian) Source # dayOfWeek' :: Date Julian -> DayOfWeek Julian Source # next' :: Int -> DayOfWeek Julian -> Date Julian -> Date Julian Source # previous' :: Int -> DayOfWeek Julian -> Date Julian -> Date Julian Source # | |||||||||||||
class HasDate d where Source #
Methods
day :: Functor f => (DayOfMonth -> f DayOfMonth) -> d -> f d Source #
Lens for the day component of a HasDate. Please note that days are not clamped: if you add e.g. 400 days then the month and year will roll
Accessor for the Month component of a HasDate.
monthl :: Functor f => (Int -> f Int) -> d -> f d Source #
Lens for interacting with the month component of a HasDate. Please note that we convert the month to an Int so meaningful math can be done on it. Also
please note that the day will be unaffected except in the case of "end of month" days which may clamp. Note that this clamping will only occur as a final step,
so that
>>>modify monthl (+ 2) <$> Gregorian.calendarDate 31 January 2000Just (CalendarDate 31 March 2000)
and not 29th of March as would happen with some libraries.
year :: Functor f => (Year -> f Year) -> d -> f d Source #
Lens for the year component of a HasDate. Please note that the rest of the date is left as is, with two exceptions: Feb 29 will clamp to 28 in a non-leapyear
and if the new year is earlier than the earliest supported year it will clamp back to that year
dayOfWeek :: d -> DoW d Source #
Accessor for the Day of the week enum of a HasDate, for example:
>>>dayOfWeek . fromJust $ Gregorian.calendarDate 31 January 2000Monday
next :: Int -> DoW d -> d -> d Source #
Returns a HasDate shifted to the nth next Day of Week from the current HasDate, for example:
>>>next 1 Monday . fromJust $ Gregorian.calendarDate 31 January 2000CalendarDate 7 February 2000
previous :: Int -> DoW d -> d -> d Source #
Returns a HasDate shifted to the nth previous Day of Week from the current HasDate, for example:
>>>previous 1 Monday . fromJust $ Gregorian.calendarDate 31 January 2000CalendarDate 24 January 2000
yearMonthDay :: d -> (Year, MoY d, DayOfMonth) Source #
Access the year, month and day-of-month components together in a single call, returned as a
(year, month, day) tuple.
This is purely an access optimization for code that needs more than one date component at once. Reading the
components individually with year, month and day is perfectly correct, but for a packed representation
(such as the Gregorian Date, which stores a cycle/century/day-in-century triple) each of those accessors
independently decodes the stored value, so asking for all three separately decodes it three times.
yearMonthDay decodes once and hands back every component, which is noticeably cheaper on hot paths (for
example date formatting). For representations that already store the components separately (such as the Julian
Date) there is nothing to decode and this is simply the three field reads, so it is never slower than the
individual accessors and callers can use it unconditionally.
Instances
| IsCalendar cal => HasDate (CalendarDateTime cal) Source # | |||||||||
Defined in Data.HodaTime.CalendarDateTime.Internal Associated Types
Methods day :: Functor f => (DayOfMonth -> f DayOfMonth) -> CalendarDateTime cal -> f (CalendarDateTime cal) Source # month :: CalendarDateTime cal -> MoY (CalendarDateTime cal) Source # monthl :: Functor f => (Int -> f Int) -> CalendarDateTime cal -> f (CalendarDateTime cal) Source # year :: Functor f => (Year -> f Year) -> CalendarDateTime cal -> f (CalendarDateTime cal) Source # dayOfWeek :: CalendarDateTime cal -> DoW (CalendarDateTime cal) Source # next :: Int -> DoW (CalendarDateTime cal) -> CalendarDateTime cal -> CalendarDateTime cal Source # previous :: Int -> DoW (CalendarDateTime cal) -> CalendarDateTime cal -> CalendarDateTime cal Source # yearMonthDay :: CalendarDateTime cal -> (Year, MoY (CalendarDateTime cal), DayOfMonth) Source # | |||||||||
| IsCalendar cal => HasDate (Date cal) Source # | |||||||||
Defined in Data.HodaTime.CalendarDateTime.Internal Associated Types
Methods day :: Functor f => (DayOfMonth -> f DayOfMonth) -> Date cal -> f (Date cal) Source # month :: Date cal -> MoY (Date cal) Source # monthl :: Functor f => (Int -> f Int) -> Date cal -> f (Date cal) Source # year :: Functor f => (Year -> f Year) -> Date cal -> f (Date cal) Source # dayOfWeek :: Date cal -> DoW (Date cal) Source # next :: Int -> DoW (Date cal) -> Date cal -> Date cal Source # previous :: Int -> DoW (Date cal) -> Date cal -> Date cal Source # yearMonthDay :: Date cal -> (Year, MoY (Date cal), DayOfMonth) Source # | |||||||||
Constructors
on :: LocalTime -> CalendarDate cal -> CalendarDateTime cal Source #
Returns a CalendarDateTime at LocalTime on the given CalendarDate
at :: Date cal -> LocalTime -> CalendarDateTime cal Source #
Returns a CalendarDateTime of the CalendarDate at the given LocalTime
atStartOfDay :: CalendarDate cal -> CalendarDateTime cal Source #
Returns the first valid time in the day specified by CalendarDate within the given TimeZone