-
-
Notifications
You must be signed in to change notification settings - Fork 716
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
Replace chrono
with time
#1307
Replace chrono
with time
#1307
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thank you!
Can you re-add the re-export or make the case against it on the ticket? I commented there?
Also can you add your contribution on CHANGELOG.md. Don't forget to put your github username.
Make sure to highlight the breaking changes:
chrono -> time
timestamp -> unix_timestamp
<---- I'm not sure that one is useful tbh.
Codecov Report
@@ Coverage Diff @@
## main #1307 +/- ##
==========================================
- Coverage 94.25% 94.22% -0.03%
==========================================
Files 232 232
Lines 40801 40856 +55
==========================================
+ Hits 38457 38498 +41
- Misses 2344 2358 +14
Continue to review full report at Codecov.
|
c8718ce
to
431a901
Compare
I decided against introducing a type alias |
@fulmicoton I am still unsure if it would be better to use |
I am convinced that storing For convenience Please verify: 304013f |
Haha, I noticed that yesterday before going to sleep |
Converted to draft because there are still some API inconsistencies that need to be resolved. Moreover all time zone conversions should be explicit, not implicit. |
@uklotzde Understood! Please let me know when I should resume the review. |
@fulmicoton Done. Please see the commit messages for a summary of the changes. I would also like to drop the convenient but lossy |
A simple extension of the |
More and more I come to the conclusion that using a dedicated newtype with conversion functions would be the correct approach. Using |
Including conversions from/to OffsetDateTime and PrimitiveDateTime.
Phew, that escalated quickly. Fortunately, introducing the newtype revealed how scattered the conversion logic was. All conversions are now implemented by dedicated functions of |
Ready again. Hopefully I didn't mess anything up. Especially the |
/// functions and not by implementing any `From`/`Into` traits | ||
/// to prevent unintended usage. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct DateTime { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a nicer implem of Debug showing Rfc3339?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the timestamp 2019-10-12T05:20:50.52Z
or like DateTime { 2019-10-12T05:20:50.52Z }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the date is ok I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation of the DateTime
wrapper now mentions the internal UTC representation, because that leaks not only for debugging but also when serializing as a JSON value.
I have noticed that the query parser is not tested with explicit time zone offsets, only with UTC? But that's unrelated and a different task.
I agree with your change (introducing a DateTime object)... Chrono was nice for this. |
Nevertheless using the |
Thank you @uklotzde for the very solid work. |
@fulmicoton Please double check once again that I didn't miss anything. Especially, if the explicit truncation to seconds inside the newtype is viable and doesn't break existing use cases. Formerly this truncation code was scattered at various places. I am still not completely familiar with when and how values are transformed and stored. |
It should be ok @uklotzde |
For date values `chrono` has been replaced with `time` - The `time` crate is re-exported as `tantivy::time` instead of `tantivy::chrono`. - The type alias `tantivy::DateTime` has been removed. - `Value::Date` wraps `time::PrimitiveDateTime` without time zone information. - Internally date/time values are stored as seconds since UNIX epoch in UTC. - Converting a `time::OffsetDateTime` to `Value::Date` implicitly converts the value into UTC. If this is not desired do the time zone conversion yourself and use `time::PrimitiveDateTime` directly instead. Closes #1304
Fixes #1304.
BREAKING API CHANGE: The type
DateTime
is no longer (re-)exported. Instead you need to usetime::OffsetDateTime
explicitly.Remarks:
time
returns results instead of panicking likechrono
does. For theFastValue
impl I had to use `.expect("valid UNIX timestamp").TODO: