1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 from timelinelib.calendar.pharaonic.time import PharaonicDelta
19 from timelinelib.calendar.pharaonic.time import PharaonicTime
20
21
22 FIRST_DAY = 1448638
26
27 - def __init__(self, year, month, day, hour, minute, second):
28 if not is_valid(year, month, day):
29 raise ValueError("Invalid pharaonic date %s-%s-%s" % (year, month, day))
30 self.year = year
31 self.month = month
32 self.day = day
33 self.hour = hour
34 self.minute = minute
35 self.second = second
36
38 return (isinstance(other, self.__class__) and
39 self.to_tuple() == other.to_tuple())
40
42 return not (self == other)
43
44 @classmethod
46 return cls(year, month, day, 0, 0, 0)
47
48 @classmethod
53
54
55 @property
57
58 if self.month == 13:
59 return 0
60
61 length_of_week = 10
62 days_into_year = ((self.month - 1)*30) + self.day
63
64 if self.day % length_of_week > 0:
65 return (days_into_year // length_of_week) + 1
66
67 return days_into_year // length_of_week
68
71
72 - def replace(self, year=None, month=None):
73 if year is None:
74 year = self.year
75 if month is None:
76 month = self.month
77 return self.__class__(
78 year,
79 month,
80 self.day,
81 self.hour,
82 self.minute,
83 self.second
84 )
85
88
90 return (self.year, self.month, self.day, self.hour, self.minute,
91 self.second)
92
94 return self.year, self.month, self.day
95
97 return self.hour, self.minute, self.second
98
103
105 return (self.month == 1 and
106 self.day == 1 and
107 self.hour == 0 and
108 self.minute == 0 and
109 self.second == 0)
110
112 return (self.day == 1 and
113 self.hour == 0 and
114 self.minute == 0 and
115 self.second == 0)
116
118 return "PharaonicDateTime<%d-%02d-%02d %02d:%02d:%02d>" % self.to_tuple()
119
122 if month <= 12:
123 return 30
124 else:
125 return 5
126
129 return (
130 hour >= 0 and hour < 24 and
131 minute >= 0 and minute < 60 and
132 second >= 0 and second < 60
133 )
134
137 return month >= 1 and month <= 13 and day >= 1 and day <= days_in_month(year, month)
138
141 """
142 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
143 """
144 if julian_day < PharaonicTime.MIN_JULIAN_DAY:
145 raise ValueError("pharaonic_day_to_gregorian_ymd only works for julian days >= %d, but was %d" % (PharaonicTime.MIN_JULIAN_DAY, julian_day))
146
147 y = 3968
148 j = 47
149 m = 0
150 n = 13
151 r = 1
152 p = 365
153 q = 0
154 v = 0
155 u = 1
156 s = 30
157 t = 0
158 w = 0
159
160 f = julian_day + j
161 e = r * f + v
162 g = (e % p)//r
163 h = u * g + w
164 day = ((h % s)//u) + 1
165 month = (((h // s) + m) % n) + 1
166 year = (e // p) - y + (n + m - month)//n
167 return year, month, day
168
171 """
172 Pharaonic year 1 = Julian day 1448638
173 """
174
175 y = 3968
176 j = 47
177 m = 0
178 n = 13
179 r = 1
180 p = 365
181 q = 0
182 v = 0
183 u = 1
184 s = 30
185 t = 0
186 w = 0
187
188 h = month - m
189 g = year + y - (n-h)//n
190 f = (h - 1 + n) % n
191 e = (p * g + q)//r + day - 1 -j
192 julian_day = e + (s * f + t)//u
193
194 if julian_day < PharaonicTime.MIN_JULIAN_DAY:
195 raise ValueError("pharaonic_ymd_to_julian_day only works for julian days >= %d, but was %d" % (PharaonicTime.MIN_JULIAN_DAY, julian_day))
196 return julian_day
197