mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-20 05:54:32 +01:00
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file length / file-length (push) Has been cancelled
freedays pre-commit / pre-commit (push) Has been cancelled
freedays tests / test (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
palette drift / palette (push) Has been cancelled
shared gate tests / gate unit tests (push) Has been cancelled
ts_core tests / test (push) Has been cancelled
web_ui tests / test (push) Has been cancelled
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
"""The weekly workdays: Tuesday, Wednesday and Thursday.
|
|
|
|
The one definition every gate app reads, so "which days are workdays" cannot
|
|
drift between them. Consumers each give it their own meaning: screen-locker
|
|
relaxes the lock, leetcode-guard charges the cheap price, wake-alarm's ramp
|
|
holds the wake time instead of stepping it earlier, and a missed workday
|
|
morning costs tomorrow its leniency.
|
|
|
|
Languages that cannot import this package (the Dart and Kotlin sides of the
|
|
phone apps) keep a literal copy and a test that fails when it drifts from
|
|
this one.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Final
|
|
|
|
from freedays._day import today
|
|
|
|
if TYPE_CHECKING:
|
|
from datetime import date
|
|
|
|
#: Python ``date.weekday()`` numbering: Mon=0 ... Sun=6.
|
|
WORKDAYS: Final[frozenset[int]] = frozenset({1, 2, 3})
|
|
|
|
#: The complement: Monday, Friday, Saturday and Sunday.
|
|
NON_WORKDAYS: Final[frozenset[int]] = frozenset(range(7)) - WORKDAYS
|
|
|
|
|
|
def is_workday(day: date | None = None) -> bool:
|
|
"""Return whether *day* (default: today, local) is a weekly workday.
|
|
|
|
Args:
|
|
day: The date to classify; ``None`` means today.
|
|
|
|
Returns:
|
|
True on Tuesday, Wednesday and Thursday.
|
|
"""
|
|
return today(day).weekday() in WORKDAYS
|