BadiCalendar¶
Class¶
- class badidatetime.badi_calendar.BahaiCalendar(*args, **kwargs)[source]¶
Bases:
BaseCalendar,CoefficientsImplementation of the Baha’i (Badí’) Calendar.
WGS84–https://coordinates-converter.com/https://gml.noaa.gov/grad/solcalc/ Sunset data- KULLISHAY_MAX = 4¶
Constant indicating the maximum Kull-i-shay the API supports.
- Type:
int
- KULLISHAY_MIN = -5¶
Constant indicating the minimum Kull-i-shay the API supports.
- Type:
int
- MAXYEAR = 1161¶
Constant indicating the maximum year this API can represent.
- Type:
int
- MINYEAR = -1842¶
Constant indicating the minimum year this API can represent.
- Type:
int
- PROLEPTIC_GREG_1ST_DAY = 1721423.5¶
Constant indicating the proleptic Gregorian first day or year 1.
- Type:
float
- _BADI_EPOCH = 2394643.11511551¶
The Badí’ epoch represented by the astronomical proleptic JD algorithm. It represents UT time or GMT.
- Type:
float
- _BAHAI_LOCATION = (35.69435, 51.288701, 3.5, 'Asia/Tehran')¶
Represents the location coordinates latitude, longitude, political time zone, and IANA time zone name of the Badí’ orientation point in Tehran.
- Type:
tuple
- _GMT_LOCATION = (51.477928, -0.001545, 0.0)¶
Represents the location coordinates latitude, longitude, and political time zone of the GMT meridian.
- Type:
tuple
- _RD_END¶
- Constant indicating the maximum Rata Die. Auto-generated constant
used to find ordinals.
- Type:
int
- _RD_START = -287¶
Constant indicating the minimum Rata Die.
- Type:
int
- _YEAR_START¶
Auto-generated constant used to find ordinals.
- Type:
dict
- _check_valid_badi_date(b_date: tuple, short_in: bool = False) None[source]¶
Check that the Kull-i-Shay, Váḥids, year, month, day, hour, minute, second, and microsecond values are valid.
- Parameters:
b_date (tuple) – A long form Badí’ date.
short_in (bool) – If True then parse for a short date else if False parse for a long date. This is for incoming dates not outgoing dates as in most other uses of ‘short’.
- Returns:
Nothing
- Return type:
None
- Raises:
AssertionError – When a date Váḥid, year, month, day, hour, minute, second, or microsecond are out of range.
- _check_valid_badi_time(hour: float, minute: float, second: float, us: int, maxsec: int = 60) None[source]¶
Check that the hour, minute, second, and microsecond values are valid.
- Parameters:
hour (float) – Hours
minute (float) – Minutes
second (float) – Seconds
us (float) – Microseconds
- Returns:
Nothing
- Return type:
None
- Raises:
AssertionError – When an hour, minute, second, or microsecond are out of range.
- _day_length(jd: float, lat: float, lon: float, *, decimal: bool = False) tuple[source]¶
The hour, minute, and seconds of the day’s offset either less than or more than 24 hours.
- Parameters:
jd (float) – The astronomically exact Julian Period day.
lat (float) – The latitude.
lon (float) – The longitude.
decimal (bool) – If False (default) return HH:MM:SS else if True return a decimal number.
- Returns:
The hour, minute, and second or a decimal number.
- Return type:
tuple or float
- _get_hms(date: tuple, *, short_in: bool = False) tuple[source]¶
Parse the hours, minutes, seconds, and microseconds, if they exist for either the short or long form Badí’ date.
- Parameters:
date (tuple) – A long or short form Badí’ date.
short_in (bool) – If True then parse for a short date else if False parse for a long date. This is for incoming dates not outgoing dates as in most other uses of ‘short’.
- Returns:
The relevant hours, minutes, and seconds.
- Return type:
tuple
- _is_leap_year(year: int) bool[source]¶
Return a Boolean True if a Badí’ leap year, False if not.
- Parameters:
year (int) – This value must be a Badí’ short form year.
- Returns:
A Boolean indicating if a leap year or not.
- Return type:
bool
- _trim_hms(hms: tuple) tuple[source]¶
Trim the hours, minutes, seconds or microseconds off the date if zero unless a lower value was not zero.
Examples¶ Examples
Results
Description
(12, 30, 6, 0)
(12, 30, 6)
The zero microseconds would be trimmed.
(12, 0, 6, 0)
(12, 0, 6)
The zero microseconds would be trimmed but the zero minutes would be left untouched.
- Parameters:
hms (tuple) – An hour, minute, and second object.
- Returns:
An object with the lower order parts stripped off if they have a zero value.
- Return type:
tuple
- _utc_to_badi_time(jd: float, lat: float, lon: float) float[source]¶
Convert UTC time to Badí’ time. The JD must be in UT time. The resultant date and time are now authoritative.
- Parameters:
jd (float) – An Astronomically correct JD.
lat (float) – The latitude.
lon (float) – The longitude.
- Returns:
The JD with the correct Badí’ time.
- Return type:
float
- badi_date_from_gregorian_date(g_date: tuple, lat: float = None, lon: float = None, zone: float = None, *, us: bool = False, short: bool = False, trim: bool = False, rtd: bool = False, _exact: bool = True) tuple[source]¶
Get the Badí’ date from the Gregorian date.
Note
The date that is passed in is in GMT date and time not the date and time of the time zone you want.
- Parameters:
g_date (tuple) – A Gregorian date.
lat (float) – The latitude.
lon (float) – The longitude.
zone (float) – The standard time zone.
us (bool) – If True the seconds are split to seconds amd microseconds else if False the seconds has a partial day as a decimal.
short (bool) – If True then parse for a short date else if False (default) parse for a long date.
trim (bool) – Trim the us, ss, mm, and hh in that order.
rtd (bool) – Round to day.
_exact (bool) – Use the more exact Julian Period algorithm. Default is True. This should generally be set to True, a False value will give inaccurate results and is used for testing only.
- Returns:
A Badí’ date long or short form.
- Return type:
tuple
- badi_date_from_jd(jd: float, lat: float = None, lon: float = None, zone: float = None, *, us: bool = False, short: bool = False, fraction: bool = False, trim: bool = False, rtd: bool = False) tuple[source]¶
Convert a Julian Period day to a Badí’ date.
Note
Only pass a UTC JD not a zone shifted JD.
- Parameters:
jd (float) – Julian Period day in the Astronomically correct method and in UT time.
lat (float) – The latitude.
lon (float) – The longitude.
zone (float) – The standard time zone.
us (bool) – If True the seconds are split to seconds and microseconds else if False the seconds has a partial day as a decimal.
short (bool) – If True then parse for a short date else if False (default) parse for a long date.
fraction (bool) – This will return a short date with a possible fraction on the day.
trim (bool) – Trim the us, ss, mm, and hh in that order.
rtd (bool) – Round to day.
- Returns:
The Badí’ date from an Astronomically correct Julian Period day.
- Return type:
tuple
- badi_date_from_timestamp(t: float, lat: float = None, lon: float = None, zone: float = None, *, us: bool = False, short: bool = False, trim: bool = False, rtd: bool = False) tuple[source]¶
Get the Badí’ date from a POSIX timestamp.
- Parameters:
t (float) – Timestamp
lat (float) – The latitude.
lon (float) – The longitude.
zone (float) – The time zone.
us (bool) – If True the seconds are split to seconds and microseconds else if False the seconds has a partial day as a decimal.
short (bool) – If True then parse for a short date else if False (default) parse for a long date.
trim (bool) – Trim the us, ss, mm, and hh in that order.
rtd (bool) – Round to day.
- Returns:
A Badí’ date long or short form.
- Return type:
tuple
- date_from_kvymdhms(b_date: tuple, *, short: bool = False) tuple[source]¶
Convert (Kull-i-Shay, Váḥid, year, month, day, hour, minute, second, us) into a (Kull-i-Shay, Váḥid, year, month, day.fraction) or (year, month, day.fraction) date.
- Parameters:
b_date (tuple) – The Badí’ date in long form.
short (bool) – If True then parse for a short date else if False (default) parse for a long date.
- Returns:
The long or short form Badí’ date with hours, minutes, seconds, and microseconds if set.
- Return type:
tuple
- first_day_of_ridvan_g_date(year: int, lat: float = None, lon: float = None, zone: float = None, *, hms: bool = False) tuple[source]¶
Find the first day of Riḍván either with or without hours, minutes, and seconds. If the latitude, longitude, and time zone are not given Riḍván time of day is determined for the city of Nur in Iran.
- Parameters:
year (int) – A Badí’ year.
lat (float) – The latitude.
lon (float) – The longitude.
zone (float) – The time zone.
hms (bool) – If True the output returns the hours, minutes, and second as separate fields. If False the day has a decimal value indicating the hours, minutes, and seconds.
- Returns:
A Gregorian date.
- Return type:
tuple
- gregorian_date_from_badi_date(b_date: tuple, lat: float = None, lon: float = None, zone: float = None, *, us: bool = False, _exact: bool = True) tuple[source]¶
Get the Gregorian date from the Badí’ date.
- Parameters:
b_date (tuple) – A Badí’ date short form.
lat (float) – The latitude.
lon (float) – The longitude.
zone (float) – The standard time zone.
us (bool) – If True the seconds are split to seconds amd microseconds else if False the seconds has a partial day as a decimal.
_exact (bool) – Use the more exact Julian Period algorithm. Default is True. This should generally be set to True, a False value, will give inaccurate results and is used for testing only.
- Returns:
The Gregorian date.
- Return type:
tuple
- jd_from_badi_date(b_date: tuple, lat: float = None, lon: float = None, zone: float = None) float[source]¶
Convert a Badí’ short form date to Julian period day.
Note
The JD must be interoperable with different calendar code. This method returns a standard UT time not Badí’ time. To convert to Badí’ time you will need to add the time zone divided by 24 to the returned JD.
- Parameters:
b_date (tuple) – A short form Badí’ date.
lat (float) – The latitude.
lon (float) – The longitude.
zone (float) – The time zone.
- Returns:
The Julian Period day.
- Return type:
float
- kvymdhms_from_b_date(b_date: tuple, *, us: bool = False, short: bool = False, trim: bool = False) tuple[source]¶
Convert (Kull-i-Shay, Váḥid, year, month, day.fraction) into (Kull-i-Shay, Váḥid, year, month, day, hour, minute, second) or if short is True (year, month, day, hour, minute, second). If us is True the seconds are split to second and microsecond.
- Parameters:
b_date (tuple) – The Badí’ date in long form.
us (bool) – If True the seconds are split to seconds and microseconds else if False the seconds has a partial day as a decimal.
short (bool) – If True then parse for a short date else if False (default) parse for a long date.
trim (bool) – Trim the us, ss, mm, and hh in that order.
- Returns:
The long or short form Badí’ date with hours, minutes, seconds, and microseconds if set.
- Return type:
tuple
- long_date_from_short_date(date: tuple, *, trim: bool = False) tuple[source]¶
Convert a date to a short date (ymdhms) to a long date (kvymdhms).
- Parameters:
b_date (tuple) – A short form date with or without microseconds.
trim (bool) – Trim the us, ss, mm, and hh in that order.
- Returns:
The long form Badí’ date.
- Return type:
tuple
- midday(date: tuple, *, hms: bool = False, _short: bool) tuple[source]¶
Find the midday time in hours, minutes, and seconds with fraction. All calculations are done in GMT.
- Parameters:
date (tuple) – Badí’ date short or long.
hms (bool) – If True return the hours, minutes, and seconds else if False return the decimal value.
_short (bool) – Indicates the incoming date format.
- Returns:
Midday in hours, minutes, and seconds.
- Return type:
tuple
- naw_ruz_g_date(year: int, lat: float = None, lon: float = None, zone: float = None, *, hms: bool = False) tuple[source]¶
Return the Badí’ date for Naw-Ruz from the given Badí’ year.
- Parameters:
year (int) – A Badí’ year.
lat (float) – The latitude.
lon (float) – The longitude.
zone (float) – The time zone.
hms (bool) – If True the output returns the hours, minutes, and seconds as separate fields. If False the day has a decimal value indicating the hours, minutes, and seconds.
- Returns:
A Gregorian date.
- Return type:
tuple
- short_date_from_long_date(b_date: tuple, *, trim: bool = False) tuple[source]¶
Convert a long date (kvymdhms) to a short date (ymdhms). In either case microseconds could also be provided.
- Parameters:
b_date (tuple) – A long form date with or without microseconds.
trim (bool) – Trim the us, ss, mm, and hh in that order.
- Returns:
The short form Badí’ date.
- Return type:
tuple
- timestamp_from_badi_date(date: tuple, lat: float = None, lon: float = None, zone: float = None) float[source]¶
Convert a Badí’ date to a timestamp.
- Parameters:
date (tuple) – The Badí’ date.
lat (float) – The latitude.
lon (float) – The longitude.
zone (float) – The time zone.
- Returns:
The timestamp corrected for the time zone.
- Return type:
float
- utc_sunset(date: tuple, lat: float = None, lon: float = None, zone: float = None) tuple[source]¶
Return the time of sunset in UTC time for the given Badí’ Day.
- Parameters:
date (tuple) – A Badí’ date.
lat (float) – The latitude.
lon (float) – The longitude.
zone (float) – The time zone.
- Returns:
The hour, minute, and second of sunset based on the provided coordinates.
- Return type:
tuple