GregorianCalendar¶
Class¶
- class badidatetime.gregorian_calendar.GregorianCalendar[source]¶
Bases:
BaseCalendarImplementation of the Gregorian Calendar.
- _GREGORIAN_EPOCH = 1721423.5¶
- _MONTHS = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)¶
- _check_valid_gregorian_month_day(g_date: tuple, historical: bool = False) None[source]¶
Check that the month and day values are valid.
- Parameters:
g_date (tuple) – The date to check.
historical (bool) – If True use the Julian leap year before 1883.
- Returns:
Nothing
- Return type:
None
- _is_leap_year(year: int, *, alt: bool = False) bool[source]¶
Determine if a year is a leap year. This method supports two different algorithms the 4|100|400 and the 4|128.
- Parameters:
year (int) – The year to determine leap year for.
alt (bool) – If False (default) use the 4|100|400 algorithm else if True use the 4|128 algorithm.
- Returns:
True or False.
- Return type:
bool
- date_from_ymdhms(date: tuple) tuple[source]¶
Convert (year, month, day, hour, minute, second) into a (year, month, day.fractional) date.
- Parameters:
date (tuple) – A six part date (y, m, d, hh, mm, ss).
- Returns:
The three part (y, m, d.nnn).
- Return type:
tuple
- gregorian_date_from_jd(jd: float, *, hms: bool = False, us: bool = False, exact: bool = False, alt: bool = False) tuple[source]¶
Convert Julian day to Gregorian date.
- Parameters:
jd (float) – A Julian period day. This value should be an historical JD if exact is False and an astronomical JD if exact is True.
hms (bool) – If True convert a fractional day to hours, minutes, seconds, and microseconds else if False (default) do not convert.
exact (bool) – If False (default) Meeus’ historically algorithm is used, else if True the more astronomically correct algorithm is used.
alt (bool) – If False (default) the more common 4|100|400 algorithm for leap years is used else if True the less common 4|128 algorithm for leap years is used. This argument only has an effect if the exact argument is also used.
- Returns:
A Gregorian date in the (year, month, day) format.
- Return type:
tuple
Note
See Astronomical Formulae for Calculators Enlarged & Revised, by Jean Meeus ch3 p26-29
- gregorian_year_from_jd(jd: float) int[source]¶
Find the Gregorian year from a Julian Period day.
- Parameters:
jd (float) – The Julian Period day.
- Returns:
The year portion of the Julian day.
- Return type:
int
- jd_from_gregorian_date(g_date: tuple, *, exact: bool = False, alt: bool = False) float[source]¶
Convert Gregorian dates to Julian day count with the 1582 10, 15 correction.
- Parameters:
g_date (tuple) – A Gregorian date in the (year, month, day) format.
exact (bool) – Julian days as if the Gregorian calendar started on year 1. This is astronomically correct but not historically correct.
alt (bool) – Use a more accurate leap year calculation, only valid when the exact keyword is used, there is no effect otherwise.
- Returns:
A Julian day in UT time.
- Return type:
float
Note
See Astronomical Formulae for Calculators Enlarged & Revised, by Jean Meeus ch3 p24-25
See: https://www.fourmilab.ch/documents/calendar/ https://core2.gsfc.nasa.gov/time/julian.html
Caution when using the exact=True keyword the Julian Period days returned will not always be the same when exact=False is used. This means date comparisons will be in error if both dates do not use the same True or False exact keyword.
- posix_timestamp(t: float, *, zone: float = 0, us: bool = False) tuple[source]¶
Find the year, month, day, hours, minutes, and seconds from a POSIX timestamp updated for provided time zone.
Warning
DO NOT USE THIS METHOD – It’s experimental and is not used in any other code.
* TODO * Needs to be fixed for years before 1970 Gregorian.
- Parameters:
t (float) – POSIX timestamp
zone (float) – Timezone
us (bool) – If True the seconds are split to seconds and microseconds else if False the seconds has a fractional day as a decimal.
- Returns:
The time of the day corrected for the timezone.
- Return type:
tuple
- ymdhms_from_date(date: tuple, us: bool = False) tuple[source]¶
Convert (year, month, day.fractional) into a (year, month, day, hour, minute, second, microseconds).
- Parameters:
date (tuple) – A three part date (y, m, d.nnn).
us (bool) – If True return microseconds as separate field from seconds else if False (default) return seconds with fractional seconds.
- Returns:
A 6 or 7 part date (y, m, d, hh, mm, ss, us).
- Return type:
tuple