Ejemplo n.º 1
0
def short_day(date):
    return format_date(date, pgettext('day-format', 'yyyy/MM/dd'))
Ejemplo n.º 2
0
def short_month(date):
    return format_date(date, pgettext('month-format', 'yyyy/MM'))
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def short_day(date):
    return format_date(date, pgettext('day-format', 'yyyy/MM/dd'))
Ejemplo n.º 5
0
def short_month(date):
    return format_date(date, pgettext('month-format', 'yyyy/MM'))
Ejemplo n.º 6
0
    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