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

add a timestamp() method to datetime.date class #103072

Closed
ZeeD opened this issue Mar 28, 2023 · 1 comment
Closed

add a timestamp() method to datetime.date class #103072

ZeeD opened this issue Mar 28, 2023 · 1 comment
Labels
extension-modules C modules in the Modules dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ZeeD
Copy link

ZeeD commented Mar 28, 2023

Feature or enhancement

Extend the datetime.date class with a new method timestamp() that mimic the same behavior of datetime.datetime.timestamp, where the time is implicitly "00:00".

Pitch

At the moment both datetime.datetime and datetime.date offers the fromtimestamp() classmethod to convert from float.
datetime.datetime objects, moreover, offer the timestamp() method to convert to float.
A similar method lacks for datetime.date.

Apart from the (lack of) symmetry, there are also some use cases where it's necessary to switch back-and-forth between datetime.dates and floats and it would be handy to have some predefined function already.

Previous discussion

https://discuss.python.org/t/a-timestamp-method-for-date-objects/13340

Linked PRs

@ZeeD ZeeD added the type-feature A feature request or enhancement label Mar 28, 2023
@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label Mar 28, 2023
@picnixz picnixz added the extension-modules C modules in the Modules dir label Mar 14, 2025
@pganssle
Copy link
Member

I'm pretty strongly -1 on this, the semantics are way wonky for multiple reasons. Dates don't have time stamps because they don't have to times. date specifically doesn't have a time zone, and so there would be no way to specify what 00:00 you are referring to; many people will think it is UTC, but to be consistent with the only other method where date is not abstract, we would want it to represent that time in the local system zone.

Normally I would leave this open for further discussion, but it seems like there was a decently long discussion on discourse that was leaning largely negative anyway, and I'm finding that I forget about these things, they stay open, then they attract PRs from well meaning people, so I will close this until there is a compelling reason to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
Development

No branches or pull requests

4 participants