-
Notifications
You must be signed in to change notification settings - Fork 246
Infer the zone datetime in FFI when possible #6517
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -518,8 +518,8 @@ pub mod ffi { | |||||||||||||||||||||||||||||||||
| write: &mut diplomat_runtime::DiplomatWrite, | ||||||||||||||||||||||||||||||||||
| ) -> Result<(), DateTimeWriteError> { | ||||||||||||||||||||||||||||||||||
| let mut input = icu_datetime::DateTimeInputUnchecked::default(); | ||||||||||||||||||||||||||||||||||
| let date = date.0.to_calendar(self.0.calendar()); | ||||||||||||||||||||||||||||||||||
| input.set_date_fields_unchecked(date); // calendar conversion on previous line | ||||||||||||||||||||||||||||||||||
| let date_in_calendar = date.0.to_calendar(self.0.calendar()); | ||||||||||||||||||||||||||||||||||
| input.set_date_fields_unchecked(date_in_calendar); // calendar conversion on previous line | ||||||||||||||||||||||||||||||||||
| input.set_time_fields(time.0); | ||||||||||||||||||||||||||||||||||
| input.set_time_zone_id(zone.id); | ||||||||||||||||||||||||||||||||||
| if let Some(offset) = zone.offset { | ||||||||||||||||||||||||||||||||||
|
|
@@ -528,6 +528,12 @@ pub mod ffi { | |||||||||||||||||||||||||||||||||
| if let Some(zone_name_timestamp) = zone.zone_name_timestamp { | ||||||||||||||||||||||||||||||||||
| input.set_time_zone_name_timestamp(zone_name_timestamp); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||
| input.set_time_zone_name_timestamp(icu_time::zone::ZoneNameTimestamp::from_date_time_iso(&icu_time::DateTime { | ||||||||||||||||||||||||||||||||||
| date: date.0, | ||||||||||||||||||||||||||||||||||
| time: time.0 | ||||||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if let Some(variant) = zone.variant { | ||||||||||||||||||||||||||||||||||
| input.set_time_zone_variant(variant); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -1012,8 +1018,8 @@ pub mod ffi { | |||||||||||||||||||||||||||||||||
| write: &mut diplomat_runtime::DiplomatWrite, | ||||||||||||||||||||||||||||||||||
| ) -> Result<(), DateTimeWriteError> { | ||||||||||||||||||||||||||||||||||
| let mut input = icu_datetime::DateTimeInputUnchecked::default(); | ||||||||||||||||||||||||||||||||||
| let date = date.0.to_calendar(Gregorian); | ||||||||||||||||||||||||||||||||||
| input.set_date_fields_unchecked(date); // calendar conversion on previous line | ||||||||||||||||||||||||||||||||||
| let date_in_calendar = date.0.to_calendar(Gregorian); | ||||||||||||||||||||||||||||||||||
| input.set_date_fields_unchecked(date_in_calendar); // calendar conversion on previous line | ||||||||||||||||||||||||||||||||||
| input.set_time_fields(time.0); | ||||||||||||||||||||||||||||||||||
| input.set_time_zone_id(zone.id); | ||||||||||||||||||||||||||||||||||
| if let Some(offset) = zone.offset { | ||||||||||||||||||||||||||||||||||
|
|
@@ -1022,6 +1028,12 @@ pub mod ffi { | |||||||||||||||||||||||||||||||||
| if let Some(zone_name_timestamp) = zone.zone_name_timestamp { | ||||||||||||||||||||||||||||||||||
| input.set_time_zone_name_timestamp(zone_name_timestamp); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||
| input.set_time_zone_name_timestamp(icu_time::zone::ZoneNameTimestamp::from_date_time_iso(&icu_time::DateTime { | ||||||||||||||||||||||||||||||||||
| date: date.0, | ||||||||||||||||||||||||||||||||||
| time: time.0 | ||||||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1031
to
+1036
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Suggested change
|
||||||||||||||||||||||||||||||||||
| if let Some(variant) = zone.variant { | ||||||||||||||||||||||||||||||||||
| input.set_time_zone_variant(variant); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
elseblock is intended to infer the time zone name timestamp when it's not explicitly provided. However, it's unconditionally setting the timestamp based on the date and time. This might not always be the desired behavior. It would be better to check if the timestamp can be inferred from the zone ID before setting it here. Otherwise, the code might be overwriting a valid timestamp with an inferred one.