Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
ISO 8601 Ordinal Date format
Synopsis
- type Year = Int
- isLeapYear :: Year -> Bool
- type DayOfYear = Int
- data OrdinalDate = OrdinalDate {}
- _odYear :: Lens' OrdinalDate Year
- _odDay :: Lens' OrdinalDate DayOfYear
- ordinalDate :: Iso' Day OrdinalDate
- toOrdinalDate :: Day -> (Year, DayOfYear)
- fromOrdinalDate :: Year -> DayOfYear -> Day
- fromOrdinalDateValid :: Year -> DayOfYear -> Maybe Day
- mondayStartWeek :: Day -> (Year, WeekOfYear, DayOfWeek)
- sundayStartWeek :: Day -> (Year, WeekOfYear, DayOfWeek)
- fromMondayStartWeek :: Year -> WeekOfYear -> DayOfWeek -> Day
- fromMondayStartWeekValid :: Year -> WeekOfYear -> DayOfWeek -> Maybe Day
- fromSundayStartWeek :: Year -> WeekOfYear -> DayOfWeek -> Day
- fromSundayStartWeekValid :: Year -> WeekOfYear -> DayOfWeek -> Maybe Day
- ordinalDateValid :: OrdinalDate -> Maybe Day
Documentation
data OrdinalDate Source #
Instances
_odYear :: Lens' OrdinalDate Year Source #
_odDay :: Lens' OrdinalDate DayOfYear Source #
ordinalDate :: Iso' Day OrdinalDate Source #
Conversion between the MJD Day
and OrdinalDate
.
>ordinalDate
#
OrdinalDate
2016 32 2016-02-01
>toModifiedJulianDay
$ordinalDate
#
OrdinalDate
2016 32 57419
>ModifiedJulianDay
57419^.
ordinalDate
OrdinalDate
{odYear = 2016, odDay = 32}
toOrdinalDate :: Day -> (Year, DayOfYear) Source #
Convert a Day
to its Gregorian Year
and DayOfYear
.
toOrdinalDate
(view
ordinalDate
->OrdinalDate
y d) = (y, d)
fromOrdinalDate :: Year -> DayOfYear -> Day Source #
Convert a Gregorian Year
and DayOfYear
to a Day
.
Does not validate the input.
fromOrdinalDate
y d =ordinalDate
#
OrdinalDate
y d
fromOrdinalDateValid :: Year -> DayOfYear -> Maybe Day Source #
Converts a Gregorian Year
and DayOfYear
to a Day
.
Returns Nothing
on invalid input.
fromOrdinalDateValid
y d =ordinalDateValid
(OrdinalDate
y d)
mondayStartWeek :: Day -> (Year, WeekOfYear, DayOfWeek) Source #
Converts a Day
to its Monday-starting week date.
The first Monday of the year belongs to 1 ∷
; earlier
days in the same year are week WeekOfYear
0
. This corresponds to "%W"
for
formatTime
.
Monday is 1 ∷
, Sunday is DayOfWeek
7
. This corresponds to
"%u"
for formatTime
.
mondayStartWeek
(view
mondayWeek
->MondayWeek
y w d) = (y, w, d)
sundayStartWeek :: Day -> (Year, WeekOfYear, DayOfWeek) Source #
Converts a Day
to its Sunday-starting week date.
The first Sunday of the year belongs to 1 ∷
; earlier
days in the same year are week WeekOfYear
0
. This corresponds to "%U"
for
formatTime
.
Sunday is 0 ∷
, Saturday is DayOfWeek
6
. This corresponds to
"%w"
for formatTime
.
sundayStartWeek
(view
sundayWeek
->SundayWeek
y w d) = (y, w, d)
fromMondayStartWeek :: Year -> WeekOfYear -> DayOfWeek -> Day Source #
Converts a Monday-starting week date to the corresponding Day
; the
inverse of mondayStartWeek
.
Does not validate the input.
fromMondayStartWeek
y w d =mondayWeek
#
MondayWeek
y w d
fromMondayStartWeekValid :: Year -> WeekOfYear -> DayOfWeek -> Maybe Day Source #
Converts a Monday-starting week date to the corresponding Day
; the
inverse of mondayStartWeek
.
Returns Nothing
for invalid input.
fromMondayStartWeekValid
y w d =mondayWeekValid
(MondayWeek
y w d)
fromSundayStartWeek :: Year -> WeekOfYear -> DayOfWeek -> Day Source #
Converts a Sunday-starting week date to the corresponding Day
; the
inverse of sundayStartWeek
.
Does not validate the input.
fromSundayStartWeek
y w d =sundayWeek
#
SundayWeek
y w d
fromSundayStartWeekValid :: Year -> WeekOfYear -> DayOfWeek -> Maybe Day Source #
Converts a Sunday-starting week date to the corresponding Day
; the
inverse of sundayStartWeek
.
Returns Nothing
for invalid input.
fromSundayStartWeekValid
y w d =sundayWeekValid
(SundayWeek
y w d)
ordinalDateValid :: OrdinalDate -> Maybe Day Source #
Convert an OrdinalDate
to a Day
, or Nothing
for invalid input.
>ordinalDateValid
(OrdinalDate
2015 365)Just
2015-12-31 >ordinalDateValid
(OrdinalDate
2015 366)Nothing
>ordinalDateValid
(OrdinalDate
2016 366)Just
2016-12-31
Orphan instances
Arbitrary OrdinalDate Source # | |
arbitrary :: Gen OrdinalDate # shrink :: OrdinalDate -> [OrdinalDate] # | |
CoArbitrary OrdinalDate Source # | |
coarbitrary :: OrdinalDate -> Gen b -> Gen b # | |
Bounded OrdinalDate Source # | |
minBound :: OrdinalDate # maxBound :: OrdinalDate # | |
Random OrdinalDate Source # | |
randomR :: RandomGen g => (OrdinalDate, OrdinalDate) -> g -> (OrdinalDate, g) # random :: RandomGen g => g -> (OrdinalDate, g) # randomRs :: RandomGen g => (OrdinalDate, OrdinalDate) -> g -> [OrdinalDate] # randoms :: RandomGen g => g -> [OrdinalDate] # |