Skip to content

Commit e01c065

Browse files
committed
Add a note that intervals are inclusive/closed; improve formatting
1 parent 47a6c57 commit e01c065

1 file changed

Lines changed: 45 additions & 12 deletions

File tree

README.md

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ pip install git+https://github.com/dh-tech/undate-python@develop#egg=undate
4242

4343
## Example Usage
4444

45-
Often humanities and cultural data include imprecise or uncertain temporal information. We want to store that information but also work with it in a structured way, not just treat it as text for display. Different projects may need to work with or convert between different date formats or even different calendars.
46-
47-
An `undate.Undate` is analogous to python’s builtin `datetime.date` object, but with support for varying degrees of precision and unknown information. You can initialize an undate with either strings or numbers for whichever parts of the date are known or partially known. An `Undate` can take an optional label.
45+
Often humanities and cultural data include imprecise or uncertain
46+
temporal information. We want to store that information but also work
47+
with it in a structured way, not just treat it as text for display.
48+
Different projects may need to work with or convert between different
49+
date formats or even different calendars.
50+
51+
An `undate.Undate` is analogous to python’s builtin `datetime.date`
52+
object, but with support for varying degrees of precision and unknown
53+
information. You can initialize an `Undate` with either strings or
54+
numbers for whichever parts of the date are known or partially known.
55+
An `Undate` can take an optional label.
4856

4957
```python
5058
from undate import Undate
@@ -61,12 +69,14 @@ easter1916 = Undate(1916, 4, 23, label="Easter 1916")
6169
```
6270

6371
You can convert an `Undate` to string using a date formatter (current default is ISO8601):
72+
6473
```python
6574
>>> [str(d) for d in [november7, november, year2k, november7_some_year]]
6675
['2000-11-07', '2000-11', '2000', '--11-07']
6776
```
6877

6978
If enough information is known, an `Undate` object can report on its duration:
79+
7080
```python
7181
>>> december = Undate(2000, 12)
7282
>>> feb_leapyear = Undate(2024, 2)
@@ -83,7 +93,9 @@ If enough information is known, an `Undate` object can report on its duration:
8393
2024-02 - duration in days: 29
8494
```
8595

86-
If enough of the date is known and the precision supports it, you can check if one date falls within another date:
96+
If enough of the date is known and the precision supports it, you can
97+
check if one date falls within another date:
98+
8799
```python
88100
>>> november7 = Undate(2000, 11, 7)
89101
>>> november2000 = Undate(2000, 11)
@@ -101,7 +113,10 @@ False
101113
False
102114
```
103115

104-
For dates that are imprecise or partially known, `undate` calculates earliest and latest possible dates for comparison purposes so you can sort dates and compare with equals, greater than, and less than. You can also compare with python `datetime.date` objects.
116+
For dates that are imprecise or partially known, `undate` calculates
117+
earliest and latest possible dates for comparison purposes so you can
118+
sort dates and compare with equals, greater than, and less than. You
119+
can also compare with python `datetime.date` objects.
105120

106121
```python
107122
>>> november7_2020 = Undate(2020, 11, 7)
@@ -119,7 +134,8 @@ False
119134
False
120135
```
121136

122-
When dates cannot be compared due to ambiguity or precision, comparison methods raise a `NotImplementedError`.
137+
When dates cannot be compared due to ambiguity or precision, comparison
138+
methods raise a `NotImplementedError`.
123139

124140
```python
125141
>>> november_2020 = Undate(2020, 11)
@@ -133,7 +149,12 @@ Traceback (most recent call last):
133149
NotImplementedError: Can't compare when one date falls within the other
134150
```
135151

136-
An `UndateInterval` is a date range between two `Undate` objects. Intervals can be open-ended, allow for optional labels, and can calculate duration if enough information is known
152+
An `UndateInterval` is a date range between two `Undate` objects.
153+
Intervals can be open-ended, allow for optional labels, and can
154+
calculate duration if enough information is known. `UndateIntervals`
155+
are inclusive (i.e., a closed interval), and include both the earliest
156+
and latest date as part of the range.
157+
137158
```python
138159
>>> from undate import UndateInterval
139160
>>> UndateInterval(Undate(1900), Undate(2000))
@@ -154,8 +175,10 @@ An `UndateInterval` is a date range between two `Undate` objects. Intervals can
154175
31
155176
```
156177

157-
You can initialize `Undate` or `UndateInterval` objects by parsing a date string with a specific converter, and you can also output an `Undate` object in those formats.
158-
Currently available converters are "ISO8601" and "EDTF" and supported calendars.
178+
You can initialize `Undate` or `UndateInterval` objects by parsing a
179+
date string with a specific converter, and you can also output an
180+
`Undate` object in those formats. Currently available converters
181+
are "ISO8601" and "EDTF" and supported calendars.
159182

160183
```python
161184
>>> from undate import Undate
@@ -173,9 +196,17 @@ Currently available converters are "ISO8601" and "EDTF" and supported calendars.
173196

174197
### Calendars
175198

176-
All `Undate` objects are calendar aware, and date converters include support for parsing and working with dates from other calendars. The Gregorian calendar is used by default; currently `undate` supports the Islamic Hijri calendar and the Hebrew Anno Mundi calendar based on calendar conversion logic implemented in the [convertdate](https://convertdate.readthedocs.io/en/latest/) package.
199+
All `Undate` objects are calendar aware, and date converters include
200+
support for parsing and working with dates from other calendars. The
201+
Gregorian calendar is used by default; currently `undate` supports the
202+
Islamic Hijri calendar and the Hebrew Anno Mundi calendar based on
203+
calendar conversion logic implemented in the
204+
[convertdate](https://convertdate.readthedocs.io/en/latest/) package.
177205

178-
Dates are stored with the year, month, day and appropriate precision for the original calendar; internally, earliest and latest dates are calculated in Gregorian / Proleptic Gregorian calendar for standardized comparison across dates from different calendars.
206+
Dates are stored with the year, month, day and appropriate precision for
207+
the original calendar; internally, earliest and latest dates are
208+
calculated in Gregorian / Proleptic Gregorian calendar for standardized
209+
comparison across dates from different calendars.
179210

180211
```python
181212
>>> from undate import Undate
@@ -198,7 +229,9 @@ Dates are stored with the year, month, day and appropriate precision for the ori
198229

199230
* * *
200231

201-
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.
232+
For more examples, refer to the code notebooks included in the[examples]
233+
(https://github.com/dh-tech/undate-python/tree/main/examples/) in this
234+
repository.
202235

203236
## Documentation
204237

0 commit comments

Comments
 (0)