def date_range(year, month): """return a tuple of two datetimes suitable for a range query""" begin = datetime.datetime(year, month, 1) endyear, endmonth = next_month(year, month) end = datetime.datetime(endyear, endmonth, 1) return coarse_datetime_repr(begin), coarse_datetime_repr(end)
def _init_next_datetime(self): next = next_month(self.focus_datetime.year, self.focus_datetime.month) monthrange = calendar.monthrange(next[0], next[1]) if self.focus_datetime.day <= monthrange[1]: day = self.focus_datetime.day else: day = monthrange[1] self.next_datetime = datetime.datetime(next[0], next[1], day)
def _init_next_datetime(self): last_day = calendar.monthrange(self.focus_datetime.year, self.focus_datetime.month)[1] plus_one = self.focus_datetime.day + 1 if (plus_one > last_day): year, month = next_month(self.focus_datetime.year, self.focus_datetime.month) day = 1 else: year = self.focus_datetime.year month = self.focus_datetime.month day = plus_one self.next_datetime = datetime.datetime(year, month, day)