Prayer Times Calculation
Astronomical Functions
Julian Date

Julian Date

The Julian Date (JD) is a continuous count of days since the beginning of the Julian Period on January 1, 4713 BCE. It is widely used in astronomy for historical reasons, but also serves as a simple way to express time in a continuous format.

Formula used

This formula accounts for the time zone, converting the local time to UTC, and then calculates the Julian Date (JD) by adding the fractional part of the day to the integer part calculated from the date components.

JD=f(date)=1721424.5+Ordinal Date+hours past midnight24UTC offset24\text{JD} = f(\text{date}) = \text{1721424.5} + \text{Ordinal Date} + \frac{\text{hours past midnight}}{24} - \frac{\text{UTC offset}}{24}

Where:

  • 1721424.51721424.5 is the julian date of Jan 1st, 0001.
  • Ordinal Date\text{Ordinal Date} means the number of days since Jan 1st, 0001.
  • The python function py datetime.toordinal(date) returns for a given date the number of days since Jan 1st, 0001.

Code Implementation

../prayertimes2025//pt_engine/astro_helpers/julian_date.py

from datetime import datetime

def julian_date(year: int, month:int, day:int, time_past_midnight_hours:float=0, utc_offset:float=0) -> float:

    # Convert the date to a datetime object
    date = datetime(year, month, day)

    # Convert the time past midnight from hours to a fraction of a day
    time_past_midnight = time_past_midnight_hours / 24.0

    # Julian Date offset
    # 1721424.5 for python as python's ordinal date is based on 0001-01-01
    # in Excel we would take 2415018.5 as Excel's ordinal date function is based on 1900-01-01)
    julian_date_offset = 1721424.5

    # Calculate the Julian Date
    julian_day = julian_date_offset + date.toordinal()  + time_past_midnight - utc_offset / 24.0

    return julian_day

 
↗ View in github