-
Notifications
You must be signed in to change notification settings - Fork 527
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
question: defining a Vec<DateTime> with mixed timezones #822
Comments
Interesting question @WhyNotHugo - it may take a bit of back and forth to settle on a good design for this, however that may be useful to inform a potential redesign/simplification of the From my current understanding of this, I think using an From what I can understand, it would be useful if we made the following changes (I'm not sure whether all are feasible, but they can be investigated):
|
I'll use an
I think making it object safe would be very useful indeed. At a glance, it seems doable, if the next item can be done too.
I think this is doable. chrono_tz uses its own custom |
I've done some exploration around possible changes to |
Yeah, it seems like using |
@pitdicker did some change related to this recently get merged?
|
@WhyNotHugo Sorry, I did not read closely enough, and thought this was solved.
For most uses converting all values to I think changing For now it comes down to an enum or trait object. The enum option is not acceptable in your case? enum dates {
utc: DateTime<Utc>,
local: DateTime<Local>,
custom: DateTime<MyTimeZone>,
} You already found #432. |
Had a number of months to think about this, and closing again. As written in the previous post we have basically two options:
1. Make the
|
On second thought: We could potentially let some pub struct DateTime<Off: Offset> { /* ... */ }
pub trait Offset: Clone + Debug {
/// Recreate the offset given a `NaiveDateTime` in UTC.
fn update_for_utc_datetime(&mut self) -> Result<(), Error>;
/// Create the offset given a `NaiveDateTime` in local time.
/// Not available when used as a trait object.
fn from_local_datetime() -> LocalResult<Self> where Self: Sized;
/// Recreate the offset given a `NaiveDateTime` in local time.
/// Returns the first result if the local time is ambiguous.
fn update_for_local_datetime_first(&mut self) -> LocalResult<()>;
/// Recreate the offset given a `NaiveDateTime` in local time.
/// Returns the last result if the local time is ambiguous.
fn update_for_local_datetime_last() -> Result<Self>;
/// Convert this offset to a FixedOffset.
fn fix(&self) -> FixedOffset;
} |
I need to define a field for one of my types with a collection/list of datetimes which have different timezone types. E.g.: I need something like:
And I need to be able to insert
DateTime<Utc>
,DateTime<Local>
, and otherchrono::offset::TimeZone
implementations.So far, I've tried using
Box<dyn ...>
, but this won't compile since the size is not known at compile time.Is this even possible with the current API? I'm finding the fact that
DateTime
instances are parametrised with theirTimeZone
a bit tricky to work with. I've seen an approach of using anenum
that implementsTimeZone
and each enum variant delegates to is associated type -- but this requires my code to implement an enum variant for any potentialTimeZone
implementation that might be used. This produces an artificial limitation in library code that applications can't use their ownTimeZone
.Fox context: I'm parsing icalendar objects, and some fields (like recurrence dates of events) can have multiple date-times in various timezones. This includes Utc, Local (a.k.a. "floating") and timezones encoded into the file which I'll need to decode as a custom
TimeZone
impementation.Related: fmeringdal/rust-rrule#85
The text was updated successfully, but these errors were encountered: