Functional Weave
Code in TypeScript

time.minutes-between@1.0.0

impl/python.py

989 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_add_days import epoch_day_from_iso  ← from dates.add-days ^1.0.0 · built alongside by fune


def _minute_of_day(time: str) -> int:
    ok = (
        isinstance(time, str)
        and len(time) == 5
        and time[2] == ":"
        and all("0" <= time[i] <= "9" for i in (0, 1, 3, 4))
    )
    hours = int(time[0:2]) if ok else -1
    minutes = int(time[3:5]) if ok else -1
    if not ok or hours > 23 or minutes > 59:
        raise ValueError('"%s" is not a time of day (HH:MM, 00:00 to 23:59)' % (time,))
    return hours * 60 + minutes


def minutes_between(start_date: str, start_time: str, end_date: str, end_time: str) -> int:
    """Minutes from one local date and time to another: the difference between
    two wall-clock readings. It knows nothing of time zones or daylight saving,
    so across a clock change it differs from real elapsed time by the change.
    """
    days = epoch_day_from_iso(end_date) - epoch_day_from_iso(start_date)
    return days * 1440 + _minute_of_day(end_time) - _minute_of_day(start_time)