-
Notifications
You must be signed in to change notification settings - Fork 520
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
Feature request: get absolute duration #810
Comments
Mya, as |
This is likely to be implemented in #714 - see |
The |
@pitdicker can you elaborate? It is still not clear to me how I can get an absolute duration using the current release of Here's a code sample that doesn't compile: use chrono; // 0.4.26
struct EthPrice {
usd: u32,
timestamp: chrono::DateTime<chrono::Utc>
}
fn main() {
let eth_price = EthPrice { usd: 2000, timestamp: chrono::Utc::now() };
let age_limit = chrono::Duration::minutes(10);
let h24_ago = chrono::Utc::now() - chrono::Duration::hours(24);
let secs_between = (h24_ago - eth_price.timestamp).abs();
let is_fresh_enough = chrono::Duration::seconds(secs_between) <= age_limit;
dbg!(is_fresh_enough);
} error:
Perhaps at the very least we can link an issue tracking when "you get the Duration from time 0.1" is no longer the case and this feature is unlocked? If it isn't already and I am simply misunderstanding how to use it. |
It is available if you use chrono with: [dependencies]
chrono = { version = "0.4.26", default-features = false, features = ["clock", "std"] } This is unfortunate, hopefully it 'just works' in the next release when we remove the time 0.1 dependency. See #1095. |
I have a stream of timestamped values, I have a function that tries to retrieve one of those values 24 hours back in time, where the value needs to be within 10 minutes, on either side, of
now - hours_24
. SQL has a great way to get me the row closest to a given point in time, but now I wanted to check on the rust side whether the closest value is actually within our time limit.The code ends up looking like this:
I was already quite happy to find negative
Duration
is perfectly acceptable but I still need to jump through some hoops because it is nice forage_limit
to be aDuration
rather than a number of seconds or something.Now that I write this I'm thinking maybe I should just go through the trouble of writing the
WHERE
in SQL but either way I'll leave this here, perhaps others need it too, and after a couple of 👍 we could consider implementing ((:The text was updated successfully, but these errors were encountered: