Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Converts between Gregorian dates and other calendar systems.Calendars included: Baha'i, French Republican, Hebrew, Indian Civil, Islamic, ISO, Julian, Mayan and Persian.

Project Description
===========
convertdate
===========

The convertdate package was originally developed as “`Python Date
Utils`_” by Phil Schwartz. It had been significantly updated and
expanded.

Available calendars:

- Bahai
- French Republican
- Gregorian
- Hebrew
- Indian Civil
- Islamic
- Julian
- Mayan
- Persian
- 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``.

Using
-----

.. code:: python

from convertdate import french_republican
from convertdate import hebrew

french_republican.from_gregorian(2014, 10, 31)
# (223, 2, 1, 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)

.. code:: python

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]
# ]

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
system always for much easier arithmatic, at the expense of ignoring
custom.

Note that for dates before 4 CE, ``convertdate`` uses the `proleptic
Julian calendar`_. The Julian Calendar was in use from 45 BC to 4 CE,
but with an irregular leap year pattern.

The `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.

.. code:: python
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)


Utils
-----

Convertdate includes some utilities for manipulating and calculating
dates.

.. code:: python
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.

.. code:: python
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


.. _Python Date Utils: http://sourceforge.net/projects/pythondateutil/
.. _proleptic Julian calendar: https://en.wikipedia.org/wiki/Proleptic_Julian_calendar
.. _proleptic Gregorian calendar: https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar


History
-------

2.0.3.1
-------

Features:
* Add `ordinal` module, for counting the day of year
* Added Mexican national holidays
* Add `monthcalendar` functions

Other changes:
* Simplified logic in `ISO` module

2.0.3
-----

Features:

* Add list of day names and `day_name` function to French Republican converter
* Add multiple conversion methods to the French Republican calendar
* Add Dublin day count and Julian day count converters
* Add month names to Bahai and Hebrew calendars.

Other changes:

* Clarify that weekdays run Monday=0 to Sunday=6 (#1)
* Change Julian converter to use astronomical notation (0 = 1 BCE, -1 = 1 BCE)
* Expanded tests

2.0.2
-----

Features:

* Add support for Python 3 (#1)
Release History

Release History

This version
History Node

2.1.3.3

History Node

2.0.3.3

History Node

2.0.3.2

History Node

2.0.3.1

History Node

2.0.1

History Node

2.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
convertdate-2.1.3.3.tar.gz (19.4 kB) Copy SHA256 Checksum SHA256 Source Nov 25, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting