What is the idiomatic way to get the duration between now and the next midnight?
I have a function like this:
extern crate chrono;
use chrono::prelude::*;
use time;
fn duration_until_next_midnight() -> time::Duration {
let now = Local::now(); // Fri Dec 08 2017 23:00:00 GMT-0300 (-03)
// ... how to continue??
}
It should make a Duration
with 1 hour, since the next midnight is Sat Dec 09 2017 00:00:00 GMT-0300 (-03)
After scouring the docs, I finally found the missing link:
Date::and_hms
.So, actually, it's as easy as:
The idea is simple:
DateTime
to tomorrow,Date
part, which keeps the timezone,DateTime
by specifying a "00:00:00"Time
withand_hms
.There's a
panic!
inand_hms
, so one has to be careful to specify a correct time.