Skip to content

Instantly share code, notes, and snippets.

@svecon
Created December 12, 2015 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svecon/1f2202752520b2114c83 to your computer and use it in GitHub Desktop.
Save svecon/1f2202752520b2114c83 to your computer and use it in GitHub Desktop.
Converting date to number of days in Julian Calendar
# Converting date to number of days
# Useful when you need to add few days and get a date
# https://en.wikipedia.org/wiki/Julian_day
def toJND(day,month,year):
a = (14-month)//12
y = year + 4800 - a
m = month + 12*a - 3
return day + (153*m+2)//5 + 365*y + y//4 - 32083
def fromJND(JND):
e = 4*(JND + 1401) + 3
h = 5*((e%1461) // 4) + 2
day = (h % 153) // 5 + 1
month = (h // 153 + 2) % 12 + 1
year = e//1461 - 4716 + (12+2-month)//12
return (day, month, year)
print(fromJND(toJND(30,4,2009)+366))
# 1 5 2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment