Skip to content

Commit

Permalink
Move julian_day() routine to new calendar module
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-rhodes committed Apr 22, 2024
1 parent 01b8138 commit 7a53497
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 10 additions & 0 deletions jplephem/calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Routines for dealing with Julian dates."""

def compute_julian_day(year, month=1, day=1):
"""Given a proleptic Gregorian calendar date, return a Julian day int."""
janfeb = month < 3
return (day
+ 1461 * (year + 4800 - janfeb) // 4
+ 367 * (month - 2 + janfeb * 12) // 12
- 3 * ((year + 4900 - janfeb) // 100) // 4
- 32075)
10 changes: 1 addition & 9 deletions jplephem/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse
import sys
from .calendar import compute_julian_day as julian_day
from .daf import DAF
from .excerpter import RemoteFile, write_excerpt
from .spk import SPK
Expand Down Expand Up @@ -116,12 +117,3 @@ def parse_date(s):
raise E('specify each date as YYYY or YYYY/MM or YYYY/MM/DD')
jd = julian_day(*fields) - 0.5
return s, jd

def julian_day(year, month=1, day=1):
"""Given a proleptic Gregorian calendar date, return a Julian day int."""
janfeb = month < 3
return (day
+ 1461 * (year + 4800 - janfeb) // 4
+ 367 * (month - 2 + janfeb * 12) // 12
- 3 * ((year + 4900 - janfeb) // 100) // 4
- 32075)

0 comments on commit 7a53497

Please sign in to comment.