Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #137 from dimagi/today-or-tmrw
Browse files Browse the repository at this point in the history
split today_or_tmrw into separate function
  • Loading branch information
twymer committed Aug 10, 2013
2 parents 78d3158 + 99d7c9a commit a0eb014
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dimagi/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def utcnow_sans_milliseconds():

DEFAULT_DATE_FORMAT = "%Y-%m-%d"

def today_or_tomorrow(date, inclusive=True):
today = datetime.datetime.combine(datetime.datetime.today(), datetime.time())
day_after_tomorrow = today + datetime.timedelta(days=2)
return today <= date + datetime.timedelta(days=1 if inclusive else 0) < day_after_tomorrow

class DateSpan(object):
"""
Expand Down Expand Up @@ -291,10 +295,8 @@ def __str__(self):
if self.startdate.day == 1 and (self.enddate + datetime.timedelta(days=1)).day == 1:
return "%s %s" % (month_name[self.startdate.month], self.startdate.year)

# if the end date is today or tomorrow, use "last N days syntax"
today = datetime.datetime.combine(datetime.datetime.today(), datetime.time())
day_after_tomorrow = today + datetime.timedelta(days=2)
if today <= self.enddate + datetime.timedelta(days=(1 if self.inclusive else 0)) < day_after_tomorrow:
# if the end date is today or tomorrow, use "last N days syntax"
if today_or_tomorrow(self.enddate, self.inclusive):
return "last %s days" % ((self.enddate - self.startdate).days + (1 if self.inclusive else 0))

return "%s to %s" % (self.startdate.strftime(self.format),
Expand Down

0 comments on commit a0eb014

Please sign in to comment.