Skip to content

Commit 5ef75b4

Browse files
committed
Merge branch 'hotfix/0.5.2'
2 parents 68a4bba + 887f6e9 commit 5ef75b4

File tree

11 files changed

+314
-80
lines changed

11 files changed

+314
-80
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 0.5.2
4+
- repr for Undate, UndateInterval, and UnDelta now produce fully-qualified, constructor-style strings with deterministic field ordering.
5+
- Added Undate.unknown_year property and is_unknown() method to check for fully-unknown year/month/day.
6+
- bugfix: comparisons (eq, gt, lt) and contains (in) now return False when year is unknown
7+
- bugfix: month durations for non-Gregorian dates now returns an integer when month length is known
8+
39
## 0.5.1
410
- Correct license identifier in CITATION.cff so it is valid
511

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ earliest and latest possible dates for comparison purposes so you can
121121
sort dates and compare with equals, greater than, and less than. You
122122
can also compare with python `datetime.date` objects.
123123

124-
```python
124+
```python
125125
>>> november7_2020 = Undate(2020, 11, 7)
126126
>>> november_2001 = Undate(2001, 11)
127127
>>> year2k = Undate(2000)
128128
>>> ad100 = Undate(100)
129129
>>> sorted([november7_2020, november_2001, year2k, ad100])
130-
[<Undate 0100>, <Undate 2000>, <Undate 2001-11>, <Undate 2020-11-07>]
130+
[undate.Undate(year=100, calendar="Gregorian"), undate.Undate(year=2000, calendar="Gregorian"), undate.Undate(year=2001, month=11, calendar="Gregorian"), undate.Undate(year=2020, month=11, day=7, calendar="Gregorian")]
131131
>>> november7_2020 > november_2001
132132
True
133133
>>> year2k < ad100
@@ -161,17 +161,17 @@ and latest date as part of the range.
161161
```python
162162
>>> from undate import UndateInterval
163163
>>> UndateInterval(Undate(1900), Undate(2000))
164-
<UndateInterval 1900/2000>
164+
undate.UndateInterval(earliest=undate.Undate(year=1900, calendar="Gregorian"), latest=undate.Undate(year=2000, calendar="Gregorian"))
165165
>>> UndateInterval(Undate(1801), Undate(1900), label="19th century")
166+
undate.UndateInterval(earliest=undate.Undate(year=1801, calendar="Gregorian"), latest=undate.Undate(year=1900, calendar="Gregorian"), label="19th century")
166167
>>> UndateInterval(Undate(1801), Undate(1900), label="19th century").duration().days
167168
36524
168-
<UndateInterval '19th century' (1801/1900)>
169169
>>> UndateInterval(Undate(1901), Undate(2000), label="20th century")
170-
<UndateInterval '20th century' (1901/2000)>
170+
undate.UndateInterval(earliest=undate.Undate(year=1901, calendar="Gregorian"), latest=undate.Undate(year=2000, calendar="Gregorian"), label="20th century")
171171
>>> UndateInterval(latest=Undate(2000)) # before 2000
172-
<UndateInterval ../2000>
172+
undate.UndateInterval(latest=undate.Undate(year=2000, calendar="Gregorian"))
173173
>>> UndateInterval(Undate(1900)) # after 1900
174-
<UndateInterval 1900/>
174+
undate.UndateInterval(earliest=undate.Undate(year=1900, calendar="Gregorian"))
175175
>>> UndateInterval(Undate(1900), Undate(2000), label="19th century").duration().days
176176
36890
177177
>>> UndateInterval(Undate(2000, 1, 1), Undate(2000, 1,31)).duration().days
@@ -186,15 +186,15 @@ are "ISO8601" and "EDTF" and supported calendars.
186186
```python
187187
>>> from undate import Undate
188188
>>> Undate.parse("2002", "ISO8601")
189-
<Undate 2002>
189+
undate.Undate(year=2002, calendar="Gregorian")
190190
>>> Undate.parse("2002-05", "EDTF")
191-
<Undate 2002-05>
191+
undate.Undate(year=2002, month=5, calendar="Gregorian")
192192
>>> Undate.parse("--05-03", "ISO8601")
193-
<Undate --05-03>
193+
undate.Undate(month=5, day=3, calendar="Gregorian")
194194
>>> Undate.parse("--05-03", "ISO8601").format("EDTF")
195195
'XXXX-05-03'
196-
>>> Undate.parse("1800/1900")
197-
<UndateInterval 1800/1900>
196+
>>> Undate.parse("1800/1900", format="EDTF")
197+
undate.UndateInterval(earliest=undate.Undate(year=1800, calendar="Gregorian"), latest=undate.Undate(year=1900, calendar="Gregorian"))
198198
```
199199

200200
### Calendars
@@ -215,26 +215,26 @@ comparison across dates from different calendars.
215215
>>> from undate import Undate
216216
>>> tammuz4816 = Undate.parse("26 Tammuz 4816", "Hebrew")
217217
>>> tammuz4816
218-
<Undate '26 Tammuz 4816 Anno Mundi' 4816-04-26 (Hebrew)>
218+
undate.Undate(year=4816, month=4, day=26, label="26 Tammuz 4816 Anno Mundi", calendar="Hebrew")
219219
>>> rajab495 = Undate.parse("Rajab 495", "Islamic")
220220
>>> rajab495
221-
<Undate 'Rajab 495 Hijrī' 0495-07 (Islamic)>
221+
undate.Undate(year=495, month=7, label="Rajab 495 Islamic", calendar="Islamic")
222222
>>> y2k = Undate.parse("2001", "EDTF")
223223
>>> y2k
224-
<Undate 2001 (Gregorian)>
224+
undate.Undate(year=2001, calendar="Gregorian")
225225
>>> [str(d.earliest) for d in [rajab495, tammuz4816, y2k]]
226226
['1102-04-28', '1056-07-17', '2001-01-01']
227227
>>> [str(d.precision) for d in [rajab495, tammuz4816, y2k]]
228228
['MONTH', 'DAY', 'YEAR']
229229
>>> sorted([rajab495, tammuz4816, y2k])
230-
[<Undate '26 Tammuz 4816 Anno Mundi' 4816-04-26 (Hebrew)>, <Undate 'Rajab 495 Hijrī' 0495-07 (Islamic)>, <Undate 2001 (Gregorian)>]
230+
[undate.Undate(year=4816, month=4, day=26, label="26 Tammuz 4816 Anno Mundi", calendar="Hebrew"), undate.Undate(year=495, month=7, label="Rajab 495 Islamic", calendar="Islamic"), undate.Undate(year=2001, calendar="Gregorian")]
231231
```
232232

233233
---
234234

235-
For more examples, refer to the code notebooks included in the[examples]
236-
(https://github.com/dh-tech/undate-python/tree/main/examples/) in this
237-
repository.
235+
For more examples, refer to the code notebooks included in the
236+
[examples](https://github.com/dh-tech/undate-python/tree/main/examples/)
237+
directory in this repository.
238238

239239
## Documentation
240240

src/undate/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
__version__ = "0.5.1"
1+
__version__ = "0.5.2"
22

3-
from undate.date import DatePrecision
3+
from undate.date import DatePrecision, UnDelta
44
from undate.undate import Undate, Calendar
55
from undate.interval import UndateInterval
66

7-
__all__ = ["Undate", "UndateInterval", "Calendar", "DatePrecision", "__version__"]
7+
__all__ = [
8+
"Undate",
9+
"UndateInterval",
10+
"Calendar",
11+
"DatePrecision",
12+
"UnDelta",
13+
"__version__",
14+
]

src/undate/converters/calendars/hebrew/converter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ class HebrewDateConverter(BaseCalendarConverter):
2121
name: str = "Hebrew"
2222
calendar_name: str = "Anno Mundi"
2323

24+
#: earliest possible year in the Hebrew calendar is year 1, it does not go negative
25+
MIN_YEAR: int = 1
26+
# convertdate gives a month 34 for numpy max year 2.5^16, so scale it back a bit
27+
MAX_YEAR = int(2.5e12)
28+
2429
#: arbitrary known non-leap year; 4816 is a non-leap year with 353 days (minimum possible)
2530
NON_LEAP_YEAR: int = 4816
2631
#: arbitrary known leap year; 4837 is a leap year with 385 days (maximum possible)

src/undate/date.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(self, *days: int):
145145
def __repr__(self):
146146
# customize string representation for simpler notation; default
147147
# specifies full UnInt initialization with upper and lower keywords
148-
return f"{self.__class__.__name__}(days=[{self.days.lower},{self.days.upper}])"
148+
return f"undate.{self.__class__.__name__}({self.days.lower},{self.days.upper})"
149149

150150
def __eq__(self, other: object) -> bool:
151151
# is an uncertain duration ever *equal* another, even if the values are the same?

src/undate/interval.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,15 @@ def format(self, format) -> str:
7070
raise ValueError(f"Unsupported format '{format}'")
7171

7272
def __repr__(self) -> str:
73-
if self.label:
74-
return "<UndateInterval '%s' (%s)>" % (self.label, self)
75-
return "<UndateInterval %s>" % self
73+
init_opts = {
74+
"earliest": repr(self.earliest) if self.earliest else None,
75+
"latest": repr(self.latest) if self.latest else None,
76+
"label": f"{self.label!r}" if self.label else None,
77+
}
78+
init_str = ", ".join(
79+
[f"{key}={val}" for key, val in init_opts.items() if val is not None]
80+
)
81+
return f"undate.UndateInterval({init_str})"
7682

7783
def __eq__(self, other) -> bool:
7884
# currently doesn't support comparison with any other types

0 commit comments

Comments
 (0)