Maksim Kasimov wrote: > what is the "pythonic" way to check is the date/time value in the given > periods range?
Something like this, though I won't make strong claims of "pythonicness". If you want to use the "in" keyword you'll want a custom class and overriding of __contains__.
Maksim Kasimov wrote: > there are few of a time periods, for example: > 2005-06-08 12:30 -> 2005-06-10 15:30, > 2005-06-12 12:30 -> 2005-06-14 15:30
> and there is some date and time value: > 2005-06-11 12:30 > what is the "pythonic" way to check is the date/time value in the given periods range? >>> import datetime >>> t1 = datetime.datetime(2005, 6, 8, 12, 30) >>> t2 = datetime.datetime(2005, 6, 10, 15, 30) >>> t = datetime.datetime(2005, 6, 9, 14, 00) >>> if t1 < t < t2:
... print "In range" ... In range
>>> t = datetime.datetime(2005, 6, 8, 14, 00) >>> if t1 < t < t2:
>>> r = InRange(t1, t2) >>> datetime.datetime(2005, 6, 7, 14, 00) in r False >>> datetime.datetime(2005, 6, 8, 14, 00) in r True >>> datetime.datetime(2005, 6, 9, 14, 00) in r True >>> datetime.datetime(2005, 6, 9, 18, 00) in r True >>> datetime.datetime(2005, 6, 10, 18, 00) in r False