Skip to main content

Julian dates from proleptic Gregorian and Julian calendars.

Project description

https://travis-ci.org/phn/jdcal.svg?branch=master

This module contains functions for converting between Julian dates and calendar dates.

A function for converting Gregorian calendar dates to Julian dates, and another function for converting Julian calendar dates to Julian dates are defined. Two functions for the reverse calculations are also defined.

Different regions of the world switched to Gregorian calendar from Julian calendar on different dates. Having separate functions for Julian and Gregorian calendars allow maximum flexibility in choosing the relevant calendar.

Julian dates are stored in two floating point numbers (double). Julian dates, and Modified Julian dates, are large numbers. If only one number is used, then the precision of the time stored is limited. Using two numbers, time can be split in a manner that will allow maximum precision. For example, the first number could be the Julian date for the beginning of a day and the second number could be the fractional day. Calculations that need the latter part can now work with maximum precision.

All the above functions are “proleptic”. This means that they work for dates on which the concerned calendar is not valid. For example, Gregorian calendar was not used prior to around October 1582.

A function to test if a given Gregorian calendar year is a leap year is also defined.

Zero point of Modified Julian Date (MJD) and the MJD of 2000/1/1 12:00:00 are also given as module level constants.

Examples

Some examples are given below. For more information see https://oneau.wordpress.com/2011/08/30/jdcal/.

Gregorian calendar:

>>> from jdcal import gcal2jd, jd2gcal
>>> gcal2jd(2000,1,1)
(2400000.5, 51544.0)
>>> 2400000.5 + 51544.0 + 0.5
2451545.0

>>> gcal2jd(2000,2,30)
(2400000.5, 51604.0)
>>> gcal2jd(2000,3,1)
(2400000.5, 51604.0)
>>> gcal2jd(2001,2,30)
(2400000.5, 51970.0)
>>> gcal2jd(2001,3,2)
(2400000.5, 51970.0)

>>> jd2gcal(*gcal2jd(2000,1,1))
(2000, 1, 1, 0.0)
>>> jd2gcal(*gcal2jd(1950,1,1))
(1950, 1, 1, 0.0)

>>> gcal2jd(2000,1,1)
(2400000.5, 51544.0)
>>> jd2gcal(2400000.5, 51544.0)
(2000, 1, 1, 0.0)
>>> jd2gcal(2400000.5, 51544.5)
(2000, 1, 1, 0.5)
>>> jd2gcal(2400000.5, 51544.245)
(2000, 1, 1, 0.24500000000261934)
>>> jd2gcal(2400000.5, 51544.1)
(2000, 1, 1, 0.099999999998544808)
>>> jd2gcal(2400000.5, 51544.75)
(2000, 1, 1, 0.75)

Julian calendar:

>>> jd2jcal(*jcal2jd(2000, 1, 1))
(2000, 1, 1, 0.0)
>>> jd2jcal(*jcal2jd(-4000, 10, 11))
(-4000, 10, 11, 0.0)

Gregorian leap year:

>>> from jdcal import is_leap
>>> is_leap(2000)
True
>>> is_leap(2100)
False

JD for zero point of MJD, and MJD for JD2000.0:

>>> from jdcal import MJD_0, MJD_JD2000
>>> print MJD_0
2400000.5
>>> print MJD_JD2000
51544.5

Installation

The module can be installed using pip or easy_install:

$ pip install jdcal

or,

$ easy_install jdcal

Tests are in test_jdcal.py.

Credits

  1. A good amount of the code is based on the excellent TPM C library by Jeffrey W. Percival.

  2. The inspiration to split Julian dates into two numbers came from the IAU SOFA C library. No code or algorithm from the SOFA library is used in jdcal.

License

Released under BSD; see LICENSE.txt.

For comments and suggestions, email to user prasanthhn in the gmail.com domain.

Project details


Download files

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

Source Distribution

jdcal-1.4.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

jdcal-1.4.1-py2.py3-none-any.whl (9.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jdcal-1.4.1.tar.gz.

File metadata

  • Download URL: jdcal-1.4.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.19.8 CPython/3.6.8

File hashes

Hashes for jdcal-1.4.1.tar.gz
Algorithm Hash digest
SHA256 472872e096eb8df219c23f2689fc336668bdb43d194094b5cc1707e1640acfc8
MD5 e05bdb60fa80f25bc60e73e0c6b7c5dc
BLAKE2b-256 7bb0fa20fce23e9c3b55b640e629cb5edf32a85e6af3cf7af599940eb0c753fe

See more details on using hashes here.

File details

Details for the file jdcal-1.4.1-py2.py3-none-any.whl.

File metadata

  • Download URL: jdcal-1.4.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.19.8 CPython/3.6.8

File hashes

Hashes for jdcal-1.4.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1abf1305fce18b4e8aa248cf8fe0c56ce2032392bc64bbd61b5dff2a19ec8bba
MD5 6774eaa33a3e1598450cd209a78624d1
BLAKE2b-256 f0da572cbc0bc582390480bbd7c4e93d14dc46079778ed915b505dc494b37c57

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page