How to use the fava.util.date.Interval.YEAR function in fava

To help you get started, we’ve selected a few fava examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beancount / fava / fava / template_filters.py View on Github external
def format_date(date):
    """Format a date according to the current interval."""
    if g.interval is Interval.YEAR:
        return date.strftime("%Y")
    if g.interval is Interval.QUARTER:
        return "{}Q{}".format(date.year, (date.month - 1) // 3 + 1)
    if g.interval is Interval.MONTH:
        return date.strftime("%b %Y")
    if g.interval is Interval.WEEK:
        return date.strftime("%YW%W")
    if g.interval is Interval.DAY:
        return date.strftime("%Y-%m-%d")
    return ""
github beancount / fava / tests / test_util_date.py View on Github external
        (Interval.YEAR, "2015-02-01", 365),
        (Interval.YEAR, "2016-01-01", 366),
    ],
)
def test_number_of_days_in_period(interval, date_str, expect):
    assert number_of_days_in_period(interval, _to_date(date_str)) == expect
github beancount / fava / fava / util / date.py View on Github external
# pylint: disable=too-many-return-statements
    string = string.strip().lower()
    if not string:
        return None, None

    string = substitute(string, fye).lower()

    match = IS_RANGE_RE.match(string)
    if match:
        return (parse_date(match.group(1))[0], parse_date(match.group(2))[1])

    match = YEAR_RE.match(string)
    if match:
        year = int(match.group(0))
        start = datetime.date(year, 1, 1)
        return start, get_next_interval(start, Interval.YEAR)

    match = MONTH_RE.match(string)
    if match:
        year, month = map(int, match.group(1, 2))
        start = datetime.date(year, month, 1)
        return start, get_next_interval(start, Interval.MONTH)

    match = DAY_RE.match(string)
    if match:
        year, month, day = map(int, match.group(1, 2, 3))
        start = datetime.date(year, month, day)
        return start, get_next_interval(start, Interval.DAY)

    match = WEEK_RE.match(string)
    if match:
        year, week = map(int, match.group(1, 2))
github beancount / fava / fava / core / budgets.py View on Github external
Returns:
        A dict of accounts to lists of budgets.

    Example:
        2015-04-09 custom "budget" Expenses:Books "monthly" 20.00 EUR
    """

    budgets = defaultdict(list)
    errors = []

    interval_map = {
        "daily": Interval.DAY,
        "weekly": Interval.WEEK,
        "monthly": Interval.MONTH,
        "quarterly": Interval.QUARTER,
        "yearly": Interval.YEAR,
    }

    for entry in custom_entries:
        if entry.type == "budget":
            try:
                interval = interval_map.get(str(entry.values[1].value))
                if not interval:
                    errors.append(
                        BudgetError(
                            entry.meta,
                            "Invalid interval for budget entry",
                            entry,
                        )
                    )
                    continue
                budget = Budget(
github beancount / fava / fava / util / date.py View on Github external
def label(self):
        """The label for the interval."""
        return {
            Interval.YEAR: gettext("Yearly"),
            Interval.QUARTER: gettext("Quarterly"),
            Interval.MONTH: gettext("Monthly"),
            Interval.WEEK: gettext("Weekly"),
            Interval.DAY: gettext("Daily"),
        }.get(self)
github beancount / fava / fava / util / date.py View on Github external
"""

    if interval is Interval.DAY:
        return 1
    if interval is Interval.WEEK:
        return 7
    if interval is Interval.MONTH:
        date = datetime.date(date.year, date.month, 1)
        return (get_next_interval(date, Interval.MONTH) - date).days
    if interval is Interval.QUARTER:
        quarter = (date.month - 1) / 3 + 1
        date = datetime.date(date.year, int(quarter) * 3 - 2, 1)
        return (get_next_interval(date, Interval.QUARTER) - date).days
    if interval is Interval.YEAR:
        date = datetime.date(date.year, 1, 1)
        return (get_next_interval(date, Interval.YEAR) - date).days
    raise NotImplementedError