Skip to content

Commit e6fb929

Browse files
committed
Merge branch 'release/0.4' into develop
2 parents 3c722fa + 6098361 commit e6fb929

File tree

8 files changed

+51
-24
lines changed

8 files changed

+51
-24
lines changed

CHANGELOG.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Change Log
22

3+
## 0.4
4+
5+
- Undate is now Calendar aware / Calendar explicit; default is Gregorian
6+
- New `BaseCalendarConverter` class, with additional methods required for calendar converters
7+
- `HebrewDateConverter`: Parsing and calendar conversion for Hebrew/Anno Mundi
8+
- `IslamicDateConverter`: Parsing and calendar conversion for Islamic/Hijri
9+
- `GregorianDateConverter`: basic Gregorian calendar logic
10+
- `undate.Calendar` class to track `Undate` object calendar, and match with calendar converters
11+
- BaseDateConverter class now includes nested/descendant subclasses when looking
12+
for available converters
13+
- `Undate.to_undate` method to convert supported date objects to `Undate` (`datetime.date`, `datetime.datetime`, and internal `undate.date.Date` class)
14+
- `UndateInterval` improvements
15+
- Can be initialized with `Undate` objects or any type supported by `Undate.to_undate`
16+
- New method for contains (`in`), to determine if another interval or date is contained by an interval
17+
- New method `intersection` to determine the overlap between two `UndateInterval` objects
18+
- EDTF parser : fixed day parsing for some unsupported cases
19+
- Dropped support for Python 3.9
20+
- Reorganized examples folder to avoid unnecessary nesting
21+
- ISMI data has been updated from older JSON data to examples in RDF (turtle)
22+
23+
324
## 0.3.1
425

526
Update readthedocs config for current installation
@@ -14,7 +35,7 @@ Update readthedocs config for current installation
1435
- Support 5+ digit years with leading Y (thanks to numpy.datetime64)
1536
- Jupyter notebook demonstrating / validating EDTF support
1637
- Full support for Level 0 Date and Time Interval (no Date and Time support)
17-
- Level 1:
38+
- Level 1:
1839
- Letter-prefixed calendar year
1940
- Unspecified digit from the right
2041
- Partial support for extended interval

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
**undate** is a python library for working with uncertain or partially known dates.
66

77
> [!WARNING]
8-
> This is pre-alpha software and is **NOT** feature complete! Use with caution.
9-
> Currently it only supports parsing and formatting dates in ISO8601 format and
10-
> some portions of EDTF (Extended Date Time Format).
8+
> This is alpha software and is not yet feature complete! Use with caution and give us feedback.
9+
> Currently `undate` supports parsing and formatting dates in ISO8601, some
10+
portions of EDTF (Extended Date Time Format), and parsing and conversion for dates in Hebrew Anno Mundi and Islamic Hijri calendars
1111

1212
*Undate was initially created as part of a [DH-Tech](https://dh-tech.github.io/) hackathon in November 2022.*
1313

14-
---
14+
* * *
1515

1616
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.11068867.svg)](https://doi.org/10.5281/zenodo.11068867)
1717
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
@@ -167,9 +167,9 @@ Dates are stored with the year, month, day and appropriate precision for the ori
167167
>>> tammuz4816 = Undate.parse("26 Tammuz 4816", "Hebrew")
168168
>>> tammuz4816
169169
<Undate '26 Tammuz 4816 Anno Mundi' 4816-04-26 (Hebrew)>
170-
>>> rajab495 = Undate.parse("Rajab 495", "Hijri")
170+
>>> rajab495 = Undate.parse("Rajab 495", "Islamic")
171171
>>> rajab495
172-
<Undate 'Rajab 495 Hijrī' 0495-07 (Hijri)>
172+
<Undate 'Rajab 495 Hijrī' 0495-07 (Islamic)>
173173
>>> y2k = Undate.parse("2001", "EDTF")
174174
>>> y2k
175175
<Undate 2001 (Gregorian)>
@@ -178,12 +178,12 @@ Dates are stored with the year, month, day and appropriate precision for the ori
178178
>>> [str(d.precision) for d in [rajab495, tammuz4816, y2k]]
179179
['MONTH', 'DAY', 'YEAR']
180180
>>> sorted([rajab495, tammuz4816, y2k])
181-
[<Undate '26 Tammuz 4816 Anno Mundi' 4816-04-26 (Hebrew)>, <Undate 'Rajab 495 Hijrī' 0495-07 (Hijri)>, <Undate 2001 (Gregorian)>]
181+
[<Undate '26 Tammuz 4816 Anno Mundi' 4816-04-26 (Hebrew)>, <Undate 'Rajab 495 Hijrī' 0495-07 (Islamic)>, <Undate 2001 (Gregorian)>]
182182
```
183183

184184
* * *
185185

186-
For more examples, refer to the [example notebooks](https://github.com/dh-tech/undate-python/tree/main/examples/notebooks/) included in this repository.
186+
For more examples, refer to the code notebooks included in the [examples](https://github.com/dh-tech/undate-python/tree/main/examples/) in this repository.
187187

188188
## Documentation
189189

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ keywords = [
2929
"digital-humanities",
3030
]
3131
classifiers = [
32-
"Development Status :: 2 - Pre-Alpha",
32+
"Development Status :: 3 - Alpha",
3333
"Programming Language :: Python :: 3",
3434
"Programming Language :: Python :: 3.10",
3535
"Programming Language :: Python :: 3.11",

src/undate/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.4.0.dev0"
1+
__version__ = "0.4.0"
22

33
from undate.date import DatePrecision
44
from undate.undate import Undate, Calendar

src/undate/interval.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def duration(self) -> Timedelta:
9494

9595
# if range is open-ended, can't calculate
9696
if self.earliest is None or self.latest is None:
97-
return NotImplemented
97+
raise NotImplementedError(
98+
"Cannot calculate duration for open-ended interval"
99+
)
98100

99101
# if both years are known, subtract end of range from beginning of start
100102
if self.latest.known_year and self.earliest.known_year:

src/undate/undate.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ def set_calendar(self, calendar: Union[str, Calendar]):
198198
# look for calendar by upper-case name
199199
try:
200200
calendar = Calendar[calendar.upper()]
201-
except KeyError:
202-
raise ValueError(f"Calendar `{calendar}` is not supported")
201+
except KeyError as err:
202+
raise ValueError(f"Calendar `{calendar}` is not supported") from err
203203
self.calendar = calendar
204204

205205
def __str__(self) -> str:
@@ -292,15 +292,13 @@ def __eq__(self, other: object) -> bool:
292292
# in one format (i.e. X for missing digits).
293293
# If we support other formats, will need to normalize to common
294294
# internal format for comparison
295-
if looks_equal:
295+
if looks_equal and (
296296
# if any part of either date that is known is _partially_ known,
297297
# then these dates are not equal
298-
if any(
299-
[self.is_partially_known(p) for p in self.initial_values.keys()]
300-
) or any(
301-
[other.is_partially_known(p) for p in other.initial_values.keys()]
302-
):
303-
return False
298+
any([self.is_partially_known(p) for p in self.initial_values.keys()])
299+
or any([other.is_partially_known(p) for p in other.initial_values.keys()])
300+
):
301+
return False
304302

305303
return looks_equal
306304

@@ -368,8 +366,9 @@ def to_undate(cls, other: object) -> "Undate":
368366
"""Convert arbitrary object to Undate, if possible. Raises TypeError
369367
if conversion is not possible.
370368
371-
Currently suppports:
369+
Currently supports:
372370
- :class:`datetime.date` or :class:`datetime.datetime`
371+
- :class:`undate.date.Date`
373372
374373
"""
375374
match other:

tests/test_converters/test_calendars/test_islamic/test_islamic_parser.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import pytest
2+
from lark.exceptions import LarkError
3+
24
from undate.converters.calendars.islamic.parser import islamic_parser
35

46

@@ -72,5 +74,5 @@ def test_should_parse(date_string):
7274

7375
@pytest.mark.parametrize("date_string", error_cases)
7476
def test_should_error(date_string):
75-
with pytest.raises(Exception):
77+
with pytest.raises(LarkError):
7678
islamic_parser.parse(date_string)

tests/test_interval.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ def test_duration(self):
144144
assert jan_march_duration.days == 2
145145

146146
# duration is not supported for open-ended intervals
147-
assert UndateInterval(Undate(2000), None).duration() == NotImplemented
147+
with pytest.raises(
148+
NotImplementedError, match="Cannot calculate.*open-ended interval"
149+
):
150+
assert UndateInterval(Undate(2000), None).duration()
148151

149152
# one year set and the other not currently raises not implemented error
150153
with pytest.raises(NotImplementedError):

0 commit comments

Comments
 (0)