1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from timelinelib.calendar.coptic.time import CopticDelta
20 from timelinelib.calendar.coptic.time import CopticTime
21
22
23 FIRST_DAY = 1825030
27
28 - def __init__(self, year, month, day, hour, minute, second):
29 if not is_valid(year, month, day):
30 raise ValueError("Invalid coptic date %s-%s-%s" % (year, month, day))
31 self.year = year
32 self.month = month
33 self.day = day
34 self.hour = hour
35 self.minute = minute
36 self.second = second
37
39 return (isinstance(other, self.__class__) and
40 self.to_tuple() == other.to_tuple())
41
43 return not (self == other)
44
45 @classmethod
47 return cls(year, month, day, 0, 0, 0)
48
49 @classmethod
54
55 @property
62
63 def days_between(end, start):
64 return end.julian_day - start.julian_day
65
66 def days_since_tkyriaka_week_1(time):
67 year = CopticDateTime.from_time(time).year
68 diff = days_between(end=time, start=tkyriaka_week_1(year + 1))
69 if diff >= 0:
70 return diff
71 diff = days_between(end=time, start=tkyriaka_week_1(year))
72 if diff >= 0:
73 return diff
74 diff = days_between(end=time, start=tkyriaka_week_1(year - 1))
75 if diff >= 0:
76 return diff
77 raise ValueError("should not end up here")
78 return days_since_monday_week_1(self.to_time()) // 7 + 1
79 """
80 if self.month == 13:
81 return 0
82
83 length_of_week = 10
84 days_into_year = ((self.month - 1)*30) + self.day
85
86 if self.day % length_of_week > 0:
87 return (days_into_year / length_of_week) + 1
88
89 return days_into_year / length_of_week
90 """
91
94
95 - def replace(self, year=None, month=None):
96 if year is None:
97 year = self.year
98 if month is None:
99 month = self.month
100 return self.__class__(
101 year,
102 month,
103 self.day,
104 self.hour,
105 self.minute,
106 self.second
107 )
108
111
113 return (self.year, self.month, self.day, self.hour, self.minute,
114 self.second)
115
117 return (self.year, self.month, self.day)
118
120 return (self.hour, self.minute, self.second)
121
126
128 return (self.month == 1 and
129 self.day == 1 and
130 self.hour == 0 and
131 self.minute == 0 and
132 self.second == 0)
133
135 return (self.day == 1 and
136 self.hour == 0 and
137 self.minute == 0 and
138 self.second == 0)
139
141 return "CopticDateTime<%d-%02d-%02d %02d:%02d:%02d>" % self.to_tuple()
142
144 if month <= 12:
145 return 30
146 elif is_leap_year(year):
147 return 6
148 else:
149 return 5
150
152 if year > 0 and (year+1) % 4 == 0:
153 return True
154 elif year < 0 and year % 4 == 0:
155 return True
156 else:
157 return False
158
160 return int(abs(year/4))
161
163 return (
164 hour >= 0 and hour < 24 and
165 minute >= 0 and minute < 60 and
166 second >= 0 and second < 60
167 )
168
171 return month >= 1 and month <= 13 and day >= 1 and day <= days_in_month(year, month)
172
175 """
176 This calendar calculation was originally published in Explanatory Supplement to the Astronomical Almanac, S.E. Urban and P.K. Seidelman, Eds. (2012). You can purchase the book at uscibooks.com/urban.htm. "15.11 Calendar Conversion Algorithms" from the following pdf is used in the below code. https://aa.usno.navy.mil/publications/docs/c15_usb_online.pdf
177 """
178 if julian_day < CopticTime.MIN_JULIAN_DAY:
179 raise ValueError("coptic_day_to_gregorian_ymd only works for julian days >= %d, but was %d" % (CopticTime.MIN_JULIAN_DAY, julian_day))
180
181
182
183
184
185 y = 4996
186 j = 124
187 m = 0
188 n = 13
189 r = 4
190 p = 1461
191 q = 0
192 v = 3
193 u = 1
194 s = 30
195 t = 0
196 w = 0
197
198 f = julian_day + j
199 e = r * f + v
200 g = (e % p)//r
201 h = u * g + w
202 day = ((h % s)/u) + 1
203 month = (((h // s) + m) % n) + 1
204 year = (e // p) - y + (n + m - month)//n
205 return (year, month, day)
206
210 """
211 Coptic year 1 = Julian day 1825030
212 """
213
214
215
216
217
218
219 y = 4996
220 j = 124
221 m = 0
222 n = 13
223 r = 4
224 p = 1461
225 q = 0
226 v = 3
227 u = 1
228 s = 30
229 t = 0
230 w = 0
231
232 h = month - m
233 g = year + y - (n-h)//n
234 f = (h - 1 + n) % n
235 e = (p * g + q)//r + day - 1 -j
236 julian_day = e + (s * f + t)//u
237
238 if julian_day < CopticTime.MIN_JULIAN_DAY:
239 raise ValueError("coptic_ymd_to_julian_day only works for julian days >= %d, but was %d" % (CopticTime.MIN_JULIAN_DAY, julian_day))
240 return julian_day
241