News for hackers. Stuff that matters.
Re:Maya – Python Datetimes for Humans by BoppreH on Sunday December 18, 2016 @05:20AM (#13205197)
Awesome! Timekeeping is hard and I'm glad we now have one more tool do deal with it.

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

    # Did this event happen "yesterday" according to the US/Eastern time zone?
    timestamp in maya.when('yesterday', to_timezone='US/Eastern')

    # Get me all events that happened last Friday (UTC)
    [event for event in events if event.time in maya.when('2016-12-16')]
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

Re:Maya – Python Datetimes for Humans by Klathmon on Sunday December 18, 2016 @09:33AM (#13205904)
Honestly I feel like it would be easier to just have the "precision" of a date/time be adjustable.

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.

Re:Maya – Python Datetimes for Humans by BoppreH on Sunday December 18, 2016 @09:42AM (#13205937)
That's exactly what I meant. Omitted parts should not be treated as zeroes, but as "any".
Re:Maya – Python Datetimes for Humans by jeffbr13 on Sunday December 18, 2016 @03:59PM (#13207606)
Python already contains separate date and time objects for this purpose[1][2]!

[1]: https://docs.python.org/3/library/datetime.html#date-objects [2]: https://docs.python.org/3/library/datetime.html#time-objects

Re:Maya – Python Datetimes for Humans by BoppreH on Sunday December 18, 2016 @04:14PM (#13207684)
I think that would only work for day long ranges. What if I want the events that happened in the last hour, or that are scheduled for May?
Re:Maya – Python Datetimes for Humans by jeffbr13 on Sunday December 18, 2016 @06:05PM (#13208263)
Combine pure dates and times with timedelta[1]? Python's multiple comparison expressions help here too.

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/

Re:Maya – Python Datetimes for Humans by RubyPinch on Sunday December 18, 2016 @09:15PM (#13209030)
probably would be easier to hide it away in a small class with `__contains__`

    event_datetime in daterange(timedelta(hours=1), before=datetime.now())
Re:Maya – Python Datetimes for Humans by robochat on Sunday December 18, 2016 @04:35PM (#13207787)
The pandas library has a period data type if you're looking for one.
Re:Maya – Python Datetimes for Humans by aorth on Monday December 19, 2016 @07:32AM (#13210980)
Important note from the comments in that issue: Kenneth says that Maya is only tested on Python 2.7 so far. Python 3 support is coming later.

https://github.com/kennethreitz/maya/issues/10#issuecomment-...

Re:Maya – Python Datetimes for Humans by supergreg on Sunday December 18, 2016 @11:18AM (#13206276)
Maybe `when` should be renamed or an alias to `at` and add an `in` method to make it more explicit.
Re:Maya – Python Datetimes for Humans by tokenizerrr on Sunday December 18, 2016 @09:24AM (#13205877)
How would you serialize that range to, for example, ISO8601?
Re:Maya – Python Datetimes for Humans by cheapsteak on Sunday December 18, 2016 @09:35AM (#13205916)
From wiki: ISO8601 has four ways to express a time interval:

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

http://en.wikipedia.org/wiki/ISO_8601#Time_intervals

Re:Maya – Python Datetimes for Humans by BoppreH on Sunday December 18, 2016 @09:38AM (#13205925)
Excellent question. ISO 8601 has features to encode time intervals ( https://en.wikipedia.org/wiki/ISO_8601#Time_intervals ).

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.

Re:Maya – Python Datetimes for Humans by AdamN on Sunday December 18, 2016 @12:05PM (#13206503)
This would need to be done in Python itself, not Maya. I'd be strongly in favor of it though.
Re:Maya – Python Datetimes for Humans by yunruse on Sunday December 18, 2016 @01:05PM (#13206788)
Not necessarily. Python objects can declare a `__contains__` function (such that `x in y` corresponds to `x.__contains__(y)`):

https://docs.python.org/3.5/reference/datamodel.html#object....