convertdate
===========
The convertdate package was originally developed as "[Python Date
Utils](http://sourceforge.net/projects/pythondateutil/)" by Phil
Schwartz. It has been significantly updated and expanded.
[Consult the complete docs for detailed usage info](https://convertdate.readthedocs.io/).
Available calendars:
- Armenian
- Bahai
- Coptic (Alexandrian)
- French Republican
- Gregorian
- Hebrew
- Indian Civil
- Islamic
- Julian
- Mayan
- Persian
- Positivist
- Mayan
- ISO
- Ordinal (day of year)
- Dublin day count
- Julian day count
The `holidays` module also provides some useful holiday-calculation,
with a focus on North American and Jewish holidays.
Installing
----------
`pip install convertdate`
Or download the package and run `python setup.py install`.
Examples
--------
>>> from convertdate import french_republican
>>> from convertdate import hebrew
>>> french_republican.from_gregorian(2014, 10, 31)
(223, 2, 9)
>>> hebrew.from_gregorian(2014, 10, 31)
(5775, 8, 7)
Note that in some calendar systems, the day begins at sundown.
Convertdate gives the conversion for noon of the day in question.
Each module includes a `monthcalendar` function, which will generate a
calender-like nested list for a year and month (each list of dates runs
from Sunday to Saturday)
>>> hebrew.monthcalendar(5775, 8)
[
[None, None, None, None, None, None, 1],
[2, 3, 4, 5, 6, 7, 8],
[9, 10, 11, 12, 13, 14, 15],
[16, 17, 18, 19, 20, 21, 22],
[23, 24, 25, 26, 27, 28, 29]
]
>>> julian.monthcalendar(2015, 1)
[
[None, None, None, 1, 2, 3, 4],
[5, 6, 7, 8, 9, 10, 11],
[12, 13, 14, 15, 16, 17, 18],
[19, 20, 21, 22, 23, 24, 25],
[26, 27, 28, 29, 30, 31, None]
]
Special Options
---------------
### Armenian
The Armenian calendar begins on 11 July 552 (Julian) and has two modes of
reckoning. The first is the invariant-length version consisting of 12 months
of 30 days each and five epagomenal days; the second is the version
established by Yovhannes Sarkawag in 1084, which fixed the first day of the
year with respect to the Julian calendar and added a sixth epagomenal day
every four years.
By default the invariant calendar is used, but the Sarkawag calendar can be
used beginning with the Armenian year 533 (11 August 1084) by passing the
parameter `method='sarkawag'` to the relevant functions.
### French Republican
Leap year calculations in the French Republican calendar are a matter of
dispute. By default, `convertdate` calculates leap years using the
autumnal equinox. You can also use one of three more systematic methods
proposed over the years.
- Romme, a co-creator of the calendar, proposed leap years in years
divisible by four, except for years divisible by 100.
- Some concordances were drawn up in the 19th century that gave leap
years every 4 years, in years that give a remainder of three when
divided by four (19, 23, 27, etc...).
- Von Mädler proposed leap years in years divisible by four, except
for years divisible by 128.
You can specify any of these three methods with the method keyword
argument in `french_republican` conversion functions.
from convertdate import french_republican
# Romme's method
french_republican.to_gregorian(20, 1, 1), method='romme')
# (1811, 9, 23)
# continuous method
french_republican.to_gregorian(20, 1, 1), method='continuous')
# (1811, 9, 24)
# von Madler's method
french_republican.to_gregorian(20, 1, 1), method='madler')
# (1811, 9, 23)
All the conversion methods correctly assign the leap years implemented
while calendar was in use (3, 7, 11).
Baha'i
------
The Bahá'í (Badí) calendar has an intercalary period, Ayyam-i-Há, which occurs between the 18th and 19th months.
Dates in this period are returned as month 19, and the month of ‘Alá is reported as month 20.
```python
from convertdate import bahai
# the first day of Ayyam-i-Ha:
bahai.to_gregorian(175, 19, 1)
# (2019, 2, 26)
# The first day of 'Ala:
bahai.to_gregorian(175, 20, 1)
# (2019, 3, 2)
```
Before the Common Era
---------------------
For dates before the Common Era (year 1), `convertdate` uses
astronomical notation: 1 BC is recorded as 0, 2 BC is -1, etc. This
makes arithmatic much easier at the expense of ignoring custom.
Note that for dates before 4 CE, `convertdate` uses the [proleptic
Julian
calendar](https://en.wikipedia.org/wiki/Proleptic_Julian_calendar). The
Julian Calendar was in use from 45 BC, but before 4 CE the leap year
leap year pattern was irregular.
The [proleptic Gregorian
calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) is
used for dates before 1582 CE, the year of the Gregorian calendar
reform.
Holidays
--------
North American holidays are the current focus of the `holidays` module,
but pull requests are welcome.
from convertdate import holidays
# For simplicity, functions in the holidays module return a tuple
# In the format (year, month, day)
holidays.new_years(2014)
# (2014, 1, 1)
holidays.memorial_day(2014)
# (2014, 5, 26)
# USA is default
holidays.thanksgiving(2014)
# (2014, 11, 27)
# But there is a Canadian option for some holidays
holidays.thanksgiving(2014, 'canada')
# (2014, 10, 13)
# Mexican national holidays
holidays.natalicio_benito_juarez(2016)
# (2016, 3, 21)
holidays.dia_revolucion(2016)
# (2016, 11, 21)
# Some Jewish holidays are included
holidays.rosh_hashanah(2014)
# Easter can be calculated according to different churches
# ('western', 'orthodox', 'eastern')
# The eastern Christian computation differs from the Orthodox one
# 4 times in each 532-year cycle.
holidays.easter(2019)
# (2019, 4, 21)
holidays.easter(2019, church="orthodox")
# (2019, 4, 28)
holidays.easter(2019, church="orthodox")
# (2019, 4, 28)
Utils
-----
Convertdate includes some utilities for manipulating and calculating
dates.
from convertdate import utils
# Calculate an arbitrary day of the week
THUR = 3
APRIL = 4
# 3rd Thursday in April
utils.nth_day_of_month(3, THUR, APRIL, 2014)
# (2014, 4, 17)
utils.nth_day_of_month(5, THUR, APRIL, 2014)
# IndexError: No 5th day of month 4
# Use 0 for the first argument to get the last weekday of a month
utils.nth_day_of_month(0, THUR, APRIL, 2014)
# (2014, 4, 24)
Note that when calculating weekdays, convertdate uses the convention of
the calendar and time modules: Monday is 0, Sunday is 6.
from convertdate import gregorian
SUN = 6
day = gregorian.to_jd(2014, 4, 17)
nextsunday = utils.next_weekday(SUN, day)
gregorian.from_jd(nextsunday)
# (2014, 4, 20)
Other utility functions:
- nearest\_weekday
- next\_or\_current\_weekday
- previous\_weekday
- previous\_or\_current\_weekday
Raw data
{
"_id": null,
"home_page": "https://github.com/fitnr/convertdate",
"name": "convertdate",
"maintainer": "",
"docs_url": null,
"requires_python": "<4,>=3.7",
"maintainer_email": "",
"keywords": "calendar,date,time",
"author": "Neil Freeman",
"author_email": "contact@fakeisthenewreal.org",
"download_url": "https://files.pythonhosted.org/packages/04/3d/04148ceb732dfb6f10e9b89fa5915080a91e27fe28fd982c259bc4d29ced/convertdate-2.4.0.tar.gz",
"platform": "",
"description": "convertdate\n===========\n\nThe convertdate package was originally developed as \"[Python Date\nUtils](http://sourceforge.net/projects/pythondateutil/)\" by Phil\nSchwartz. It has been significantly updated and expanded.\n\n[Consult the complete docs for detailed usage info](https://convertdate.readthedocs.io/).\n\nAvailable calendars:\n\n- Armenian\n- Bahai\n- Coptic (Alexandrian)\n- French Republican\n- Gregorian\n- Hebrew\n- Indian Civil\n- Islamic\n- Julian\n- Mayan\n- Persian\n- Positivist\n- Mayan\n- ISO\n- Ordinal (day of year)\n- Dublin day count\n- Julian day count\n\nThe `holidays` module also provides some useful holiday-calculation,\nwith a focus on North American and Jewish holidays.\n\nInstalling\n----------\n\n`pip install convertdate`\n\nOr download the package and run `python setup.py install`.\n\nExamples\n--------\n\n >>> from convertdate import french_republican\n >>> from convertdate import hebrew\n >>> french_republican.from_gregorian(2014, 10, 31)\n (223, 2, 9)\n >>> hebrew.from_gregorian(2014, 10, 31)\n (5775, 8, 7)\n\nNote that in some calendar systems, the day begins at sundown.\nConvertdate gives the conversion for noon of the day in question.\n\nEach module includes a `monthcalendar` function, which will generate a\ncalender-like nested list for a year and month (each list of dates runs\nfrom Sunday to Saturday)\n\n >>> hebrew.monthcalendar(5775, 8)\n [\n [None, None, None, None, None, None, 1],\n [2, 3, 4, 5, 6, 7, 8],\n [9, 10, 11, 12, 13, 14, 15],\n [16, 17, 18, 19, 20, 21, 22],\n [23, 24, 25, 26, 27, 28, 29]\n ]\n\n >>> julian.monthcalendar(2015, 1)\n [\n [None, None, None, 1, 2, 3, 4],\n [5, 6, 7, 8, 9, 10, 11],\n [12, 13, 14, 15, 16, 17, 18],\n [19, 20, 21, 22, 23, 24, 25],\n [26, 27, 28, 29, 30, 31, None]\n ]\n\nSpecial Options\n---------------\n\n### Armenian\n\nThe Armenian calendar begins on 11 July 552 (Julian) and has two modes of\nreckoning. The first is the invariant-length version consisting of 12 months\nof 30 days each and five epagomenal days; the second is the version\nestablished by Yovhannes Sarkawag in 1084, which fixed the first day of the\nyear with respect to the Julian calendar and added a sixth epagomenal day\nevery four years.\n\nBy default the invariant calendar is used, but the Sarkawag calendar can be\nused beginning with the Armenian year 533 (11 August 1084) by passing the\nparameter `method='sarkawag'` to the relevant functions.\n\n\n### French Republican\n\nLeap year calculations in the French Republican calendar are a matter of\ndispute. By default, `convertdate` calculates leap years using the\nautumnal equinox. You can also use one of three more systematic methods\nproposed over the years.\n\n- Romme, a co-creator of the calendar, proposed leap years in years\n divisible by four, except for years divisible by 100.\n- Some concordances were drawn up in the 19th century that gave leap\n years every 4 years, in years that give a remainder of three when\n divided by four (19, 23, 27, etc...).\n- Von Mädler proposed leap years in years divisible by four, except\n for years divisible by 128.\n\nYou can specify any of these three methods with the method keyword\nargument in `french_republican` conversion functions.\n\n from convertdate import french_republican\n\n # Romme's method\n french_republican.to_gregorian(20, 1, 1), method='romme')\n # (1811, 9, 23)\n\n # continuous method\n french_republican.to_gregorian(20, 1, 1), method='continuous')\n # (1811, 9, 24)\n\n # von Madler's method\n french_republican.to_gregorian(20, 1, 1), method='madler')\n # (1811, 9, 23)\n\nAll the conversion methods correctly assign the leap years implemented\nwhile calendar was in use (3, 7, 11).\n\nBaha'i\n------\n\nThe Bahá'í (Badí) calendar has an intercalary period, Ayyam-i-Há, which occurs between the 18th and 19th months.\nDates in this period are returned as month 19, and the month of ‘Alá is reported as month 20.\n\n```python\nfrom convertdate import bahai\n# the first day of Ayyam-i-Ha:\nbahai.to_gregorian(175, 19, 1)\n# (2019, 2, 26)\n# The first day of 'Ala:\nbahai.to_gregorian(175, 20, 1)\n# (2019, 3, 2)\n```\n\nBefore the Common Era\n---------------------\n\nFor dates before the Common Era (year 1), `convertdate` uses\nastronomical notation: 1 BC is recorded as 0, 2 BC is -1, etc. This\nmakes arithmatic much easier at the expense of ignoring custom.\n\nNote that for dates before 4 CE, `convertdate` uses the [proleptic\nJulian\ncalendar](https://en.wikipedia.org/wiki/Proleptic_Julian_calendar). The\nJulian Calendar was in use from 45 BC, but before 4 CE the leap year\nleap year pattern was irregular.\n\nThe [proleptic Gregorian\ncalendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) is\nused for dates before 1582 CE, the year of the Gregorian calendar\nreform.\n\nHolidays\n--------\n\nNorth American holidays are the current focus of the `holidays` module,\nbut pull requests are welcome.\n\n from convertdate import holidays\n\n # For simplicity, functions in the holidays module return a tuple\n # In the format (year, month, day)\n\n holidays.new_years(2014)\n # (2014, 1, 1)\n\n holidays.memorial_day(2014)\n # (2014, 5, 26)\n\n # USA is default\n holidays.thanksgiving(2014)\n # (2014, 11, 27)\n\n # But there is a Canadian option for some holidays\n holidays.thanksgiving(2014, 'canada')\n # (2014, 10, 13)\n\n # Mexican national holidays\n holidays.natalicio_benito_juarez(2016)\n # (2016, 3, 21)\n\n holidays.dia_revolucion(2016)\n # (2016, 11, 21)\n\n # Some Jewish holidays are included\n holidays.rosh_hashanah(2014)\n \n # Easter can be calculated according to different churches \n # ('western', 'orthodox', 'eastern')\n # The eastern Christian computation differs from the Orthodox one\n # 4 times in each 532-year cycle.\n \n holidays.easter(2019)\n # (2019, 4, 21)\n holidays.easter(2019, church=\"orthodox\")\n # (2019, 4, 28)\n holidays.easter(2019, church=\"orthodox\")\n # (2019, 4, 28)\n\nUtils\n-----\n\nConvertdate includes some utilities for manipulating and calculating\ndates.\n\n from convertdate import utils\n\n # Calculate an arbitrary day of the week\n THUR = 3\n APRIL = 4\n\n # 3rd Thursday in April\n utils.nth_day_of_month(3, THUR, APRIL, 2014)\n # (2014, 4, 17)\n\n utils.nth_day_of_month(5, THUR, APRIL, 2014)\n # IndexError: No 5th day of month 4\n\n # Use 0 for the first argument to get the last weekday of a month\n utils.nth_day_of_month(0, THUR, APRIL, 2014)\n # (2014, 4, 24)\n\nNote that when calculating weekdays, convertdate uses the convention of\nthe calendar and time modules: Monday is 0, Sunday is 6.\n\n from convertdate import gregorian\n\n SUN = 6\n\n day = gregorian.to_jd(2014, 4, 17)\n nextsunday = utils.next_weekday(SUN, day)\n\n gregorian.from_jd(nextsunday)\n # (2014, 4, 20)\n\nOther utility functions:\n\n- nearest\\_weekday\n- next\\_or\\_current\\_weekday\n- previous\\_weekday\n- previous\\_or\\_current\\_weekday\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Converts between Gregorian dates and other calendar systems",
"version": "2.4.0",
"split_keywords": [
"calendar",
"date",
"time"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "848e757732829631f368ba8b78b547c3",
"sha256": "fcffe3a67522172648cf03b0c3757cfd079726fe5ae04ce29989ad3958039e4e"
},
"downloads": -1,
"filename": "convertdate-2.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "848e757732829631f368ba8b78b547c3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.7",
"size": 47923,
"upload_time": "2022-01-22T18:32:32",
"upload_time_iso_8601": "2022-01-22T18:32:32.094309Z",
"url": "https://files.pythonhosted.org/packages/27/65/3deecc820ce91716225ec72b584b48ba9512ed9583ad48619e3dbbbbd714/convertdate-2.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "320965d9ae24060c385110606c61d040",
"sha256": "770c6b2195544d3e451e230b3f1c9b121ed02680b877f896306a04cf6f26b48f"
},
"downloads": -1,
"filename": "convertdate-2.4.0.tar.gz",
"has_sig": false,
"md5_digest": "320965d9ae24060c385110606c61d040",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.7",
"size": 40288,
"upload_time": "2022-01-22T18:32:33",
"upload_time_iso_8601": "2022-01-22T18:32:33.952745Z",
"url": "https://files.pythonhosted.org/packages/04/3d/04148ceb732dfb6f10e9b89fa5915080a91e27fe28fd982c259bc4d29ced/convertdate-2.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-01-22 18:32:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "fitnr",
"github_project": "convertdate",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "convertdate"
}