Skip to main content

jdcal

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.

Metadata

Release files for jdcal 1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jdcal 1.4
File Size Uploaded
jdcal-1.4.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jdcal 1.4
File Interpreter ABI Platform
jdcal-1.4-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 17.1 kB

Release files / jdcal-1.4.tar.gz

Download URL jdcal-1.4.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ea0a5067c5f0f50ad4c7bdc80abad3d976604f6fb026b0b3a17a9d84bb9046c9
BLAKE2b-256 checksum
How to use checksums
3bd5181cab9a39dbe8060bd073acae2518e0378e66ff7509c4c6db0881d58e01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / jdcal-1.4-py2.py3-none-any.whl

Download URL jdcal-1.4-py2.py3-none-any.whl
Size 9.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
948fb8d079e63b4be7a69dd5f0cd618a0a57e80753de8248fd786a8a20658a07
BLAKE2b-256 checksum
How to use checksums
a038dcf83532480f25284f3ef13f8ed63e03c58a65c9d3ba2a6a894ed9497207
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.4.1

2 release files

This release

1.4 This release

2 release files

1.3

1 release file

1.2

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page