예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
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
예제 #4
0
파일: helpers.py 프로젝트: odtvince/udata
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
예제 #5
0
 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'))
예제 #6
0
def short_day(date):
    return format_date(date, pgettext('day-format', 'yyyy/MM/dd'))
예제 #7
0
def short_month(date):
    return format_date(date, pgettext('month-format', 'yyyy/MM'))
예제 #8
0
def isodate(value, format='short'):
    dt = date(*map(int, value.split('-')))
    return format_date(dt, format)
예제 #9
0
 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')))
예제 #10
0

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
예제 #11
0
파일: helpers.py 프로젝트: odtvince/udata
def short_day(date):
    return format_date(date, pgettext('day-format', 'yyyy/MM/dd'))
예제 #12
0
파일: helpers.py 프로젝트: odtvince/udata
def short_month(date):
    return format_date(date, pgettext('month-format', 'yyyy/MM'))
예제 #13
0
파일: helpers.py 프로젝트: odtvince/udata
def isodate(value, format='short'):
    dt = date(*map(int, value.split('-')))
    return format_date(dt, format)
예제 #14
0
파일: helpers.py 프로젝트: guillo-w/udata
    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