Example #1
0
def format_day(day, format_string, locale, attributes=None):
    if attributes is None:
        attributes = {}

    attributes["date"] = day.strftime(locale['dateformat'])
    attributes["date-long"] = day.strftime(locale['longdateformat'])

    attributes["name"] = utils.construct_daynames(day)

    colors = {"reset": style("", reset=True), "bold": style("", bold=True, reset=False)}
    for c in ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]:
        colors[c] = style("", reset=False, fg=c)
        colors[c + "-bold"] = style("", reset=False, fg=c, bold=True)
    attributes.update(colors)
    try:
        return format_string.format(**attributes) + colors["reset"]
    except (KeyError, IndexError):
        raise KeyError("cannot format day with: %s" % format_string)
Example #2
0
def format_day(day, format_string, locale, attributes=None):
    if attributes is None:
        attributes = {}

    attributes["date"] = day.strftime(locale['dateformat'])
    attributes["date-long"] = day.strftime(locale['longdateformat'])

    attributes["name"] = utils.construct_daynames(day)

    colors = {"reset": style("", reset=True), "bold": style("", bold=True, reset=False)}
    for c in ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]:
        colors[c] = style("", reset=False, fg=c)
        colors[c + "-bold"] = style("", reset=False, fg=c, bold=True)
    attributes.update(colors)
    try:
        return format_string.format(**attributes) + colors["reset"]
    except (KeyError, IndexError):
        raise KeyError("cannot format day with: %s" % format_string)
Example #3
0
def test_construct_daynames():
    with freeze_time('2016-9-19'):
        assert construct_daynames(date(2016, 9, 19)) == 'Today'
        assert construct_daynames(date(2016, 9, 20)) == 'Tomorrow'
        assert construct_daynames(date(2016, 9, 21)) == 'Wednesday'
Example #4
0
def test_construct_daynames():
    with freeze_time('2016-9-19'):
        assert construct_daynames(date(2016, 9, 19)) == 'Today'
        assert construct_daynames(date(2016, 9, 20)) == 'Tomorrow'
        assert construct_daynames(date(2016, 9, 21)) == 'Wednesday'