Created
December 12, 2015 15:01
-
-
Save svecon/1f2202752520b2114c83 to your computer and use it in GitHub Desktop.
Converting date to number of days in Julian Calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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