Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

## Synopsis

- newtype Day = ModifiedJulianDay {}
- addDays :: Integer -> Day -> Day
- diffDays :: Day -> Day -> Integer
- class Ord p => DayPeriod p where
- periodFirstDay :: p -> Day
- periodLastDay :: p -> Day
- dayPeriod :: Day -> p

- periodAllDays :: DayPeriod p => p -> [Day]
- periodLength :: DayPeriod p => p -> Int
- periodFromDay :: DayPeriod p => Day -> (p, Int)
- periodToDay :: DayPeriod p => p -> Int -> Day
- periodToDayValid :: DayPeriod p => p -> Int -> Maybe Day
- data CalendarDiffDays = CalendarDiffDays {}
- calendarDay :: CalendarDiffDays
- calendarWeek :: CalendarDiffDays
- calendarMonth :: CalendarDiffDays
- calendarYear :: CalendarDiffDays
- scaleCalendarDiffDays :: Integer -> CalendarDiffDays -> CalendarDiffDays
- type Year = Integer
- pattern CommonEra :: Integer -> Year
- pattern BeforeCommonEra :: Integer -> Year
- type MonthOfYear = Int
- pattern January :: MonthOfYear
- pattern February :: MonthOfYear
- pattern March :: MonthOfYear
- pattern April :: MonthOfYear
- pattern May :: MonthOfYear
- pattern June :: MonthOfYear
- pattern July :: MonthOfYear
- pattern August :: MonthOfYear
- pattern September :: MonthOfYear
- pattern October :: MonthOfYear
- pattern November :: MonthOfYear
- pattern December :: MonthOfYear
- type DayOfMonth = Int
- toGregorian :: Day -> (Year, MonthOfYear, DayOfMonth)
- fromGregorian :: Year -> MonthOfYear -> DayOfMonth -> Day
- pattern YearMonthDay :: Year -> MonthOfYear -> DayOfMonth -> Day
- fromGregorianValid :: Year -> MonthOfYear -> DayOfMonth -> Maybe Day
- showGregorian :: Day -> String
- gregorianMonthLength :: Year -> MonthOfYear -> DayOfMonth
- addGregorianMonthsClip :: Integer -> Day -> Day
- addGregorianMonthsRollOver :: Integer -> Day -> Day
- addGregorianYearsClip :: Integer -> Day -> Day
- addGregorianYearsRollOver :: Integer -> Day -> Day
- addGregorianDurationClip :: CalendarDiffDays -> Day -> Day
- addGregorianDurationRollOver :: CalendarDiffDays -> Day -> Day
- diffGregorianDurationClip :: Day -> Day -> CalendarDiffDays
- diffGregorianDurationRollOver :: Day -> Day -> CalendarDiffDays
- isLeapYear :: Year -> Bool
- data DayOfWeek
- dayOfWeek :: Day -> DayOfWeek
- dayOfWeekDiff :: DayOfWeek -> DayOfWeek -> Int
- firstDayOfWeekOnAfter :: DayOfWeek -> Day -> Day
- weekAllDays :: DayOfWeek -> Day -> [Day]
- weekFirstDay :: DayOfWeek -> Day -> Day
- weekLastDay :: DayOfWeek -> Day -> Day

# Days

The Modified Julian Day is a standard count of days, with zero being the day 1858-11-17.

#### Instances

# DayPeriod

class Ord p => DayPeriod p where Source #

The class of types which can be represented as a period of days.

*Since: time-1.12.1*

periodFirstDay :: p -> Day Source #

Returns the first `Day`

in a period of days.

periodLastDay :: p -> Day Source #

Returns the last `Day`

in a period of days.

dayPeriod :: Day -> p Source #

Get the period this day is in.

periodAllDays :: DayPeriod p => p -> [Day] Source #

A list of all the days in this period.

*Since: time-1.12.1*

periodLength :: DayPeriod p => p -> Int Source #

The number of days in this period.

*Since: time-1.12.1*

periodFromDay :: DayPeriod p => Day -> (p, Int) Source #

Get the period this day is in, with the 1-based day number within the period.

periodFromDay (periodFirstDay p) = (p,1)

*Since: time-1.12.1*

periodToDay :: DayPeriod p => p -> Int -> Day Source #

Inverse of `periodFromDay`

.

*Since: time-1.12.1*

periodToDayValid :: DayPeriod p => p -> Int -> Maybe Day Source #

Validating inverse of `periodFromDay`

.

*Since: time-1.12.1*

# Calendar Duration

data CalendarDiffDays Source #

#### Instances

scaleCalendarDiffDays :: Integer -> CalendarDiffDays -> CalendarDiffDays Source #

Scale by a factor. Note that `scaleCalendarDiffDays (-1)`

will not perfectly invert a duration, due to variable month lengths.

# Year, month and day

pattern BeforeCommonEra :: Integer -> Year Source #

Also known as Before Christ.
Note that Year 1 = 1 CE, and the previous Year 0 = 1 BCE.
`CommonEra`

and `BeforeCommonEra`

form a `COMPLETE`

set.

type MonthOfYear = Int Source #

Month of year, in range 1 (January) to 12 (December).

pattern January :: MonthOfYear Source #

pattern February :: MonthOfYear Source #

pattern March :: MonthOfYear Source #

pattern April :: MonthOfYear Source #

pattern May :: MonthOfYear Source #

pattern June :: MonthOfYear Source #

pattern July :: MonthOfYear Source #

pattern August :: MonthOfYear Source #

pattern September :: MonthOfYear Source #

pattern October :: MonthOfYear Source #

pattern November :: MonthOfYear Source #

pattern December :: MonthOfYear Source #

The twelve `MonthOfYear`

patterns form a `COMPLETE`

set.

type DayOfMonth = Int Source #

Day of month, in range 1 to 31.

# Gregorian calendar

toGregorian :: Day -> (Year, MonthOfYear, DayOfMonth) Source #

Convert to proleptic Gregorian calendar.

fromGregorian :: Year -> MonthOfYear -> DayOfMonth -> Day Source #

Convert from proleptic Gregorian calendar. Invalid values will be clipped to the correct range, month first, then day.

pattern YearMonthDay :: Year -> MonthOfYear -> DayOfMonth -> Day Source #

Bidirectional abstract constructor for the proleptic Gregorian calendar. Invalid values will be clipped to the correct range, month first, then day.

fromGregorianValid :: Year -> MonthOfYear -> DayOfMonth -> Maybe Day Source #

Convert from proleptic Gregorian calendar. Invalid values will return Nothing

showGregorian :: Day -> String Source #

Show in ISO 8601 format (yyyy-mm-dd)

gregorianMonthLength :: Year -> MonthOfYear -> DayOfMonth Source #

The number of days in a given month according to the proleptic Gregorian calendar.

addGregorianMonthsClip :: Integer -> Day -> Day Source #

Add months, with days past the last day of the month clipped to the last day. For instance, 2005-01-30 + 1 month = 2005-02-28.

addGregorianMonthsRollOver :: Integer -> Day -> Day Source #

Add months, with days past the last day of the month rolling over to the next month. For instance, 2005-01-30 + 1 month = 2005-03-02.

addGregorianYearsClip :: Integer -> Day -> Day Source #

Add years, matching month and day, with Feb 29th clipped to Feb 28th if necessary. For instance, 2004-02-29 + 2 years = 2006-02-28.

addGregorianYearsRollOver :: Integer -> Day -> Day Source #

Add years, matching month and day, with Feb 29th rolled over to Mar 1st if necessary. For instance, 2004-02-29 + 2 years = 2006-03-01.

addGregorianDurationClip :: CalendarDiffDays -> Day -> Day Source #

Add months (clipped to last day), then add days

addGregorianDurationRollOver :: CalendarDiffDays -> Day -> Day Source #

Add months (rolling over to next month), then add days

diffGregorianDurationClip :: Day -> Day -> CalendarDiffDays Source #

Calendrical difference, with as many whole months as possible

diffGregorianDurationRollOver :: Day -> Day -> CalendarDiffDays Source #

Calendrical difference, with as many whole months as possible.
Same as `diffGregorianDurationClip`

for positive durations.

isLeapYear :: Year -> Bool Source #

Is this year a leap year according to the proleptic Gregorian calendar?

# Week

#### Instances

dayOfWeekDiff :: DayOfWeek -> DayOfWeek -> Int Source #

`dayOfWeekDiff a b = a - b`

in range 0 to 6.
The number of days from b to the next a.

weekAllDays :: DayOfWeek -> Day -> [Day] Source #

Returns a week containing the given `Day`

where the first day is the
`DayOfWeek`

specified.

Examples:

`>>>`

[YearMonthDay 2022 2 20 .. YearMonthDay 2022 2 26]`weekAllDays Sunday (YearMonthDay 2022 02 21)`

`>>>`

[YearMonthDay 2022 2 21 .. YearMonthDay 2022 2 27]`weekAllDays Monday (YearMonthDay 2022 02 21)`

`>>>`

[YearMonthDay 2022 2 15 .. YearMonthDay 2022 2 21]`weekAllDays Tuesday (YearMonthDay 2022 02 21)`

*Since: time-1.12.2*

weekFirstDay :: DayOfWeek -> Day -> Day Source #

Returns the first day of a week containing the given `Day`

.

Examples:

`>>>`

YearMonthDay 2022 2 20`weekFirstDay Sunday (YearMonthDay 2022 02 21)`

`>>>`

YearMonthDay 2022 2 21`weekFirstDay Monday (YearMonthDay 2022 02 21)`

`>>>`

YearMonthDay 2022 2 15`weekFirstDay Tuesday (YearMonthDay 2022 02 21)`

*Since: time-1.12.2*

weekLastDay :: DayOfWeek -> Day -> Day Source #

Returns the last day of a week containing the given `Day`

.

Examples:

`>>>`

YearMonthDay 2022 2 26`weekLastDay Sunday (YearMonthDay 2022 02 21)`

`>>>`

YearMonthDay 2022 2 27`weekLastDay Monday (YearMonthDay 2022 02 21)`

`>>>`

YearMonthDay 2022 2 21`weekLastDay Tuesday (YearMonthDay 2022 02 21)`

*Since: time-1.12.2*