You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
You can convert an `Undate` to string using a date formatter (current default is ISO8601):
72
+
64
73
```python
65
74
>>> [str(d) for d in [november7, november, year2k, november7_some_year]]
66
75
['2000-11-07', '2000-11', '2000', '--11-07']
67
76
```
68
77
69
78
If enough information is known, an `Undate` object can report on its duration:
79
+
70
80
```python
71
81
>>> december = Undate(2000, 12)
72
82
>>> feb_leapyear = Undate(2024, 2)
@@ -83,7 +93,9 @@ If enough information is known, an `Undate` object can report on its duration:
83
93
2024-02- duration in days: 29
84
94
```
85
95
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
+
87
99
```python
88
100
>>> november7 = Undate(2000, 11, 7)
89
101
>>> november2000 = Undate(2000, 11)
@@ -101,7 +113,10 @@ False
101
113
False
102
114
```
103
115
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.
105
120
106
121
```python
107
122
>>> november7_2020 = Undate(2020, 11, 7)
@@ -119,7 +134,8 @@ False
119
134
False
120
135
```
121
136
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
NotImplementedError: Can't compare when one date falls within the other
134
150
```
135
151
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
+
137
158
```python
138
159
>>>from undate import UndateInterval
139
160
>>> UndateInterval(Undate(1900), Undate(2000))
@@ -154,8 +175,10 @@ An `UndateInterval` is a date range between two `Undate` objects. Intervals can
154
175
31
155
176
```
156
177
157
-
You can initialize `Undate`or`UndateInterval` objects by parsing a date string with a specific converter, and you can also output an `Undate`objectin 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`objectin those formats. Currently available converters
181
+
are "ISO8601"and"EDTF"and supported calendars.
159
182
160
183
```python
161
184
>>>from undate import Undate
@@ -173,9 +196,17 @@ Currently available converters are "ISO8601" and "EDTF" and supported calendars.
173
196
174
197
### Calendars
175
198
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
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.
179
210
180
211
```python
181
212
>>>from undate import Undate
@@ -198,7 +229,9 @@ Dates are stored with the year, month, day and appropriate precision for the ori
198
229
199
230
***
200
231
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
0 commit comments