Functional Weave
Code in Python

todo.due-status@1.0.0

impl/python.py

836 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .dates_day_of_week import day_of_week  ← from dates.day-of-week ^1.0.0 · built alongside by fune
from .dates_days_between import days_between  ← from dates.days-between ^1.0.0 · built alongside by fune
from .todo_due_status_types import DueStatus
from .todo_item import Todo  ← from todo.item ^1.0.0 · built alongside by fune


def due_status(todo: Todo, today: str) -> DueStatus:
    """One word for where a todo stands today; done wins, this-week is the rest of the ISO week."""
    # Check the dates first, so a bad date is an error even on a done todo.
    if todo.due is not None:
        days_between(today, todo.due)
    else:
        day_of_week(today)
    if todo.done:
        return "done"
    if todo.due is None:
        return "none"
    days = days_between(today, todo.due)
    if days < 0:
        return "overdue"
    if days == 0:
        return "today"
    if days == 1:
        return "tomorrow"
    if days <= 7 - day_of_week(today):
        return "this-week"
    return "later"