Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opposite of Timestamp.to_seconds #69

Open
amadanmath opened this issue Jul 23, 2024 · 0 comments
Open

Opposite of Timestamp.to_seconds #69

amadanmath opened this issue Jul 23, 2024 · 0 comments

Comments

@amadanmath
Copy link

amadanmath commented Jul 23, 2024

Timestamp.to_seconds is there to convert the timestamp into seconds. It might be helpful if there was also the opposite method, to build a timestamp from seconds — for example, when you need to do some artihmetic on timestamps, like shift the timings. Maybe something like

@classmethod
def from_seconds(cls, secs):
    hours, secs = divmod(secs, 3600)
    mins, secs = divmod(secs, 60)
    secs, msecs = divmod(secs, 1)
    return cls(hours, mins, secs, msecs)

EDIT: Also, is there a reason why milliseconds are left out of to_seconds? timedelta.total_seconds returns sub-second precision. It is easy enough to round when one needs integral seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant