You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){let date = chrono::NaiveDate::from_ymd_opt(2064,11,2).unwrap();let tz = chrono_tz::Tz::America__Havana;println!("{:?}",midnight_on(date, tz));}
with the error
thread 'main' panicked at 'Ambiguous local time, ranging from 2064-11-02T00:00:00CDT to 2064-11-02T00:00:00CST', /home/ekleog/.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.23/src/offset/mod.rs:189:17
Waiting until #883 makes it in, the best bet I currently found as a workaround is to extract the implementation from there:
pubfnmidnight_on<Tz>(date: chrono::NaiveDate,tz:&Tz) -> chrono::DateTime<Tz>whereTz:Clone + std::fmt::Debug + chrono::TimeZone,{let base = chrono::NaiveTime::MIN;for multiple in0..=24{let start_time = base + chrono::Duration::minutes(multiple *15);match date.and_time(start_time).and_local_timezone(tz.clone()){
chrono::LocalResult::None => continue,
chrono::LocalResult::Single(dt) => return dt,
chrono::LocalResult::Ambiguous(dt1, dt2) => {if dt1.naive_utc() < dt2.naive_utc(){return dt1;}else{return dt2;}}}}panic!("Unable to calculate start time for date {} and time zone {:?}",
date, tz
)}
The text was updated successfully, but these errors were encountered:
In my opinion the problem is that we have no way to resolve a local time that falls inside a timezone transition gap (with LocalResult::None as result) to something useful. Fixing this requires a breaking change to LocalResult.
This issue is for documentation, and would be fixed by #883.
It is currently hard to convert from NaiveDate to DateTime, due to timezone shifts possibly occurring. The following code seems reasonable:
but fails when passed for instance:
with the error
Waiting until #883 makes it in, the best bet I currently found as a workaround is to extract the implementation from there:
The text was updated successfully, but these errors were encountered: