convertdate 2.4.1__tar.gz → 2.5.0__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.
Files changed (48) hide show
  1. {convertdate-2.4.1/src/convertdate.egg-info → convertdate-2.5.0}/PKG-INFO +3 -25
  2. {convertdate-2.4.1 → convertdate-2.5.0}/pyproject.toml +4 -3
  3. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/__init__.py +1 -1
  4. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/coptic.py +2 -2
  5. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/ordinal.py +10 -3
  6. {convertdate-2.4.1 → convertdate-2.5.0/src/convertdate.egg-info}/PKG-INFO +3 -25
  7. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate.egg-info/SOURCES.txt +1 -0
  8. convertdate-2.5.0/tests/test_coptic.py +68 -0
  9. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_ordinal.py +30 -1
  10. {convertdate-2.4.1 → convertdate-2.5.0}/LICENSE +0 -0
  11. {convertdate-2.4.1 → convertdate-2.5.0}/README.md +0 -0
  12. {convertdate-2.4.1 → convertdate-2.5.0}/setup.cfg +0 -0
  13. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/armenian.py +0 -0
  14. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/bahai.py +0 -0
  15. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/data/__init__.py +0 -0
  16. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/data/french_republican_days.py +0 -0
  17. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/data/positivist.py +0 -0
  18. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/daycount.py +0 -0
  19. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/dublin.py +0 -0
  20. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/french_republican.py +0 -0
  21. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/gregorian.py +0 -0
  22. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/hebrew.py +0 -0
  23. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/holidays.py +0 -0
  24. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/indian_civil.py +0 -0
  25. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/islamic.py +0 -0
  26. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/iso.py +0 -0
  27. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/julian.py +0 -0
  28. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/julianday.py +0 -0
  29. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/mayan.py +0 -0
  30. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/persian.py +0 -0
  31. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/positivist.py +0 -0
  32. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate/utils.py +0 -0
  33. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate.egg-info/dependency_links.txt +0 -0
  34. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate.egg-info/requires.txt +0 -0
  35. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate.egg-info/top_level.txt +0 -0
  36. {convertdate-2.4.1 → convertdate-2.5.0}/src/convertdate.egg-info/zip-safe +0 -0
  37. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_armenian.py +0 -0
  38. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_bahai.py +0 -0
  39. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_french_republican.py +0 -0
  40. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_general.py +0 -0
  41. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_gregorian.py +0 -0
  42. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_holidays.py +0 -0
  43. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_indian_civil.py +0 -0
  44. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_julian.py +0 -0
  45. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_mayan.py +0 -0
  46. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_persian.py +0 -0
  47. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_positivist.py +0 -0
  48. {convertdate-2.4.1 → convertdate-2.5.0}/tests/test_utils.py +0 -0
@@ -1,34 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: convertdate
3
- Version: 2.4.1
3
+ Version: 2.5.0
4
4
  Summary: Converts between Gregorian dates and other calendar systems
5
+ Author: Phil Schwartz
5
6
  Author-email: Neil Freeman <contact@fakeisthenewreal.org>
6
- License: The MIT License (MIT)
7
-
8
- Copyright (c) 2014-2022 Neil Freeman
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in
18
- all copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
- THE SOFTWARE.
27
-
28
-
7
+ License-Expression: MIT
29
8
  Project-URL: Homepage, https://github.com/fitnr/convertdate
30
9
  Keywords: calendar,date,time
31
- Classifier: License :: OSI Approved :: MIT License
32
10
  Classifier: Natural Language :: English
33
11
  Classifier: Programming Language :: Python
34
12
  Classifier: Programming Language :: Python :: 3.8
@@ -7,13 +7,14 @@
7
7
  name = "convertdate"
8
8
  description = "Converts between Gregorian dates and other calendar systems"
9
9
  authors = [
10
- {name = "Neil Freeman", email = "contact@fakeisthenewreal.org"}
10
+ {name = "Neil Freeman", email = "contact@fakeisthenewreal.org"},
11
+ {name = "Phil Schwartz"}
11
12
  ]
12
13
  readme = "README.md"
13
- license = {file = "LICENSE"}
14
+ license = "MIT"
15
+ license-files = ["LICENSE"]
14
16
  keywords = ["calendar", "date", "time"]
15
17
  classifiers = [
16
- "License :: OSI Approved :: MIT License",
17
18
  "Natural Language :: English",
18
19
  "Programming Language :: Python",
19
20
  "Programming Language :: Python :: 3.8",
@@ -40,7 +40,7 @@ from . import (
40
40
  utils,
41
41
  )
42
42
 
43
- __version__ = '2.4.1'
43
+ __version__ = '2.5.0'
44
44
 
45
45
  __all__ = [
46
46
  'armenian',
@@ -13,6 +13,7 @@ of the ancient Egyptian calendar.
13
13
  It consists of twelve months of 30 days, followed by a "little month" of five days
14
14
  (six in leap years).
15
15
  """
16
+
16
17
  from math import floor
17
18
 
18
19
  from . import gregorian
@@ -49,8 +50,7 @@ def to_jd(year, month, day):
49
50
 
50
51
  def from_jd(jdc):
51
52
  "Create a new date from a Julian date."
52
- cdc = floor(jdc) + 0.5 - EPOCH
53
- year = floor((cdc - floor((cdc + 366) / 1461)) / 365) + 1
53
+ year = floor((4 * floor(jdc - EPOCH) + 1463) / 1461)
54
54
 
55
55
  yday = jdc - to_jd(year, 1, 1)
56
56
 
@@ -22,9 +22,16 @@ def to_jd(year, dayofyear):
22
22
 
23
23
 
24
24
  def from_jd(jd):
25
- '''Convert a Julian day count to an ordinal date.'''
26
- year, _, _ = gregorian.from_jd(jd)
27
- return year, round(jd - gregorian.to_jd(year, 1, 1) + 1)
25
+ '''Convert a Julian day count to an ordinal date.
26
+
27
+ The day of year is derived from the Gregorian date rather than the raw
28
+ ``jd``. Both ``to_jd`` values carry the same half-day offset, so their
29
+ difference is an exact whole number of days; subtracting ``jd`` directly
30
+ leaves a ``.5`` remainder that ``round`` pushes the wrong way (e.g.
31
+ ``365.5`` -> ``366``), reporting a non-existent day 366 in common years.
32
+ '''
33
+ year, month, day = gregorian.from_jd(jd)
34
+ return year, int(gregorian.to_jd(year, month, day) - gregorian.to_jd(year, 1, 1)) + 1
28
35
 
29
36
 
30
37
  def from_gregorian(year, month, day):
@@ -1,34 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: convertdate
3
- Version: 2.4.1
3
+ Version: 2.5.0
4
4
  Summary: Converts between Gregorian dates and other calendar systems
5
+ Author: Phil Schwartz
5
6
  Author-email: Neil Freeman <contact@fakeisthenewreal.org>
6
- License: The MIT License (MIT)
7
-
8
- Copyright (c) 2014-2022 Neil Freeman
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in
18
- all copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
- THE SOFTWARE.
27
-
28
-
7
+ License-Expression: MIT
29
8
  Project-URL: Homepage, https://github.com/fitnr/convertdate
30
9
  Keywords: calendar,date,time
31
- Classifier: License :: OSI Approved :: MIT License
32
10
  Classifier: Natural Language :: English
33
11
  Classifier: Programming Language :: Python
34
12
  Classifier: Programming Language :: Python :: 3.8
@@ -32,6 +32,7 @@ src/convertdate/data/french_republican_days.py
32
32
  src/convertdate/data/positivist.py
33
33
  tests/test_armenian.py
34
34
  tests/test_bahai.py
35
+ tests/test_coptic.py
35
36
  tests/test_french_republican.py
36
37
  tests/test_general.py
37
38
  tests/test_gregorian.py
@@ -0,0 +1,68 @@
1
+ from convertdate import coptic
2
+
3
+ from . import CalTestCase
4
+
5
+
6
+ class TestGregorian(CalTestCase):
7
+ def setUp(self):
8
+ pass
9
+
10
+ def test_epoch(self):
11
+ self.assertEqual(coptic.to_jd(1, 1, 1), coptic.EPOCH)
12
+ self.assertEqual(coptic.to_jd(1, 1, 2), coptic.EPOCH + 1)
13
+ self.assertEqual(coptic.to_jd(2, 1, 1), coptic.EPOCH + 365.0)
14
+ self.assertEqual(coptic.from_jd(coptic.EPOCH), (1, 1, 1))
15
+
16
+ def test_is_leap(self):
17
+ self.assertTrue(coptic.is_leap(1839))
18
+ self.assertTrue(coptic.is_leap(1891))
19
+ self.assertTrue(coptic.is_leap(1999))
20
+ self.assertTrue(coptic.is_leap(2423))
21
+
22
+ self.assertFalse(coptic.is_leap(1800))
23
+ self.assertFalse(coptic.is_leap(1890))
24
+ self.assertFalse(coptic.is_leap(1956))
25
+ self.assertFalse(coptic.is_leap(2000))
26
+
27
+ def test_reflexive_jd(self):
28
+ self.assertEqual(coptic.from_jd(2431772.0), (1662, 3, 3))
29
+
30
+ # leap year 1891
31
+ self.assertEqual(coptic.from_jd(2515715.5), (1891, 13, 5))
32
+ self.assertEqual(coptic.to_jd(1891, 13, 5), 2515715.5)
33
+ self.assertEqual(coptic.from_jd(2515716.0), (1891, 13, 5))
34
+
35
+ self.assertEqual(coptic.from_jd(2515716.5), (1891, 13, 6))
36
+ self.assertEqual(coptic.to_jd(1891, 13, 6), 2515716.5)
37
+ self.assertEqual(coptic.from_jd(2515717.0), (1891, 13, 6))
38
+
39
+ self.assertEqual(coptic.from_jd(2515717.5), (1892, 1, 1))
40
+ self.assertEqual(coptic.to_jd(1892, 1, 1), 2515717.5)
41
+ self.assertEqual(coptic.from_jd(2515718.0), (1892, 1, 1))
42
+
43
+ # regular year 2000 (%4=0)
44
+ self.assertEqual(coptic.from_jd(2555528.0), (2000, 13, 4))
45
+ self.assertEqual(coptic.from_jd(2555528.5), (2000, 13, 5))
46
+ self.assertEqual(coptic.to_jd(2000, 13, 5), 2555528.5)
47
+ self.assertEqual(coptic.from_jd(2555529.0), (2000, 13, 5))
48
+ self.assertEqual(coptic.from_jd(2555529.5), (2001, 1, 1))
49
+
50
+ # regular year 1889 (%4=1)
51
+ self.assertEqual(coptic.from_jd(2514984.5), (1889, 13, 4))
52
+ self.assertEqual(coptic.to_jd(1889, 13, 4), 2514984.5)
53
+ self.assertEqual(coptic.from_jd(2514985.0), (1889, 13, 4))
54
+
55
+ self.assertEqual(coptic.from_jd(2514985.5), (1889, 13, 5))
56
+ self.assertEqual(coptic.to_jd(1889, 13, 5), 2514985.5)
57
+ self.assertEqual(coptic.from_jd(2514986.0), (1889, 13, 5))
58
+
59
+ # regular year 1886 (%4=2)
60
+ self.assertEqual(coptic.from_jd(2513888.5), (1886, 13, 4))
61
+ self.assertEqual(coptic.to_jd(1886, 13, 4), 2513888.5)
62
+ self.assertEqual(coptic.from_jd(2513889.0), (1886, 13, 4))
63
+ self.assertEqual(coptic.from_jd(2513889.5), (1886, 13, 5))
64
+ self.assertEqual(coptic.to_jd(1886, 13, 5), 2513889.5)
65
+ self.assertEqual(coptic.from_jd(2513890.0), (1886, 13, 5))
66
+ self.assertEqual(coptic.from_jd(2513890.5), (1887, 1, 1))
67
+ self.assertEqual(coptic.to_jd(1887, 1, 1), 2513890.5)
68
+ self.assertEqual(coptic.from_jd(2513891.0), (1887, 1, 1))
@@ -1,6 +1,6 @@
1
1
  from calendar import isleap
2
2
 
3
- from convertdate import ordinal
3
+ from convertdate import gregorian, ordinal
4
4
 
5
5
  from . import CalTestCase
6
6
 
@@ -57,3 +57,32 @@ class TestOrdinal(CalTestCase):
57
57
  self.assertEqual(ordinal.from_gregorian(year, 2, 29), (year, 60))
58
58
 
59
59
  self.assertEqual(ordinal.from_gregorian(year, 3, 1), (year, 60 + leap))
60
+
61
+ def test_from_jd_dec_31_common_year(self):
62
+ # An integer Julian day count for December 31 of a common year must map
63
+ # to ordinal day 365, not the non-existent day 366. Regression for the
64
+ # ``round(365.5) -> 366`` half-day rounding bug in ``from_jd``.
65
+ for year in (2021, 2022, 2023, 2025, 2100, 2200):
66
+ self.assertFalse(isleap(year))
67
+ jd = gregorian.to_jd(year, 12, 31) # ...5 (midnight) form
68
+ self.assertEqual(ordinal.from_jd(jd), (year, 365))
69
+ # and the integer JDN that gregorian maps to that same day
70
+ self.assertEqual(ordinal.from_jd(int(jd) + 1), (year, 365))
71
+
72
+ def test_from_jd_dec_31_leap_year(self):
73
+ # Leap-year December 31 stays day 366.
74
+ for year in (2020, 2024, 2000):
75
+ self.assertTrue(isleap(year))
76
+ self.assertEqual(ordinal.from_jd(gregorian.to_jd(year, 12, 31)), (year, 366))
77
+ self.assertEqual(ordinal.from_jd(int(gregorian.to_jd(year, 12, 31)) + 1), (year, 366))
78
+
79
+ def test_from_jd_consistent_with_gregorian(self):
80
+ # For any Julian day -- integer count or ``.5`` midnight form -- the
81
+ # ordinal date must describe the same calendar day as gregorian.from_jd,
82
+ # and never yield a day of year beyond the length of its year.
83
+ for jd in range(2415020, 2488395, 7):
84
+ for j in (jd, jd + 0.5):
85
+ year, doy = ordinal.from_jd(j)
86
+ self.assertEqual((year, doy), ordinal.from_gregorian(*gregorian.from_jd(j)))
87
+ self.assertLessEqual(doy, 366 if isleap(year) else 365)
88
+ self.assertGreaterEqual(doy, 1)
File without changes
File without changes
File without changes