def test_labelize(self): label = self.facet.labelize('label', '1940-01-01-2014-12-31') expected = 'label: {0} - {1}'.format( format_date(date(1940, 01, 01), 'short'), format_date(date(2014, 12, 31), 'short') ) self.assertEqual(label, expected)
def test_labelize(self): label = self.facet.labelize('1940-01-01-2014-12-31') expected = '{0} - {1}'.format( format_date(date(1940, 1, 1), 'short'), format_date(date(2014, 12, 31), 'short') ) self.assertEqual(label, expected)
def daterange(value, details=False): '''Display a date range in the shorter possible maner.''' if not isinstance(value, db.DateRange): raise ValueError('daterange only accept db.DateRange as parameter') if details: return daterange_with_details(value) date_format = 'YYYY' delta = value.end - value.start start, end = None, None start = format_date(value.start, date_format) if delta.days > 365: end = format_date(value.end, date_format) return '{start!s}–{end!s}'.format(start=start, end=end) if end else start
def labelize(self, label, value): start, end = self.parse_value(value) return '{0}: {1} - {2}'.format(label, format_date(start, 'short'), format_date(end, 'short'))
def short_day(date): return format_date(date, pgettext('day-format', 'yyyy/MM/dd'))
def short_month(date): return format_date(date, pgettext('month-format', 'yyyy/MM'))
def isodate(value, format='short'): dt = date(*map(int, value.split('-'))) return format_date(dt, format)
def default_labelizer(self, value): self.validate_parameter(value) start, end = self.parse_value(value) return ' - '.join((format_date(start, 'short'), format_date(end, 'short')))
def is_last_month_day(date): _, last_day = calendar.monthrange(date.year, date.month) return date.day == last_day def is_first_year_day(date): return date.day == 1 and date.month == 1 def is_last_year_day(date): return date.month == 12 and is_last_month_day(date) short_month = lambda d: format_date(d, pgettext('month-format', 'yyyy/MM')) short_day = lambda d: format_date(d, pgettext('day-format', 'yyyy/MM/dd')) @front.app_template_global() @front.app_template_filter() def daterange(value): '''Display a date range in the shorter possible maner.''' if not isinstance(value, db.DateRange): raise ValueError('daterange only accept db.DateRange as parameter') delta = value.end - value.start start, end = None, None if is_first_year_day(value.start) and is_last_year_day(value.end): start = value.start.year if delta.days > 365: end = value.end.year
return date.day == 1 def is_last_month_day(date): _, last_day = calendar.monthrange(date.year, date.month) return date.day == last_day def is_first_year_day(date): return date.day == 1 and date.month == 1 def is_last_year_day(date): return date.month == 12 and is_last_month_day(date) short_month = lambda d: format_date(d, pgettext('month-format', 'yyyy/MM')) short_day = lambda d: format_date(d, pgettext('day-format', 'yyyy/MM/dd')) @front.app_template_global() @front.app_template_filter() def daterange(value): '''Display a date range in the shorter possible maner.''' if not isinstance(value, db.DateRange): raise ValueError('daterange only accept db.DateRange as parameter') delta = value.end - value.start start, end = None, None if is_first_year_day(value.start) and is_last_year_day(value.end): start = value.start.year if delta.days > 365: end = value.end.year