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.
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.
31
50
32
-
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.
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
+
49
73
```python
50
74
>>> [str(d) for d in [november7, november, year2k, november7_some_year]]
51
75
['2000-11-07', '2000-11', '2000', '--11-07']
52
76
```
53
77
54
78
If enough information is known, an `Undate` object can report on its duration:
79
+
55
80
```python
56
81
>>> december = Undate(2000, 12)
57
82
>>> feb_leapyear = Undate(2024, 2)
@@ -68,7 +93,9 @@ If enough information is known, an `Undate` object can report on its duration:
68
93
2024-02- duration in days: 29
69
94
```
70
95
71
-
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
+
72
99
```python
73
100
>>> november7 = Undate(2000, 11, 7)
74
101
>>> november2000 = Undate(2000, 11)
@@ -86,7 +113,10 @@ False
86
113
False
87
114
```
88
115
89
-
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.
90
120
91
121
```python
92
122
>>> november7_2020 = Undate(2020, 11, 7)
@@ -104,7 +134,8 @@ False
104
134
False
105
135
```
106
136
107
-
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
119
150
```
120
151
121
-
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
>>> UndateInterval(latest=Undate(2000)) # before 2000
133
169
<UndateInterval ../2000>
134
170
>>> UndateInterval(Undate(1900)) # after 1900
@@ -139,8 +175,10 @@ An `UndateInterval` is a date range between two `Undate` objects. Intervals can
139
175
31
140
176
```
141
177
142
-
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.
143
-
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.
144
182
145
183
```python
146
184
>>>from undate import Undate
@@ -158,9 +196,17 @@ Currently available converters are "ISO8601" and "EDTF" and supported calendars.
158
196
159
197
### Calendars
160
198
161
-
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.
164
210
165
211
```python
166
212
>>>from undate import Undate
@@ -183,7 +229,9 @@ Dates are stored with the year, month, day and appropriate precision for the ori
183
229
184
230
***
185
231
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.
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