loop {
{
let now = time::now();
let mut fiveam = now + Duration::hours(24);
fiveam.tm_utcoff = now.tm_utcoff;
fiveam.tm_hour = 5;
fiveam.tm_min = rand::random::<i32>() % 60;
let duration = fiveam - now;
info!("Next backup time: {} -> {}, {} minutes to go",
now.ctime(), fiveam.ctime(), duration.num_minutes());
thread::sleep_ms(duration.num_milliseconds() as u32);
}
// do some daily job here
}
log of first loop:
INFO:mybackup: Next backup time: Fri Apr 10 13:25:54 2015 -> Sat Apr 11 05:37:54 2015, 972 minutes to go
log of second loop:
INFO:mybackup: Next backup time: Sat Apr 11 07:43:39 2015 -> Sat Apr 11 05:59:39 2015, -104 minutes to go
In the second loop Tm Sat Apr 11 07:43:39 2015 add 24 hours still in Apr 11. Is this a bug of rust-lang/time?
PS. I run many time, the frist loop always get a expected fiveam time.