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 Default implementation for naive date types #506

Merged
merged 7 commits into from
Jan 22, 2021

Conversation

DiD92
Copy link
Contributor

@DiD92 DiD92 commented Nov 24, 2020

This PR aims to add some Default implementations for some of the naive types. The currently added defaults are the following:

  • Default NaiveDateTime has been set to 1970-01-01 00:00:00
  • Default NaiveDate has been set to 1970-01-01
  • Default NaiveTime has been set to 00:00:00

The main reason for the PR is to help in struct definitions that wish to simply #derive[Default] but currently are not able to because on of their attributes is of the previously mentioned types, adding this change would help simplify the code in that particular scenario.

@quodlibetor
Copy link
Contributor

Sorry for the delay! I agree that this is just kind of annoying to have not-implemented, and just using the unix epoch makes sense as a reasonably-surprising value.

If you're willing to fix the tests and add implementations of this for the non-naive Datetime<Tz> (where it just defaults to the same date/time in the user-requested timezone) I would be happy to merge this!

@quodlibetor quodlibetor self-requested a review December 20, 2020 23:23
@DiD92
Copy link
Contributor Author

DiD92 commented Dec 25, 2020

Hi @quodlibetor , sorry for my late reply, yes I'm more than happy to do that! I'll update the PR once I have the changes.

@DiD92
Copy link
Contributor Author

DiD92 commented Dec 27, 2020

Hi @quodlibetor, the test now pass and I've added Default implementations for DateTime as you requested, if any more changes are needed please feel free to request them.

@@ -1341,6 +1341,20 @@ impl str::FromStr for NaiveTime {
}
}

/// The default for a NaiveTime is midnight, oo:oo:00 exactly.
Copy link
Contributor

Choose a reason for hiding this comment

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

these are the letter o instead of the number 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

///
/// # Example
///
/// ~~~~
Copy link
Contributor

Choose a reason for hiding this comment

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

we recently (in between your submission of this PR and now) swapped all the doctests to use backticks to be more inline with other rust code. If you feel like changing these that'd be appreciated, but your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed the docs from the Default impl to use backticks!

* Fixed typo in NaiveTime docs for Default
@DiD92
Copy link
Contributor Author

DiD92 commented Jan 11, 2021

Hello @quodlibetor hope you had a nice holiday, I simply wanted to know if anything more was required in order to have the PR merge onto master, happy to make any changes if needed!

@quodlibetor quodlibetor merged commit 3467172 into chronotope:main Jan 22, 2021
@quodlibetor
Copy link
Contributor

Thank you!

@DiD92 DiD92 deleted the add-default-impl branch January 22, 2021 22:48
@malthe
Copy link

malthe commented Jan 24, 2021

I think DateTime::now() is a more useful default – and arguably a lot less surprising. If you want an essentially "unset" datetime as the default value, then Option<DateTime> is a better choice.

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.

3 participants