Package: approx-dates
[This is a preliminary version of this library (hence the 0.*
version number) and the API may change.]It’s frequently useful to be able to represent partial or
approximate dates in Python.  Colloquially, examples of these
might be:1963 (i.e. just the year, with no month or day specified)March 1979 (i.e. just the year and the month, with no day
specified)At some point before the 21st of July 2015At some point after 1st January 2000Some point between 25th and 31st of December 2016At an arbitrary or unknown point in the pastAt an arbitrary or unknown point in the futureTheApproxDateclass can represent all of the above, as well
as precise dates, where the exact year, month and day is known.This package has been tested on Python 2.7 and Python 3.5.Similar PackagesThe alternative to this package that I’m aware of is theApproximateDateclass fromdjango-date-extensions. This has
a different model for approximate dates - they can bepast,future,YYYY,YYYY-MMorYYYY-MM-DD, whereas theApproxDatemodel in this package can also represent a date
which is known to be between two arbitrary dates, or is known to
be before (or after) some particular date.InstallationYou can install this package with:pipinstallapprox_datesUsageYou can create a full date or a partial date from the an ISO
8601 string:fromapprox_dates.modelsimportApproxDateApproxDate.from_iso8601('1215-06-15')ApproxDate.from_iso8601('1215-06')ApproxDate.from_iso8601('1215')Or you can reprent points arbitrarily far in the past or future
with:ApproxDate.PASTApproxDate.FUTURETo represent a date that’s somewhere within two bounds, you can
specify two endpoints. For example:fromdatetimeimportdateApproxDate(date(2016,12,25),date(2016,12,31))These endpoints are intended to be inclusive. For example, the
aboveApproxDatemight represent the 25th, 26th, … or the
31st of December 2016.You can test whether anApproxDaterepresents arbitrarily
far in the future or in the past with thepastandfutureproperties which evaluate toTrueorFalse.To convert anApproxDateinto one of core Python’sdatetime.dateobjects, you can use on of the following
methods:ad=ApproxDate.from_iso8601('1979-03')ad.earliest_date>>>datetime.date(1979,3,1)ad.latest_date>>>datetime.date(1979,3,31)ad.midpoint_date>>>datetime.date(1979,3,16)Obviously, whether oneApproxDateis earlier or later than
another is ill-defined, so the__lt__,__gt__,__lte__and__gte__magic methods are not defined onApproxDate.  If you need to compare twoApproxDateobjects, you need to first convert it to adatetime.dateusing one of the methods above.The__eq__and__ne__magic methods are defined, so that
two approx dates can be tested for whether they represent
exactly the same possible range of dates.  If the right hand
side of an equality or inequality comparison is adatetime.date, it will treated equal if theApproxDateon the left is precise to a day, and reprents the same date.You can also test whether adatetime.datemight be between
twoApproxDateordatetime.dateobjects using theApproxDate.possibly_betweenclass method, e.g.:d1=ApproxDate.from_iso8601('2000')d2=ApproxDate.from_iso8601('2005')ApproxDate.possibly_between(d1,date(2000,7,1),d2)>>>TrueApproxDate.possibly_between(d1,date(1999,12,31),d2)>>>TrueDevelopmentAfter cloning this repository, you can install the dependencies
for development with:pipinstall-e.pipinstalltoxAnd then run the tests with:tox