Skip to content

Commit 2a7bcc1

Browse files
authored
Merge pull request #131 from dh-tech/feature/improve-readme
Improve readme
2 parents e664a81 + e01c065 commit 2a7bcc1

2 files changed

Lines changed: 68 additions & 20 deletions

File tree

README.md

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,37 @@ portions of EDTF (Extended Date Time Format), and parsing and conversion for dat
2525

2626
Read [Contributors](CONTRIBUTORS.md) for detailed contribution information.
2727

28+
## Installation
29+
30+
*Recommended*: use pip to install the latest published version from PyPI:
31+
32+
```console
33+
pip install undate
34+
```
35+
36+
To install a development version or specific tag or branch, you can install from GitHub.
37+
Use the `@name` notation to specify the branch or tag; e.g., to install development version:
38+
39+
```console
40+
pip install git+https://github.com/dh-tech/undate-python@develop#egg=undate
41+
```
42+
2843
## Example Usage
2944

30-
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.
3150

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.
55+
An `Undate` can take an optional label.
3356

3457
```python
35-
from undate.undate import Undate
58+
from undate import Undate
3659

3760
november7 = Undate(2000, 11, 7)
3861
november = Undate(2000, 11)
@@ -46,12 +69,14 @@ easter1916 = Undate(1916, 4, 23, label="Easter 1916")
4669
```
4770

4871
You can convert an `Undate` to string using a date formatter (current default is ISO8601):
72+
4973
```python
5074
>>> [str(d) for d in [november7, november, year2k, november7_some_year]]
5175
['2000-11-07', '2000-11', '2000', '--11-07']
5276
```
5377

5478
If enough information is known, an `Undate` object can report on its duration:
79+
5580
```python
5681
>>> december = Undate(2000, 12)
5782
>>> feb_leapyear = Undate(2024, 2)
@@ -68,7 +93,9 @@ If enough information is known, an `Undate` object can report on its duration:
6893
2024-02 - duration in days: 29
6994
```
7095

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+
7299
```python
73100
>>> november7 = Undate(2000, 11, 7)
74101
>>> november2000 = Undate(2000, 11)
@@ -86,7 +113,10 @@ False
86113
False
87114
```
88115

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.
90120

91121
```python
92122
>>> november7_2020 = Undate(2020, 11, 7)
@@ -104,7 +134,8 @@ False
104134
False
105135
```
106136

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
138+
methods raise a `NotImplementedError`.
108139

109140
```python
110141
>>> november_2020 = Undate(2020, 11)
@@ -118,17 +149,22 @@ Traceback (most recent call last):
118149
NotImplementedError: Can't compare when one date falls within the other
119150
```
120151

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
156+
and latest date as part of the range.
157+
122158
```python
123-
>>> from undate.undate import UndateInterval
159+
>>> from undate import UndateInterval
124160
>>> UndateInterval(Undate(1900), Undate(2000))
125161
<UndateInterval 1900/2000>
126-
>>> UndateInterval(Undate(1900), Undate(2000), label="19th century")
127-
>>> UndateInterval(Undate(1900), Undate(2000), label="19th century").duration().days
128-
36890
129-
<UndateInterval '19th century' (1900/2000)>
130-
>>> UndateInterval(Undate(1900), Undate(2000), label="20th century")
131-
<UndateInterval '20th century' (1900/2000)>
162+
>>> UndateInterval(Undate(1801), Undate(1900), label="19th century")
163+
>>> UndateInterval(Undate(1801), Undate(1900), label="19th century").duration().days
164+
36524
165+
<UndateInterval '19th century' (1801/1900)>
166+
>>> UndateInterval(Undate(1901), Undate(2000), label="20th century")
167+
<UndateInterval '20th century' (1901/2000)>
132168
>>> UndateInterval(latest=Undate(2000)) # before 2000
133169
<UndateInterval ../2000>
134170
>>> UndateInterval(Undate(1900)) # after 1900
@@ -139,8 +175,10 @@ An `UndateInterval` is a date range between two `Undate` objects. Intervals can
139175
31
140176
```
141177

142-
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.
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` object in those formats. Currently available converters
181+
are "ISO8601" and "EDTF" and supported calendars.
144182

145183
```python
146184
>>> from undate import Undate
@@ -158,9 +196,17 @@ Currently available converters are "ISO8601" and "EDTF" and supported calendars.
158196

159197
### Calendars
160198

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
203+
calendar conversion logic implemented in the
204+
[convertdate](https://convertdate.readthedocs.io/en/latest/) package.
162205

163-
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.
164210

165211
```python
166212
>>> from undate import Undate
@@ -183,7 +229,9 @@ Dates are stored with the year, month, day and appropriate precision for the ori
183229

184230
* * *
185231

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
234+
repository.
187235

188236
## Documentation
189237

src/undate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.4.0"
1+
__version__ = "0.5.0.dev0"
22

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

0 commit comments

Comments
 (0)