Just off the top of my head, ISO8601 is already in the right order, just letting users "leave off" anything that's not important and then having a library interpret those "partial dates" as a range internally so it's easy to check identity or if one date is "in" another.
[1]: https://docs.python.org/3/library/datetime.html#date-objects [2]: https://docs.python.org/3/library/datetime.html#time-objects
For events in the last hour, the following expression should evaluate to True:
(datetime.now() - timedelta(hours=1)) <= event_datetime
Checking whether event_datetime is within May of the current year is a bit more involved, but you may not need to convert everything to a date (would have to check in an interpreter): date.today().replace(month=5, day=1) <= event_datetime.date() <= date.today().replace(month=5, day=31)
The point is that the language already has good support for sensible time operations, but it's parsing is weak. And there's Arrow for that[2]![1]: https://docs.python.org/3/library/datetime.html#timedelta-ob... [2]: http://arrow.readthedocs.io/en/latest/
event_datetime in daterange(timedelta(hours=1), before=datetime.now())https://github.com/kennethreitz/maya/issues/10#issuecomment-...
1. Start and end, such as "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z".
2. Start and duration, such as "2007-03-01T13:00:00Z/P1Y2M10DT2H30M"
3. Duration and end, such as "P1Y2M10DT2H30M/2008-05-11T15:30:00Z"
4. Duration only, such as "P1Y2M10DT2H30M", with additional context information
If that's too verbose, and we only need to represent integer intervals, one could store a truncated representation, where the omitted parts mean "any" (like * in cron). For example, `2016-11` could mean the entire month of November.
But those are just ideas for the representation. The important feature is that not all objects are precise points in time, but may be a block/interval/range.
https://docs.python.org/3.5/reference/datamodel.html#object....
One thing that is bothering me is that when you ask for `maya.when('tomorrow')`, or give only a date, you get back a timestamp with millisecond precision, representing 00:00 of that day. I understand this simplifies the implementation, but shouldn't `tomorrow` be a range, from 00:00 to 23:59?
Treating imprecise dates as ranges would allow for stuff like
Maybe I'm being naive, and there's a reason why this won't work, but this seems the way most humans deal with time.PS: it failed to install on Windows, so I opened an issue at https://github.com/kennethreitz/maya/issues/10