-
Notifications
You must be signed in to change notification settings - Fork 78
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
Chrono types for Timestamp #41
Conversation
Cargo.toml
Outdated
chrono = { version = "0.4.9", optional = true } | ||
|
||
[dev-dependencies] | ||
chrono = { version = "0.4.9" } |
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.
Why do you always enable the chrono
feature in test by all those any(test, feature = "chrono_timestamp")
? We test with cargo test --all-features
so I guess it's fine to only enable the test when the feature is enabled
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.
chrono = { version = "0.4.9" } |
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.
@durangatan this one and we're ready to merge ;)
@@ -157,7 +201,14 @@ pub enum QueryType { | |||
|
|||
#[cfg(test)] | |||
mod tests { | |||
extern crate chrono; |
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.
This should be feature-gated (see above)
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.
Thanks for this PR! 🎉
For example, Timestamp::Hours(3) probably doesn't mean three hours from the epoch, but for now I kept it consistent.
Sadly, this is exactly the way it is. Time in InfluxDb is UTC and an Unix nanosecond timestamp by default. We can set other precisions (which is done using the Timestamp
enum).
The From implementation creates a Timestamp::Milliseconds from a given date. It will work for any DateTime object that implements TimeZone
It should probably use Timestamp::Nanoseconds
by default, as that's the preferred time resolution from InfluxDb
It would probably also be nice to document the feature gate somewhere, so potential users can find this easily.
Btw, right now you only implement |
I chose UTC because it is a "true unix timestamp".
lmk if I should change the implementation to NaiveDateTime |
I see your point, but for some user who doesn't care about the timezone and interprets the |
Based on the above comments in the thread, I think it's a safe assumption that a user will expect an influxDB timestamp to represent a UTC datetime, not a timezoned time. |
I would say that supporting UTC only is reasonable, as InfluxDb makes that assumption for us and we should strive to behave similar to it. |
not sure how to fix the last bit of the build; looks like kcov is failing but I can't tell which command specifically fails |
From the logs, it looks like cargo-travis is not being run with Since I'm planning on removing coverage in #23 since it's broken and gives inaccurate results I'd be fine with you also removing the cargo-travis step and all references to code coverage (lib.rs badge and Cargo.toml badge) |
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.
Looks good to me! Thanks for contributing this!
Since @msrd0 requested the feature, I'll have him have the last words.
Some small suggestions have been noticed.
Co-Authored-By: Gero Gerke <hello@gerogerke.de>
Co-Authored-By: Gero Gerke <hello@gerogerke.de>
Co-Authored-By: Gero Gerke <hello@gerogerke.de>
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.
Thank you very much for this contribution. 🎉
This will be helpful to everyone working with Chrono in their projects.
Description
Fixes #35.
Into
implementation casts everything to aDateTime<Utc>
with at least millisecond precision. I figure the caller can cast the value to a timezone if needed.Timestamp
s the preferred way in UTC-land, because I'm not super familiar with how influxdb works. For example,Timestamp::Hours(3)
probably doesn't mean three hours from the epoch, but for now I kept it consistent.From<DateTime>
implementation creates aTimestamp::Milliseconds
from a given date. It will work for any DateTime object that implementsTimeZone
.chrono_timestamps
compilation feature.I hope this is sort of what you're looking for; let me know if you want me to take it in a different direction or implement more chrono converters.
Checklist
cargo fmt --all
cargo clippy --all-targets --all-features -- -D warnings
cargo readme > README.md