utc-0.1.0.0: A pragmatic time and date library.

Safe HaskellSafe
LanguageHaskell98

Data.UTC.Class.IsDate

Synopsis

Documentation

class Epoch t => IsDate t where Source

This class captures the behaviour of the Proleptic Gregorian Calendar.

Without any exception the following holds:

  • A regular year has 365 days and the corresponding February has 28 days.
  • A leap year has 366 days and the corresponding February has 29 days.
  • A year that is a multiple of 400 is a leap year.
  • A year that is a multiple of 100 but not of 400 is not a leap year.
  • A year that is a multiple of 4 but not of 100 is a leap year.

Minimal complete definition

year, month, day, setYear, setMonth, setDay

Methods

year :: t -> Integer Source

year  "2014-⁠12-⁠24" == 2014

For negative years the function assumes astronomical year numbering (year 1 ~ 1 AD, year 0 ~ 1 BC, year -1 ~ 2 BC etc). Note that 1 BC and 5 BC are therefore leap years.

month :: t -> Integer Source

month "2014-⁠12-⁠24" == 12

The function only returns values ranging from 1 to 12.

day :: t -> Integer Source

day   "2014-⁠12-⁠24" == 24

The function only returns values ranging from 1 to 31.

setYear :: Monad m => Integer -> t -> m t Source

Sets the year and fails if the result would be invalid.

setYear 2005 "2004-02-28" :: Maybe Date
> Just 2005-02-28
setYear 2005 "2004-02-29" :: Maybe Date
> Nothing

setMonth :: Monad m => Integer -> t -> m t Source

Sets the month of year and fails if the result would be invalid.

The function only accepts input ranging from 1 to 12.

setDay :: Monad m => Integer -> t -> m t Source

Sets the day of month and fails if the result would be invalid.

The function only accepts input ranging from 1 to 31 (or less depending on month and year).

addYears :: Monad m => Integer -> t -> m t Source

A year is a relative amount of time. The function's semantic is a follows:

  • The years (positive or negative) are added.
  • If the target date is invalid then days are subtracted until the date gets valid.
  • If the resulting date is out of the instance type's range, the function fails (cannot happen for Date and DateTime as they use multiprecision integers).
addYears 4 "2000-02-29" :: Maybe Date
> Just 2004-02-29
addYears 1 "2000-02-29" :: Maybe Date
> Just 2001-02-28

addMonths :: Monad m => Integer -> t -> m t Source

A month is a relative amount of time. The function's semantic is equivalent to that of addYears.

The function fails if the resulting date is out of the instance type's range (cannot happen for Date and DateTime as they use multiprecision integers).

addMonths (-13) "1970-01-01" :: Maybe Date
> Just 1968-12-01

addDays :: Monad m => Integer -> t -> m t Source

A day is an absolute amount of time. There is no surprise to expect.

The function fails if the resulting date is out of the instance type's range (cannot happen for Date and DateTime as they use multiprecision integers).

addDays 365 "1970-01-01" :: Maybe Date
> Just 1971-01-01
addDays 365 "2000-01-01" :: Maybe Date
> Just 2000-12-31