What python libraries are there for dealing with ancient or imprecise dates?

Python's date library does not support BCE dates - it only supports dates from 1AD onwards. (Limitations on date objects are common to most systems due to the storage format. For example postgresql dates are [limited] to the range 4713 BC to 5874897 AD.)

Python's date library also expects dates to be 'full' dates, i.e. there is no support for differing levels of precision, e.g. the year 1900 must be stored with a month and day rather than just as a year.

Are there any libraries that help you work around these limitations?

asked 23 Jan '11, 12:15

rgrp's gravatar image

rgrp ♦♦
501122027
accept rate: 14%

edited 23 Jan '11, 13:10


There's a 'FlexiDate' library I've contributed to that's part of dateutil:

https://bitbucket.org/okfn/datautil/src/3c79c20ef243/datautil/date.py

This date module can be used completely standalone without any other part of the datautil package and has only one dependency dateutil (which, strictly, is optional). More information from the library docstring:


Date parsing and normalization utilities based on FlexiDate.

To parser dates use parse, e.g.::

parse('1890') -> FlexiDate(year=u'1890')
parse('1890?') -> FlexiDate(year=u'1890', qualifier='Uncertainty: 1985?')

Once you have a FlexiDate you can get access to attributes (strings of course ...)::

fd = parse('Jan 1890')
fd.year # u'1890'
fd.month # u'01'

And convert to other forms:

fd.as_float() # 1890
fd.as_datetime() # datetime(1890,01,01)

Background

FlexiDate is focused on supporting:

  1. Dates outside of Python (or DB) supported period (esp. dates < 0 AD)
  2. Imprecise dates (c.1860, 18??, fl. 1534, etc)
  3. Normalization of dates to machine processable versions
  4. Sortable in the database (in correct date order)

For more information see:

http://www.rufuspollock.org/2009/06/18/flexible-dates-in-python/

link

answered 23 Jan '11, 13:34

rgrp's gravatar image

rgrp ♦♦
501122027
accept rate: 14%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×2
×2
×2

Asked: 23 Jan '11, 12:15

Seen: 964 times

Last updated: 23 Jan '11, 13:34

powered by OSQA