persiantools 4.0.0__tar.gz → 4.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {persiantools-4.0.0/persiantools.egg-info → persiantools-4.0.2}/PKG-INFO +1 -1
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools/__init__.py +1 -1
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools/jdatetime.py +23 -32
- {persiantools-4.0.0 → persiantools-4.0.2/persiantools.egg-info}/PKG-INFO +1 -1
- {persiantools-4.0.0 → persiantools-4.0.2}/tests/test_jalalidate.py +13 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/LICENSE +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/MANIFEST.in +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/README.md +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools/characters.py +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools/digits.py +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools/utils.py +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools.egg-info/SOURCES.txt +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools.egg-info/dependency_links.txt +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools.egg-info/not-zip-safe +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools.egg-info/requires.txt +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/persiantools.egg-info/top_level.txt +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/pyproject.toml +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/setup.cfg +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/setup.py +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/tests/test_characters.py +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/tests/test_digits.py +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/tests/test_jalalidatetime.py +0 -0
- {persiantools-4.0.0 → persiantools-4.0.2}/tests/test_utils.py +0 -0
|
@@ -265,63 +265,54 @@ class JalaliDate:
|
|
|
265
265
|
|
|
266
266
|
def to_gregorian(self):
|
|
267
267
|
"""based on jdf.scr.ir"""
|
|
268
|
+
year = self.year + 1595
|
|
268
269
|
month = self.month
|
|
269
270
|
day = self.day
|
|
270
|
-
year = self.year
|
|
271
271
|
|
|
272
|
-
#
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
days = (365 * year) + (year // 33) * 8 + ((year % 33) + 3) // 4
|
|
279
|
-
days += 78 + day + days_in_month
|
|
272
|
+
# Calculate the total number of days
|
|
273
|
+
days = -355668 + (365 * year) + ((year // 33) * 8) + (((year % 33) + 3) // 4) + day
|
|
274
|
+
if month < 7:
|
|
275
|
+
days += (month - 1) * 31
|
|
276
|
+
else:
|
|
277
|
+
days += ((month - 7) * 30) + 186
|
|
280
278
|
|
|
281
|
-
|
|
279
|
+
# Determine the Gregorian year
|
|
280
|
+
gregorian_year = 400 * (days // 146097)
|
|
282
281
|
days %= 146097
|
|
283
282
|
|
|
284
283
|
if days > 36524:
|
|
285
284
|
days -= 1
|
|
286
285
|
gregorian_year += 100 * (days // 36524)
|
|
287
286
|
days %= 36524
|
|
288
|
-
|
|
289
287
|
if days >= 365:
|
|
290
288
|
days += 1
|
|
291
289
|
|
|
292
290
|
gregorian_year += 4 * (days // 1461)
|
|
293
291
|
days %= 1461
|
|
294
|
-
gregorian_year += (days - 1) // 365
|
|
295
|
-
|
|
296
292
|
if days > 365:
|
|
293
|
+
gregorian_year += (days - 1) // 365
|
|
297
294
|
days = (days - 1) % 365
|
|
298
295
|
|
|
299
296
|
gregorian_day = days + 1
|
|
300
297
|
|
|
298
|
+
# Handle leap years for February day count adjustment
|
|
299
|
+
if (gregorian_year % 4 == 0 and gregorian_year % 100 != 0) or (gregorian_year % 400 == 0):
|
|
300
|
+
feb_days = 29
|
|
301
|
+
else:
|
|
302
|
+
feb_days = 28
|
|
303
|
+
|
|
301
304
|
# Days in each month of the Gregorian calendar
|
|
302
|
-
gregorian_days_in_month = [
|
|
303
|
-
0,
|
|
304
|
-
31,
|
|
305
|
-
29 if (gregorian_year % 4 == 0 and gregorian_year % 100 != 0) or gregorian_year % 400 == 0 else 28,
|
|
306
|
-
31,
|
|
307
|
-
30,
|
|
308
|
-
31,
|
|
309
|
-
30,
|
|
310
|
-
31,
|
|
311
|
-
31,
|
|
312
|
-
30,
|
|
313
|
-
31,
|
|
314
|
-
30,
|
|
315
|
-
31,
|
|
316
|
-
]
|
|
305
|
+
gregorian_days_in_month = [0, 31, feb_days, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
317
306
|
|
|
318
307
|
# Determine the Gregorian month
|
|
319
|
-
|
|
320
|
-
|
|
308
|
+
gregorian_month = 1
|
|
309
|
+
for days_in_month in gregorian_days_in_month[1:]:
|
|
310
|
+
if gregorian_day <= days_in_month:
|
|
321
311
|
break
|
|
322
|
-
gregorian_day -=
|
|
312
|
+
gregorian_day -= days_in_month
|
|
313
|
+
gregorian_month += 1
|
|
323
314
|
|
|
324
|
-
return date(gregorian_year,
|
|
315
|
+
return date(gregorian_year, gregorian_month, gregorian_day)
|
|
325
316
|
|
|
326
317
|
@classmethod
|
|
327
318
|
def today(cls):
|
|
@@ -23,6 +23,12 @@ class TestJalaliDate(TestCase):
|
|
|
23
23
|
self.assertEqual(JalaliDate(1400, 4, 25).to_gregorian(), date(2021, 7, 16))
|
|
24
24
|
self.assertEqual(JalaliDate(1400, 12, 20).to_gregorian(), date(2022, 3, 11))
|
|
25
25
|
self.assertEqual(JalaliDate(1403, 1, 5).to_gregorian(), date(2024, 3, 24))
|
|
26
|
+
self.assertEqual(JalaliDate(1390, 10, 11).to_gregorian(), date(2012, 1, 1))
|
|
27
|
+
self.assertEqual(JalaliDate(1398, 10, 11).to_gregorian(), date(2020, 1, 1))
|
|
28
|
+
self.assertEqual(JalaliDate(1402, 10, 11).to_gregorian(), date(2024, 1, 1))
|
|
29
|
+
self.assertEqual(JalaliDate(1402, 10, 10).to_gregorian(), date(2023, 12, 31))
|
|
30
|
+
self.assertEqual(JalaliDate(1403, 10, 11).to_gregorian(), date(2024, 12, 31))
|
|
31
|
+
self.assertEqual(JalaliDate(1403, 2, 23).to_gregorian(), date(2024, 5, 12))
|
|
26
32
|
|
|
27
33
|
self.assertEqual(JalaliDate.today().to_gregorian(), date.today())
|
|
28
34
|
|
|
@@ -40,6 +46,13 @@ class TestJalaliDate(TestCase):
|
|
|
40
46
|
self.assertEqual(JalaliDate.to_jalali(2021, 2, 11), JalaliDate(1399, 11, 23))
|
|
41
47
|
self.assertEqual(JalaliDate.to_jalali(2021, 7, 16), JalaliDate(1400, 4, 25))
|
|
42
48
|
self.assertEqual(JalaliDate.to_jalali(2024, 3, 24), JalaliDate(1403, 1, 5))
|
|
49
|
+
self.assertEqual(JalaliDate.to_jalali(2012, 1, 1), JalaliDate(1390, 10, 11))
|
|
50
|
+
self.assertEqual(JalaliDate.to_jalali(2020, 1, 1), JalaliDate(1398, 10, 11))
|
|
51
|
+
self.assertEqual(JalaliDate.to_jalali(2024, 1, 1), JalaliDate(1402, 10, 11))
|
|
52
|
+
self.assertEqual(JalaliDate.to_jalali(2024, 1, 1), JalaliDate(1402, 10, 11))
|
|
53
|
+
self.assertEqual(JalaliDate.to_jalali(2023, 12, 31), JalaliDate(1402, 10, 10))
|
|
54
|
+
self.assertEqual(JalaliDate.to_jalali(2024, 12, 31), JalaliDate(1403, 10, 11))
|
|
55
|
+
self.assertEqual(JalaliDate.to_jalali(2024, 5, 12), JalaliDate(1403, 2, 23))
|
|
43
56
|
|
|
44
57
|
self.assertEqual(JalaliDate(date.today()), JalaliDate.today())
|
|
45
58
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|