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

Deprecate timestamp methods on NaiveDateTime #1473

Merged
merged 9 commits into from Mar 1, 2024

Conversation

pitdicker
Copy link
Collaborator

As discussed in #1471 a timestamp is defined to be in UTC. The NaiveDateTime type doesn't know the offset from UTC, so is is technically wrong to have these methods. Users should use the similar methods on the DateTime<Utc> type (or the TimeZone trait) instead.

Converting from NaiveDateTime to DateTime<Utc> is simple with .and_utc(), and in the other direction with .naive_utc().


The first commit introduces two extra functions on DateTime<Utc> to get feature parity with NaiveDateTime: from_timestamp_micros and from_timestamp_nanos.

Later commits move over our implementation and tests from NaiveDateTime to DateTime.

Then we avoid using the timestamp methods on NaiveDateTime and deprecate the them.

Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! Let's do a release soon after merging this so we can get some feedback?

src/datetime/mod.rs Show resolved Hide resolved
Copy link

codecov bot commented Feb 29, 2024

Codecov Report

Attention: Patch coverage is 93.92097% with 20 lines in your changes are missing coverage. Please review.

Project coverage is 91.94%. Comparing base (e292d9b) to head (1159dd9).
Report is 4 commits behind head on main.

Files Patch % Lines
src/naive/datetime/mod.rs 17.64% 14 Missing ⚠️
src/datetime/mod.rs 95.08% 3 Missing ⚠️
src/naive/datetime/serde.rs 95.65% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1473      +/-   ##
==========================================
- Coverage   92.16%   91.94%   -0.22%     
==========================================
  Files          40       40              
  Lines       18052    18014      -38     
==========================================
- Hits        16637    16563      -74     
- Misses       1415     1451      +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pitdicker
Copy link
Collaborator Author

Let's do a release soon after merging this so we can get some feedback?

Good idea, I'll start preparing release notes.

Do we want to include #1450, deprecating the panicking constructors of TimeDelta, as well?
In my opinion if we are going to introduce some churn it is better to do it all at once than do it twice a few weeks apart.
It is now five weeks since introducing their fallible alternatives.

@djc
Copy link
Contributor

djc commented Mar 1, 2024

Do we want to include #1450, deprecating the panicking constructors of TimeDelta, as well? In my opinion if we are going to introduce some churn it is better to do it all at once than do it twice a few weeks apart. It is now five weeks since introducing their fallible alternatives.

Yes, that seems okay.

@pitdicker pitdicker merged commit 1d3da21 into chronotope:main Mar 1, 2024
35 checks passed
@pitdicker pitdicker deleted the deprecate_timestamp branch March 1, 2024 10:52
@pitdicker pitdicker mentioned this pull request Mar 9, 2024
iuioiua added a commit to denoland/deno that referenced this pull request Apr 8, 2024
`chrono::NaiveDateTime::from_timestamp_opt()` was deprecated in
chronotope/chrono#1473.

Prerequisite for #23272.
satyarohith pushed a commit to denoland/deno that referenced this pull request Apr 11, 2024
`chrono::NaiveDateTime::from_timestamp_opt()` was deprecated in
chronotope/chrono#1473.

Prerequisite for #23272.
littledivy pushed a commit to littledivy/deno that referenced this pull request Apr 19, 2024
`chrono::NaiveDateTime::from_timestamp_opt()` was deprecated in
chronotope/chrono#1473.

Prerequisite for denoland#23272.
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

Successfully merging this pull request may close these issues.

None yet

2 participants