From 99d7c9a3202b294516e0834daa972b40a8703fe0 Mon Sep 17 00:00:00 2001 From: yedi Date: Fri, 9 Aug 2013 15:57:30 -0400 Subject: [PATCH] split today_or_tmrw into separate function --- dimagi/utils/dates.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dimagi/utils/dates.py b/dimagi/utils/dates.py index e179255..2108f39 100644 --- a/dimagi/utils/dates.py +++ b/dimagi/utils/dates.py @@ -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): """ @@ -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),