-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharmenian.py
53 lines (43 loc) · 1 KB
/
armenian.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3
#
# Convert between the Armenian Calendar and Julian Day
#
import months
epoch = 1922868
m = months.ARMENIAN
def tojd(day, month, year):
day = int(day)
month = month
year = int(year)
jday = epoch
if year > 0:
# positive years
jday = jday + (365 * (year - 1))
else:
# negative dates
jday = jday + (365 * year)
for i in m.keys():
if i == month:
jday += day - 1
break
else:
jday += m[i]
def fromjd(jday):
"""Convert a Julian Day to a date in the Armenian calendar"""
jday = int(jday)
day = 0
month = ""
year = 0
if jday >= epoch:
year = ((jday - epoch) // 365) + 1
else:
year = 0 - (((epoch - jday) // 365) + 1)
delta = (jday - epoch) % 365
for i in m.keys():
if delta < m[i]:
month = i
day = delta + 1
break
else:
delta -= m[i]
return (day, month, year)