-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathassyrian.py
172 lines (153 loc) · 4.25 KB
/
assyrian.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/python3
#
# Convert between the Assyrian Calendar and Julian Day
#
import months
import leap_years_assyrian
cycle4 = (4 * 365) + 1
cycle100 = (100 * 365) + 24
cycle400 = (400 * 365) + 97
epoch = (-13386)
def tojd(day,month,year):
day = int(day)
month = month
year = int(year)
jday = epoch
if year > 0:
# positive year
y = 1
cycles = (year - y) // 400
y += (400 * cycles)
jday += (cycle400 * cycles)
while y < year:
if y % 400 == 349:
jday += 366
elif y % 100 == 49:
jday += 365
elif y % 4 == 1:
jday += 366
else:
jday += 365
y += 1
if year % 400 == 349:
m = months.ASSYRIAN_LEAP
elif year % 100 == 49:
m = months.ASSYRIAN_NORMAL
elif year % 4 == 1:
m = months.ASSYRIAN_LEAP
else:
m = months.ASSYRIAN_NORMAL
else:
# negative years
y = 0
cycles = (y - year) // 400
y -= (400 * cycles)
jday -= (cycle400 * cycles)
while y > year:
if y - year > 400:
y -= 400
jday -= cycle400
else:
y -= 1
if abs(y) % 400 == 51:
jday -= 366
elif abs(y) % 100 == 51:
jday -= 365
elif abs(y) % 4 == 3:
jday -= 366
else:
jday -= 365
if year % 400 == 51:
m = months.ASSYRIAN_LEAP
elif year % 100 == 51:
m = months.ASSYRIAN_NORMAL
elif year % 4 == 3:
m = months.ASSYRIAN_LEAP
else:
m = months.ASSYRIAN_NORMAL
for i in m.keys():
if i == month:
jday += day - 1
break
else:
jday += m[i]
return jday
def fromjd(jday):
"""Convert a Julian Day to a date in the Assyrian calendar."""
jday = int(jday)
day = 0
month = ""
year = 0
akitu = epoch
if jday >= epoch:
# positive year
year = 1
cycles = (jday - akitu) // cycle400
year += (400 * cycles)
akitu += (cycle400 * cycles)
curryear = False
while curryear == False:
if year % 400 == 349:
if jday - akitu < 366:
curryear = True
else:
year += 1
akitu += 366
elif year % 100 == 49:
if jday - akitu < 365:
curryear = True
else:
year += 1
akitu += 365
elif year % 4 == 1:
if jday - akitu < 366:
curryear = True
else:
year += 1
akitu += 366
else:
if jday - akitu < 365:
curryear = True
else:
year += 1
akitu += 365
if year % 400 == 349:
m = months.ASSYRIAN_LEAP
elif year % 100 == 49:
m = months.ASSYRIAN_NORMAL
elif year % 4 == 1:
m = months.ASSYRIAN_LEAP
else:
m = months.ASSYRIAN_NORMAL
else:
# negative date
cycles = (akitu - jday) // cycle400
year -= (400 * cycles)
akitu -= (cycle400 * cycles)
while akitu > jday:
year -= 1
if abs(year) % 400 == 51:
akitu -= 366
elif abs(year) % 100 == 51:
akitu -= 365
elif abs(year) % 4 == 3:
akitu -= 366
else:
akitu -= 365
if abs(year) % 400 == 51:
m = months.ASSYRIAN_LEAP
elif abs(year) % 100 == 51:
m = months.ASSYRIAN_NORMAL
elif abs(year) % 4 == 3:
m = months.ASSYRIAN_LEAP
else:
m = months.ASSYRIAN_NORMAL
delta = jday - akitu
for i in m.keys():
if delta < m[i]:
month = i
day = delta + 1
break
else:
delta -= m[i]
return (day, month, year)