High-precision conversion between Gregorian calendar datetimes and Julian Dates (JD)
Project description
Apside — High-Precision Conversion Between Gregorian and Julian Dates
Author: Venkata Siddharth Pendyala
Email: venkatasiddharthpendyala@outlook.com
License: MIT
Overview
Apside provides exact, arbitrarily precise conversions between Gregorian calendar datetimes and Julian Dates (JD).
This implementation upgrades the classic approach by using:
- Exact integer Julian Day Number (JDN) via the Fliegel–Van Flandern algorithm (no 365.25 or 30.6001 approximations).
- Arbitrary-precision fractional days with
decimal.Decimal(configurable precision). - Nanosecond-level time components with rollover-safe normalization.
The result is strictly reversible JD↔Gregorian conversion with precision limited only by the Decimal context.
What’s New vs. Typical Implementations
- Exact integer calendar arithmetic for the date part (no floating-point floors).
Decimalfractional day with configurable precision (e.g., 50–100 significant digits).- Support for nanoseconds in both directions.
- Correct automatic handling of the 1582-10-15 Gregorian reform boundary.
Note: This module operates on civil time (UTC). For timescale conversions (UTC↔TAI↔TT↔TDB), leap seconds, ΔT, and relativistic corrections, integrate IERS/JPL data or use a companion timescale module.
Installation
Copy apside.py into your project, or package it as desired. No external dependencies.
API
gregToJulian(y, m, d, hour=0, minute=0, second=0, microsecond=0, nanosecond=0) -> Decimal
Exact civil datetime → JD (as Decimal).
- Calendar boundary: automatically selects Julian vs. Gregorian with the historical switchover at 1582-10-15.
- Fractional day is computed from hour:minute:second:microsecond:nanosecond using
Decimal. - JD is referenced to the standard astronomical convention (noon origin handled internally).
jdToGreg(jd: Decimal) -> tuple[int, int, int, int, int, int, int, int]
JD (Decimal) → (year, month, day, hour, minute, second, microsecond, nanosecond) in UTC.
- Uses only integer calendar arithmetic for the date.
- Fractional day is expanded to time with rollover normalization.
Precision
- Default
Decimalprecision in this file is set to 50 significant digits (getcontext().prec = 50). - Increase the precision for sub-nanosecond JD resolution (e.g., 80–100) depending on your needs.
- Reversibility: JD→Gregorian→JD round-trips within the configured decimal precision.
Example
from decimal import getcontext
from apside import gregToJulian, jdToGreg
# Increase precision if needed
getcontext().prec = 80
# Gregorian → JD (with nanoseconds)
jd = gregToJulian(2025, 10, 4, 12, 30, 0, microsecond=123456, nanosecond=789)
print(jd) # Decimal JD with ~80-digit precision
# JD → Gregorian (reversible, with nanos)
print(jdToGreg(jd))
# (2025, 10, 4, 12, 30, 0, 123456, 789)
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apside-0.1.0.tar.gz.
File metadata
- Download URL: apside-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ea7e191d2eb37e5cb95f75460e4105431cf764343a660f48d90ba7892e1121e
|
|
| MD5 |
f7d717534600b078cd4cedff11e0d2d8
|
|
| BLAKE2b-256 |
048f9a359ca8a03e80d96d6267e3674e51dcb705a3a2949f74b1b50de2dda49f
|
File details
Details for the file apside-0.1.0-py3-none-any.whl.
File metadata
- Download URL: apside-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35db35973e9df42a786c4294c7e52f482cb687cbff806033d3ea62a716c874e3
|
|
| MD5 |
e70c004d98e4d2aeb2741e6e206187de
|
|
| BLAKE2b-256 |
74b14cac69f221bc7852cc91b33b0cf1bb74b93afd1e1b04a882530a4838f91e
|
File details
Details for the file apside-0.1-py3-none-any.whl.
File metadata
- Download URL: apside-0.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e116d289aa483a4ddb539f93c6042e6aabdd6ae4afc6243a6f29a5e656e86f2c
|
|
| MD5 |
c334d5c73925ac6e131c2c9a1ff868e0
|
|
| BLAKE2b-256 |
d8a72124e907a0f60b2bb9d162897acd05639d697db154a012e9ad1b5b38a3f5
|