/*----------------------------------------------------------------------------
   Copyright 2012-2021, Microsoft Research, Daan Leijen

   Licensed under the Apache License, Version 2.0 ("The Licence"). You may not
   use this file except in compliance with the License. A copy of the License
   can be found in the LICENSE file at the root of this distribution.
----------------------------------------------------------------------------*/

/* Various calendars\: TAI, GPS, ISO week, Julian, Coptic, etc.

*/
module std/time/calendarsstd/time/calendars

import std/time/instantstd/time/instant
import std/time/utcstd/time/utc
import std/time/datestd/time/date
import std/time/calendarstd/time/calendar

/*----------------------------------------------------------------------------
  Time scale calendars
----------------------------------------------------------------------------*/

/*
// The TAI Calendar. This is a standard ISO 8601 calender using
// TAI time where every day is exactly 86400 SI seconds (unlike
// standard UTC time which can insert leap seconds).
pub val cal-tai = iso-calendar( ts-tai, "TAI" )

// The GPS calendar is always `TAI - 19` but with epoch 1980-01-06Z
pub val cal-gps = iso-calendar( ts-gps, "GPS" ) //(ts-gps.to-tai)(timestamp(fixed(~19))).seconds )

// The Terrestrial (or Ephemeris) time calendar, i.e. an ISO calendar but using the `ts-tt` time scale.
// TT is always `TAI + 32.184`
pub val cal-tt  = iso-calendar( ts-tt, "TT" )//, fixed(32184,3) )
*/

// ----------------------------------------------------
// Coptic calendar
// ----------------------------------------------------

// The [Coptic](https://en.wikipedia.org/wiki/Coptic_calendar) calendar.
// The calendar short name is ``CC``.
pub val cal-copticstd/time/calendars/cal-coptic: calendar = solar-ecalendarstd/time/calendar/solar-ecalendar: (name : string, long-name : string, days-before-year : (year : int) -> int, estimate-year : (days : int) -> (int, maybe<int>), days-before-month : (year : int, month : int) -> int, days-to-month : (year : int, doy : int) -> int, epoch-shift : ? int, has-year-zero : ? bool, month-prefix : ? string, show-era : ? ((date) -> string)) -> calendar(
  "CC"literal: string
count= 2
, "Coptic"literal: string
count= 6
, coptic-days-before-yearstd/time/calendars/coptic-days-before-year: (year : int) -> int, coptic-estimate-yearstd/time/calendars/coptic-estimate-year: (days : int) -> (int, maybe<int>), // coptic-days-to-yeardoy, coptic-days-before-monthstd/time/calendars/coptic-days-before-month: (year : int, month : int) -> int, coptic-doy-to-monthstd/time/calendars/coptic-doy-to-month: (year : int, doy : int) -> int, epoch-shift = 626515literal: int
dec = 626515
hex32= 0x00098F53
bit32= 0b00000000000010011000111101010011
, // 2001-01-01 - 284-08-29 Julian show-era = fnfn: (d : date) -> string(dd: date:datestd/time/date/date: V){ if dd: date.yearstd/time/date/date/year: (date : date) -> int.is-posstd/core/int/is-pos: (i : int) -> bool then "A.M."literal: string
count= 4
else ""literal: string
count= 0
} // Anno Martyrum
) fun coptic-days-before-monthstd/time/calendars/coptic-days-before-month: (year : int, month : int) -> int( yearyear: int : intstd/core/types/int: V, monthmonth: int : intstd/core/types/int: V )result: -> total int : intstd/core/types/int: V 30literal: int
dec = 30
hex8 = 0x1E
bit8 = 0b00011110
*std/core/int/(*): (int, int) -> int(monthmonth: int -std/core/int/(-): (x : int, y : int) -> int 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
) fun coptic-doy-to-monthstd/time/calendars/coptic-doy-to-month: (year : int, doy : int) -> int( yearyear: int : intstd/core/types/int: V, doydoy: int : intstd/core/types/int: V )result: -> total int : intstd/core/types/int: V doydoy: int/std/core/int/(/): (x : int, y : int) -> int30literal: int
dec = 30
hex8 = 0x1E
bit8 = 0b00011110
+std/core/int/(+): (x : int, y : int) -> int
1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
fun coptic-days-before-yearstd/time/calendars/coptic-days-before-year: (year : int) -> int( yearyear: int : intstd/core/types/int: V )result: -> total int 365literal: int
dec = 365
hex16= 0x016D
bit16= 0b0000000101101101
*std/core/int/(*): (int, int) -> intyearyear: int.decstd/core/int/dec: (i : int) -> int +std/core/int/(+): (x : int, y : int) -> int yearyear: int/std/core/int/(/): (x : int, y : int) -> int
4literal: int
dec = 4
hex8 = 0x04
bit8 = 0b00000100
fun coptic-estimate-yearstd/time/calendars/coptic-estimate-year: (days : int) -> (int, maybe<int>)( daysdays: int : intstd/core/types/int: V )result: -> total (int, maybe<int>) : (std/core/types/tuple2: (V, V) -> Vintstd/core/types/int: V,maybestd/core/types/maybe: V -> V<intstd/core/types/int: V>) val (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)eraera: int,doedoe: int)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) = divmodstd/core/int/divmod: (x : int, y : int) -> (int, int)(daysdays: int +std/core/int/(+): (x : int, y : int) -> int 365literal: int
dec = 365
hex16= 0x016D
bit16= 0b0000000101101101
, 1461literal: int
dec = 1461
hex16= 0x05B5
bit16= 0b0000010110110101
) (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)4literal: int
dec = 4
hex8 = 0x04
bit8 = 0b00000100
*std/core/int/(*): (int, int) -> interaera: int +std/core/int/(+): (x : int, y : int) -> int doedoe: int/std/core/int/(/): (x : int, y : int) -> int366literal: int
dec = 366
hex16= 0x016E
bit16= 0b0000000101101110
, Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(364literal: int
dec = 364
hex16= 0x016C
bit16= 0b0000000101101100
)
)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) fun coptic-days-to-yeardoystd/time/calendars/coptic-days-to-yeardoy: (days : int) -> (int, int)( daysdays: int : intstd/core/types/int: V )result: -> total (int, int) : (std/core/types/tuple2: (V, V) -> Vintstd/core/types/int: V,intstd/core/types/int: V) val (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)eraera: int,doedoe: int)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) = divmodstd/core/int/divmod: (x : int, y : int) -> (int, int)(daysdays: int +std/core/int/(+): (x : int, y : int) -> int 365literal: int
dec = 365
hex16= 0x016D
bit16= 0b0000000101101101
, 1461literal: int
dec = 1461
hex16= 0x05B5
bit16= 0b0000010110110101
) val yoeyoe: int = minstd/core/int/min: (i : int, j : int) -> int( doedoe: int/std/core/int/(/): (x : int, y : int) -> int365literal: int
dec = 365
hex16= 0x016D
bit16= 0b0000000101101101
, 3literal: int
dec = 3
hex8 = 0x03
bit8 = 0b00000011
) (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)4literal: int
dec = 4
hex8 = 0x04
bit8 = 0b00000100
*std/core/int/(*): (int, int) -> interaera: int +std/core/int/(+): (x : int, y : int) -> int yoeyoe: int, doedoe: int -std/core/int/(-): (x : int, y : int) -> int 365literal: int
dec = 365
hex16= 0x016D
bit16= 0b0000000101101101
*std/core/int/(*): (int, int) -> intyoeyoe: int
)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) // The [Ethiopian](https://en.wikipedia.org/wiki/Ethiopian_calendar) calendar. // The calendar short name is ``EC``. pub val cal-ethiopianstd/time/calendars/cal-ethiopian: calendar = year-shift-earth-calendarstd/time/calendar/year-shift-earth-calendar: (name : string, long-name : string, year-shift : int, cal : calendar, month-prefix : ? string, show-era : ? ((date) -> string)) -> calendar( "EC"literal: string
count= 2
, "Ethiopian"literal: string
count= 9
, ~std/core/int/(~): (i : int) -> int276literal: int
dec = 276
hex16= 0x0114
bit16= 0b0000000100010100
, cal-copticstd/time/calendars/cal-coptic: calendar
) // ---------------------------------------------------- // ISO week calendar // ---------------------------------------------------- /* The 'ISO week' calendar. This implements the [ISO week date](https://en.wikipedia.org/wiki/ISO_week_date) calendar the week number is interpreted as "month" number instead, i.e. every year has 52 (or 53) months of 7 week days each. Short name is `"IW"`. Since its introduction in 1988, the ISO week calendar is a widely accepted standard for a weekly calendar. It is used mainly by businesses for fiscal year calculations. Weeks start on Monday (as day 1) and every common year has 52 weeks. Every 5 to 7 years, there is a 'leap' year with an extra week 53. The ISO week calendar is directly based on the Gregorian calendar. For example, Tuesday 2001-01-02 is denoted as 2001-W01-2 in the ISO week calendar: weekday 2 (Tuesday) of week 1 in 2001. The year of an ISO week is defined as the Gregorian year that has the Thursday of that week, &ie; contains the most days of that week. For example, Thursday 2004-01-01 has week date 2004-W01-4. This means that sometimes the Gregorian year is different for a first- or last week: Wednesday 2003-12-31 falls in the first week of 2004W and has week date 2004-W01-3. Similarly, Saturday 2005-01-01 falls in the last (leap) week of 2004W and has week date 2004-W53-6. */ pub val cal-iso-weekstd/time/calendars/cal-iso-week: calendar = solar-ecalendarstd/time/calendar/solar-ecalendar: (name : string, long-name : string, days-before-year : (year : int) -> int, estimate-year : (days : int) -> (int, maybe<int>), days-before-month : (year : int, month : int) -> int, days-to-month : (year : int, doy : int) -> int, epoch-shift : ? int, has-year-zero : ? bool, month-prefix : ? string, show-era : ? ((date) -> string)) -> calendar( "IW"literal: string
count= 2
, "ISO Week"literal: string
count= 8
, isow-days-before-yearstd/time/calendars/isow-days-before-year: (year : int) -> int, isow-estimate-yearstd/time/calendars/isow-estimate-year: (days : int) -> (int, maybe<int>), isow-days-before-monthstd/time/calendars/isow-days-before-month: (year : int, month : int) -> int, isow-doy-to-monthstd/time/calendars/isow-doy-to-month: (year : int, doy : int) -> int, month-prefix = "W"literal: string
count= 1
) fun isow-days-before-monthstd/time/calendars/isow-days-before-month: (year : int, month : int) -> int( yearyear: int : intstd/core/types/int: V, monthmonth: int : intstd/core/types/int: V )result: -> total int : intstd/core/types/int: V 7literal: int
dec = 7
hex8 = 0x07
bit8 = 0b00000111
*std/core/int/(*): (int, int) -> int(monthmonth: int -std/core/int/(-): (x : int, y : int) -> int 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
) fun isow-doy-to-monthstd/time/calendars/isow-doy-to-month: (year : int, doy : int) -> int( yearyear: int : intstd/core/types/int: V, doydoy: int : intstd/core/types/int: V )result: -> total int : intstd/core/types/int: V doydoy: int/std/core/int/(/): (x : int, y : int) -> int7literal: int
dec = 7
hex8 = 0x07
bit8 = 0b00000111
+std/core/int/(+): (x : int, y : int) -> int
1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
fun isow-days-before-yearstd/time/calendars/isow-days-before-year: (year : int) -> int( yearyear: int : intstd/core/types/int: V )result: -> total int val gdaysgdays: int = iso-days-before-yearstd/time/calendars/iso-days-before-year: (year : int) -> int(yearyear: int) val weekdayweekday: int = gdaysgdays: int%std/core/int/(%): (int, int) -> int7literal: int
dec = 7
hex8 = 0x07
bit8 = 0b00000111
// Monday=0, Saturday=6 (because 0001-01-01 is a Monday) val adjustadjust: int = if weekdayweekday: int <=std/core/int/(<=): (x : int, y : int) -> bool 3literal: int
dec = 3
hex8 = 0x03
bit8 = 0b00000011
then (0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
-std/core/int/(-): (x : int, y : int) -> int weekdayweekday: int) else (7literal: int
dec = 7
hex8 = 0x07
bit8 = 0b00000111
-std/core/int/(-): (x : int, y : int) -> int weekdayweekday: int) gdaysgdays: int +std/core/int/(+): (x : int, y : int) -> int adjustadjust: int
fun isow-estimate-yearstd/time/calendars/isow-estimate-year: (days : int) -> (int, maybe<int>)( daysdays: int : intstd/core/types/int: V )result: -> total (int, maybe<int>) : (std/core/types/tuple2: (V, V) -> Vintstd/core/types/int: V,maybestd/core/types/maybe: V -> V<intstd/core/types/int: V>) iso-estimate-yearstd/time/calendars/iso-estimate-year: (days : int) -> (int, maybe<int>)( daysdays: int -std/core/int/(-): (x : int, y : int) -> int 3literal: int
dec = 3
hex8 = 0x03
bit8 = 0b00000011
) // because we stick out at most 3 days into the next year // duplicate from std/time/calendar to reduce dependencies fun iso-days-before-yearstd/time/calendars/iso-days-before-year: (year : int) -> int( yearyear: int : intstd/core/types/int: V )result: -> total int val yy: int = yearyear: int.decstd/core/int/dec: (i : int) -> int val leapdaysleapdays: int = (yy: int/std/core/int/(/): (x : int, y : int) -> int4literal: int
dec = 4
hex8 = 0x04
bit8 = 0b00000100
-std/core/int/(-): (x : int, y : int) -> int yy: int/std/core/int/(/): (x : int, y : int) -> int100literal: int
dec = 100
hex8 = 0x64
bit8 = 0b01100100
) +std/core/int/(+): (x : int, y : int) -> int yy: int/std/core/int/(/): (x : int, y : int) -> int400literal: int
dec = 400
hex16= 0x0190
bit16= 0b0000000110010000
365literal: int
dec = 365
hex16= 0x016D
bit16= 0b0000000101101101
*std/core/int/(*): (int, int) -> intyy: int +std/core/int/(+): (x : int, y : int) -> int leapdaysleapdays: int
fun iso-estimate-yearstd/time/calendars/iso-estimate-year: (days : int) -> (int, maybe<int>)( daysdays: int : intstd/core/types/int: V )result: -> total (int, maybe<int>) : (std/core/types/tuple2: (V, V) -> Vintstd/core/types/int: V,maybestd/core/types/maybe: V -> V<intstd/core/types/int: V>) val (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)eraera: int,yoeyoe: int)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) = divmodstd/core/int/divmod: (x : int, y : int) -> (int, int)(daysdays: int,146097literal: int
dec = 146097
hex32= 0x00023AB1
bit32= 0b00000000000000100011101010110001
) (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
+std/core/int/(+): (x : int, y : int) -> int 400literal: int
dec = 400
hex16= 0x0190
bit16= 0b0000000110010000
*std/core/int/(*): (int, int) -> interaera: int +std/core/int/(+): (x : int, y : int) -> int (100literal: int
dec = 100
hex8 = 0x64
bit8 = 0b01100100
*std/core/int/(*): (int, int) -> intyoeyoe: int)/std/core/int/(/): (x : int, y : int) -> int36525literal: int
dec = 36525
hex32= 0x00008EAD
bit32= 0b00000000000000001000111010101101
, Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(363literal: int
dec = 363
hex16= 0x016B
bit16= 0b0000000101101011
)
)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) // ---------------------------------------------------- // ISO month calendar // ---------------------------------------------------- /* <!--meta .calendar .sans-serif; border: 1px solid black; .mheader font-weight: bold; .separator padding-bottom:0.2ex; .noborder border-left:none; border-right:none; .spacer border-left:none; border-right:none; height:0.4ex; .month td-padding-right: 1ex; tr-padding-top: 0.25ex; tbody-tr-1-padding-top: 0.5ex; .sans-serif --> This is _not_ a standard ISO calendar -- it is named this way because it is based directly on the standard [ISO week date](https://en.wikipedia.org/wiki/ISO_week_date) calendar. The short name of the calendar is `"IM"`. The "ISO month" calendar takes the ISO week calendar _as is_, but divides it up in 12 months. This is more familiar than using week numbers to denote a date. A common ISO week year of 52 weeks is divided into 4 quarters of 13 weeks each. Each quarter has 3 months of 30, 30, and 31 days respectively. So, January has 30 days, February has 30 days too, March has 31 days, April has 30 days again, etc. On a leap year, we have an extra leap week 53 that is inserted at the end of the last month, &ie; adds days 32 to 38 to December. Since quarters are meant to be equal for business purposes, we generally don't count the leap week as part of the 4th quarter. This monthly calendar has many good properties, not the least that it matches the Gregorian calendar dates very closely[^fn-match], and is based a widely supported standard ISO calendar. Moreover, it is [perennial](https://en.wikipedia.org/wiki/Perennial_calendar) where every date in the year always has the same weekday. For example, every year and every quarter always start on a Monday and end on a Sunday. Thanksgiving (the 4th Thursday of November) is always on November 23, and always 31 days before Christmas. Christmas and New year are always on Sunday, and there is never a Friday the 13th. [^fn-match]: The month date always matches within 5 days of the Gregorian calendar; and 90% of the time, the date is within 3 days. When writing down a date in the monthly calendar we prefix the month with a capital [M]{.sans-serif} in order to distinguish these dates from regular Gregorian dates or ISO week dates. For example, |-----|----------------|----------------|----------------------------------------------------------|---------------| | Day | Gregorian date | Month date | Remarks | ISO week date | +-----|:--------------:|:--------------:+----------------------------------------------------------|:-------------:+ | Mon | 2018-01-01 | 2018-M01-01 | Matches since Monday starts the first week of the year. | 2018-W01-1 | | Thu | 2016-11-24 | 2016-M11-23 | Thanksgiving, always on Thursday M11-23 every year. | 2016-W47-5 | | Thu | 2013-07-04 | 2013-M07-04 | Independence day is always on Thursday M07-04. | 2013-W27-4 | |-----|----------------|----------------|----------------------------------------------------------|---------------| | Thu | 2004-01-01 | 2004-M01-04 | Since the first week falls partly in 2003M. | 2004-W01-4 | | Sun | 2005-01-02 | 2004-M12-38 | Since it is the last day of the leap week of 2004M. | 2004-W53-7 | |-----|----------------|----------------|----------------------------------------------------------|---------------| { white-space:nowrap; col-4-white-space:normal; col-3-padding-right:1ex; } With the regularity of the new calendar, we can reuse the same calendar pattern for each quarter over and over; unlike the Gregorian calendar it never changes which makes planning for businesses, schools, government etc. much simpler. Here is the (perpetual) calendar with the corresponding ISO week numbers: ~ Begin Calendar { .sans-serif; border: 1px solid #AAA; padding:1ex; } +~~~:|~~~:|~~~:|~~~:|~~~:|~~~:|~~~:+~~~|~~~~:|~~~~:|~~~~:|~~~~:|~~~~~~~~~~~~~| | Quarterly Calendar ||||||| &quad; | ISO week numbers |||| |{.noborder; text-align:center} | | | | | | | | | Q1 | Q2 | Q3 | Q4 | |{.noborder; .mheader} |----|----|----|----|----|----|----| | | | | | | | Mo | Tu | We | Th | Fr | Sa | Su | | Jan | Apr | Jul |Oct | |{.mheader} |----|----|----|----|----|----|----| | | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | | 1 | 14 | 27 | 40 | | | 8 | 9 | 10 | 11 | 12 | 13 | 14 | | 2 | 15 | 28 | 41 | | | 15 | 16 | 17 | 18 | 19 | 20 | 21 | | 3 | 16 | 29 | 42 | | | 22 | 23 | 24 | 25 | 26 | 27 | 28 | | 4 | 17 | 30 | 43 | | | 29 | 30 | | | | | | | 5 | 18 | 31 | 44 | | |----|----|----|----|----|----|----| | | | | | | | | | | | | | | | | | | | |{.spacer} |----|----|----|----|----|----|----| | | | | | | | Mo | Tu | We | Th | Fr | Sa | Su | | Feb | May | Aug | Nov | |{.mheader} |----|----|----|----|----|----|----| | | | | | | | | | 1 | 2 | 3 | 4 | 5 | | 5 | 18 | 31 | 44 | | | 6 | 7 | 8 | 9 | 10 | 11 | 12 | | 6 | 19 | 32 | 45 | | | 13 | 14 | 15 | 16 | 17 | 18 | 19 | | 7 | 20 | 33 | 46 | | | 20 | 21 | 22 | 23 | 24 | 25 | 26 | | 8 | 21 | 34 | 47 | | | 27 | 28 | 29 | 30 | | | | | 9 | 22 | 35 | 48 | | |----|----|----|----|----|----|----| | | | | | | | | | | | | | | | | | | | |{.spacer} |----|----|----|----|----|----|----| | | | | | | | Mo | Tu | We | Th | Fr | Sa | Su | | Mar | Jun | Sep | Dec | |{.mheader} |----|----|----|----|----|----|----| | | | | | | | | | | | 1 | 2 | 3 | | 9 | 22 | 35 | 48 | | | 4 | 5 | 6 | 7 | 8 | 9 | 10 | | 10 | 23 | 36 | 49 | | | 11 | 12 | 13 | 14 | 15 | 16 | 17 | | 11 | 24 | 37 | 50 | | | 18 | 19 | 20 | 21 | 22 | 23 | 24 | | 12 | 25 | 38 | 51 | | | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | 13 | 26 | 39 | 52 | | |----|----|----|----|----|----|----| | | | | | | | | | | | | | | | | | | | |{.spacer} |----|----|----|----|----|----|----| | | | | | | |\ 32|\ 33|\ 34|\ 35|\ 36|\ 37|\ 38| | leap week^&dagger;^ ||| 53 | | |----|----|----|----|----|----|----| | | | | | | { .month; margin-left:auto; margin-right:auto } &nbsp; ^&dagger;^ A leap week is inserted at the end of December. Upcoming years with a leap week are 2020, 2026, 2032, 2037, and 2043. In general, a leap week is inserted whenever the corresponding Gregorian year starts and/or ends on a Thursday. ~ End Calendar -- Daan Leijen, 2016. */ pub val cal-iso-monthstd/time/calendars/cal-iso-month: calendar = solar-ecalendarstd/time/calendar/solar-ecalendar: (name : string, long-name : string, days-before-year : (year : int) -> int, estimate-year : (days : int) -> (int, maybe<int>), days-before-month : (year : int, month : int) -> int, days-to-month : (year : int, doy : int) -> int, epoch-shift : ? int, has-year-zero : ? bool, month-prefix : ? string, show-era : ? ((date) -> string)) -> calendar( "IM"literal: string
count= 2
, "ISO Month"literal: string
count= 9
, isow-days-before-yearstd/time/calendars/isow-days-before-year: (year : int) -> int, isow-estimate-yearstd/time/calendars/isow-estimate-year: (days : int) -> (int, maybe<int>), isom-days-before-monthstd/time/calendars/isom-days-before-month: (year : int, month : int) -> int, isom-doy-to-monthstd/time/calendars/isom-doy-to-month: (year : int, doy : int) -> int, month-prefix = "M"literal: string
count= 1
) fun isom-days-before-monthstd/time/calendars/isom-days-before-month: (year : int, month : int) -> int( yearyear: int : intstd/core/types/int: V, monthmonth: int : intstd/core/types/int: V )result: -> total int : intstd/core/types/int: V 30literal: int
dec = 30
hex8 = 0x1E
bit8 = 0b00011110
*std/core/int/(*): (int, int) -> intmonthmonth: int.decstd/core/int/dec: (i : int) -> int +std/core/int/(+): (x : int, y : int) -> int monthmonth: int.decstd/core/int/dec: (i : int) -> int/std/core/int/(/): (x : int, y : int) -> int
3literal: int
dec = 3
hex8 = 0x03
bit8 = 0b00000011
fun isom-doy-to-monthstd/time/calendars/isom-doy-to-month: (year : int, doy : int) -> int( yearyear: int : intstd/core/types/int: V, doydoy: int : intstd/core/types/int: V )result: -> total int : intstd/core/types/int: V val mm: int = (100literal: int
dec = 100
hex8 = 0x64
bit8 = 0b01100100
*std/core/int/(*): (int, int) -> intdoydoy: int.incstd/core/int/inc: (i : int) -> int)/std/core/int/(/): (x : int, y : int) -> int3034literal: int
dec = 3034
hex16= 0x0BDA
bit16= 0b0000101111011010
minstd/core/int/min: (i : int, j : int) -> int(mm: int.incstd/core/int/inc: (i : int) -> int,12literal: int
dec = 12
hex8 = 0x0C
bit8 = 0b00001100
) // ------------------------------------------------------------------------ // Julian calendar // ------------------------------------------------------------------------ // The [Julian calendar](https://en.wikipedia.org/wiki/Julian_calendar). // Uses old-style ``BC`` and ``AD`` to display era's. // The calendar short name is ``JC``. pub val cal-julianstd/time/calendars/cal-julian: calendar = solar-ecalendarstd/time/calendar/solar-ecalendar: (name : string, long-name : string, days-before-year : (year : int) -> int, estimate-year : (days : int) -> (int, maybe<int>), days-before-month : (year : int, month : int) -> int, days-to-month : (year : int, doy : int) -> int, epoch-shift : ? int, has-year-zero : ? bool, month-prefix : ? string, show-era : ? ((date) -> string)) -> calendar( "JC"literal: string
count= 2
, "Julian"literal: string
count= 6
, julian-days-before-yearstd/time/calendars/julian-days-before-year: (year : int) -> int, julian-estimate-yearstd/time/calendars/julian-estimate-year: (days : int) -> (int, maybe<int>), julian-days-before-monthstd/time/calendars/julian-days-before-month: (year : int, month : int) -> int, julian-doy-to-monthstd/time/calendars/julian-doy-to-month: (year : int, doy : int) -> int, epoch-shift = 730121literal: int
dec = 730121
hex32= 0x000B2409
bit32= 0b00000000000010110010010000001001
, // 2000-01-01 - 0000-12-30 // 730121 + 366 has-year-zero = Falsestd/core/types/False: bool, show-era = fnfn: (d : date) -> string(dd: date:datestd/time/date/date: V){ if dd: date.yearstd/time/date/date/year: (date : date) -> int.is-negstd/core/int/is-neg: (i : int) -> bool then "BC"literal: string
count= 2
else "AD"literal: string
count= 2
}
) fun julian-days-before-monthstd/time/calendars/julian-days-before-month: (year : int, month : int) -> int( yearyear: int : intstd/core/types/int: V, monthmonth: int : intstd/core/types/int: V )result: -> total int : intstd/core/types/int: V val adjadj: int = julian-adjuststd/time/calendars/julian-adjust: (is-before-march : bool, year : int) -> int( monthmonth: int<=std/core/int/(<=): (x : int, y : int) -> bool2literal: int
dec = 2
hex8 = 0x02
bit8 = 0b00000010
, yearyear: int ) (367literal: int
dec = 367
hex16= 0x016F
bit16= 0b0000000101101111
*std/core/int/(*): (int, int) -> intmonthmonth: int -std/core/int/(-): (x : int, y : int) -> int 362literal: int
dec = 362
hex16= 0x016A
bit16= 0b0000000101101010
)/std/core/int/(/): (x : int, y : int) -> int12literal: int
dec = 12
hex8 = 0x0C
bit8 = 0b00001100
-std/core/int/(-): (x : int, y : int) -> int adjadj: int
fun julian-doy-to-monthstd/time/calendars/julian-doy-to-month: (year : int, doy : int) -> int( yearyear: int : intstd/core/types/int: V, doydoy: int : intstd/core/types/int: V )result: -> total int : intstd/core/types/int: V val adjadj: int = julian-adjuststd/time/calendars/julian-adjust: (is-before-march : bool, year : int) -> int( doydoy: int<=std/core/int/(<=): (x : int, y : int) -> bool58literal: int
dec = 58
hex8 = 0x3A
bit8 = 0b00111010
, yearyear: int) (12literal: int
dec = 12
hex8 = 0x0C
bit8 = 0b00001100
*std/core/int/(*): (int, int) -> int(doydoy: int +std/core/int/(+): (x : int, y : int) -> int adjadj: int) +std/core/int/(+): (x : int, y : int) -> int 373literal: int
dec = 373
hex16= 0x0175
bit16= 0b0000000101110101
)/std/core/int/(/): (x : int, y : int) -> int367literal: int
dec = 367
hex16= 0x016F
bit16= 0b0000000101101111
fun julian-adjuststd/time/calendars/julian-adjust: (is-before-march : bool, year : int) -> int( is-before-marchis-before-march: bool : boolstd/core/types/bool: V, yearyear: int : intstd/core/types/int: V )result: -> total int : intstd/core/types/int: V if is-before-marchis-before-march: bool then 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
elif yearyear: int%std/core/int/(%): (int, int) -> int4literal: int
dec = 4
hex8 = 0x04
bit8 = 0b00000100
==std/core/int/(==): (x : int, y : int) -> bool0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
then 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
else
2literal: int
dec = 2
hex8 = 0x02
bit8 = 0b00000010
fun julian-days-before-yearstd/time/calendars/julian-days-before-year: (year : int) -> int( yearyear: int : intstd/core/types/int: V )result: -> total int val leapdaysleapdays: int = yearyear: int.decstd/core/int/dec: (i : int) -> int/std/core/int/(/): (x : int, y : int) -> int4literal: int
dec = 4
hex8 = 0x04
bit8 = 0b00000100
365literal: int
dec = 365
hex16= 0x016D
bit16= 0b0000000101101101
*std/core/int/(*): (int, int) -> intyearyear: int.decstd/core/int/dec: (i : int) -> int +std/core/int/(+): (x : int, y : int) -> int leapdaysleapdays: int
fun julian-estimate-yearstd/time/calendars/julian-estimate-year: (days : int) -> (int, maybe<int>)( daysdays: int : intstd/core/types/int: V )result: -> total (int, maybe<int>) : (std/core/types/tuple2: (V, V) -> Vintstd/core/types/int: V,maybestd/core/types/maybe: V -> V<intstd/core/types/int: V>) val (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)eraera: int,yoeyoe: int)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) = divmodstd/core/int/divmod: (x : int, y : int) -> (int, int)(daysdays: int +std/core/int/(+): (x : int, y : int) -> int 365literal: int
dec = 365
hex16= 0x016D
bit16= 0b0000000101101101
, 1461literal: int
dec = 1461
hex16= 0x05B5
bit16= 0b0000010110110101
) (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)4literal: int
dec = 4
hex8 = 0x04
bit8 = 0b00000100
*std/core/int/(*): (int, int) -> interaera: int +std/core/int/(+): (x : int, y : int) -> int yoeyoe: int/std/core/int/(/): (x : int, y : int) -> int366literal: int
dec = 366
hex16= 0x016E
bit16= 0b0000000101101110
, Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(364literal: int
dec = 364
hex16= 0x016C
bit16= 0b0000000101101100
)
)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) // ------------------------------------------------------------------------ // Julian/Gregorian calendar // ------------------------------------------------------------------------ // The combined Julian / Gregorian calendar, using the Julian calendar for dates // before 1582-10-15 and the Gregorian calendar otherwise. It is possible to // specify a different switch date using the `julian-gregorian` function. // The calendar short name is ``JG``. pub val cal-jgstd/time/calendars/cal-jg: calendar = julian-gregorianstd/time/calendars/julian-gregorian: (switch-date : ? date) -> calendar() pub fun julian-gregorianstd/time/calendars/julian-gregorian: (switch-date : ? date) -> calendar( switch-dateswitch-date: ? date: datestd/time/date/date: V = Datestd/time/date/Date: (year : int, month : int, day : int) -> date(1582literal: int
dec = 1582
hex16= 0x062E
bit16= 0b0000011000101110
,10literal: int
dec = 10
hex8 = 0x0A
bit8 = 0b00001010
,15literal: int
dec = 15
hex8 = 0x0F
bit8 = 0b00001111
) )result: -> total calendar : calendarstd/time/calendar/calendar: V fun showerashowera: (d : date) -> string( dd: date:datestd/time/date/date: V )result: -> total string if dd: date <std/time/date/(<): (i : date, j : date) -> bool switch-dateswitch-date: date then if dd: date.yearstd/time/date/date/year: (date : date) -> int >=std/core/int/(>=): (x : int, y : int) -> bool 1500literal: int
dec = 1500
hex16= 0x05DC
bit16= 0b0000010111011100
then "CE (O.S.)"literal: string
count= 9
else (cal-julianstd/time/calendars/cal-julian: calendar.show-erastd/time/calendar/calendar/show-era: (calendar : calendar) -> ((date) -> string))(dd: date) else if dd: date.yearstd/time/date/date/year: (date : date) -> int <=std/core/int/(<=): (x : int, y : int) -> bool 1926literal: int
dec = 1926
hex16= 0x0786
bit16= 0b0000011110000110
then "CE (N.S.)"literal: string
count= 9
else (cal-gregorianstd/time/calendar/cal-gregorian: calendar.show-erastd/time/calendar/calendar/show-era: (calendar : calendar) -> ((date) -> string))(dd: date
) combine-earth-calendarsstd/time/calendar/combine-earth-calendars: (name : string, long-name : string, switch-date : date, cal1 : calendar, cal2 : calendar, mb-show-era : ? (maybe<(date) -> string>)) -> calendar( "JG"literal: string
count= 2
, "Julian-Gregorian"literal: string
count= 16
, switch-dateswitch-date: date, cal-julianstd/time/calendars/cal-julian: calendar, cal-gregorianstd/time/calendar/cal-gregorian: calendar, Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(showerashowera: (d : date) -> string)
)