Skip to content

Add arithmetic support (add/subtract) to the Time type #375

Description

@Binilkks

Feature Request: Time.add() / Time.subtract() arithmetic

Problem

Every major type in whenever supports arithmetic via add() and subtract()Date, Instant, ZonedDateTime, OffsetDateTime, PlainDateTime — but Time does not.

This makes it awkward to work with time-of-day arithmetic, which is common in scheduling scenarios (store hours, shift times, reminders, etc.).

Expected Behavior

Time(22, 0).add(hours(3))      # → Time(1, 0), wraps past midnight
Time(1, 0).subtract(hours(3))  # → Time(22, 0), wraps before midnight

Arithmetic could wrap around midnight (modular arithmetic), consistent with how most users would expect time-of-day math to work.

Current Workaround

Users currently have to manually handle the math via _to_ns_since_midnight() internals or convert to PlainDateTime first, which is verbose and leaks implementation details.

Suggested Signature

def add(self, delta: TimeDelta, /) -> Time: ...
def subtract(self, delta: TimeDelta, /) -> Time: ...

Operator overloads (__add__, __sub__) could also follow the same pattern as other types.

Notes

Python's stdlib datetime.time also skips arithmetic, so this would be a meaningful improvement over the standard library behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscussion is needed before proceedingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions