Skip to content
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

Respect length in zone fieldsets #6029

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

robertbastian
Copy link
Member

Z, V, and O are all capable of formatting multiple lengths, but currently always format long. This adds the relevant constructors and integrates with the fieldset builder.

I've also replaced with_zone_specific_long() et al by a with_zone(impl ZoneMarkers), as otherwise the API would have exploded:

fieldsets::T::medium().with_zone(Z::short());
fieldsets::YMDT::long().with_zone(V::long());
fieldsets::YMDT::long().with_zone(Vs::short()); // only has a short constructor
fieldsets::YMDT::long().with_zone(L::new()); // only has a single length

@Manishearth Manishearth removed request for a team, zbraniecki and Manishearth January 23, 2025 17:18
Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine, but I believe @sffc bounced back and forth on some designes around this, so I'll let him decide

@sffc
Copy link
Member

sffc commented Jan 23, 2025

Issue: this looks like it basically undoes much of what I implemented in #5936, which was the result of multiple tradeoffs and I believe landed at the best overall design. I would have really appreciated a discussion about this before you went and implemented a change to it.

ffi/dart/test/icu_test.dart Outdated Show resolved Hide resolved
@robertbastian
Copy link
Member Author

It looks like there was also no discussion on #5936, you just went ahead and implemented something.

You added the short data to the Z and V fieldsets, but it's currently inaccessible. This makes it accessible.

@robertbastian robertbastian requested a review from sffc January 23, 2025 17:35
pub fn with_zone_location(self) -> Combo<Self, L> {
Combo::new(self, L::new())
/// Associates this field set with a time zone format.
pub fn with_zone<Z: ZoneMarkers>(self, zone: Z) -> Combo<Self, Z> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: This new signature for with_zone is nice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One concern I thought of with regard to this signature. Currently, users do not typically need to ever write out the Z, Vs, or other time zone field set types. This new signature requires that they do this. With the old signature, user code ends up being the comparatively more readable with_zone_specific as opposed to with_zone(Zs::short()).

@@ -833,11 +795,9 @@ macro_rules! impl_zone_marker {
// A plain language description of the field set for documentation.
description = $description:literal,
// Length of the skeleton if this is the only field.
length_override = $length_override:ident,
$(sample_length = $sample_length:ident,)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Adding back sample_length here means that the field set gains a length field, which is the same length field as is used by other fields. Month and Time Zone Name lengths should be independently settable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these macros are way too complex. this works

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this doesn't work. The presence of sample_length causes the length field to be added. The length field should be inoperable for time zone field sets if the length derives from the type, as it has done since I landed my change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this PR is adding the length field to time zone field sets.

// TODO: Add short/long UTC offset?
impl_marker_length_constructors!(O,);
impl O {
pub(crate) fn to_field(self) -> (fields::TimeZone, fields::FieldLength) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: to_field can be done in the macro. Previously I wrote it as a switch statement between long and non-long, with the two results being arguments to the macro.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see a way to do this. Zs, Vs, Z, V, and O have clear mappings between the Length and the FieldLength, but L and X don't have a Length and produce different field length. This code is very easy to understand, wrapping it in multiple macros would not be.

@sffc
Copy link
Member

sffc commented Jan 23, 2025

You added the short data to the Z and V fieldsets, but it's currently inaccessible. This makes it accessible.

I noticed this yesterday and it is a bug. Z previously contained short data and it was reachable through code similar to what is in this PR, but that code is gone, and short data should be removed from Z.

@sffc
Copy link
Member

sffc commented Jan 23, 2025

It looks like there was also no discussion on #5936, you just went ahead and implemented something.

I could have left more breadcrumbs about why I landed on that design, but asking on that PR why I did things a certain way, even after the PR landed, would have been a good thing to do.

@robertbastian robertbastian requested a review from sffc January 23, 2025 17:58
@robertbastian
Copy link
Member Author

short data should be removed from Z.

Says you. How I remember the design that was discussed was that Z and V support both lengths (like all other field sets support all lengths), and Zs and Vs were escape hatches to avoid including long data.

@@ -833,11 +795,9 @@ macro_rules! impl_zone_marker {
// A plain language description of the field set for documentation.
description = $description:literal,
// Length of the skeleton if this is the only field.
length_override = $length_override:ident,
$(sample_length = $sample_length:ident,)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this doesn't work. The presence of sample_length causes the length field to be added. The length field should be inoperable for time zone field sets if the length derives from the type, as it has done since I landed my change.

@sffc
Copy link
Member

sffc commented Jan 23, 2025

short data should be removed from Z.

Says you. How I remember the design that was discussed was that Z and V support both lengths (like all other field sets support all lengths), and Zs and Vs were escape hatches to avoid including long data.

Yes, and I altered that design in #5936, while you were away. I'm happy to reopen that discussion if there was something wrong with the decision I made, but it's awkward to do it on a PR that basically reverts #5936.

#5936 should have removed the short data and it is a bug that it didn't.

@sffc
Copy link
Member

sffc commented Jan 24, 2025

It's not ideal that this PR was opened at this time since I am currently making large-ish changes to some of these files (especially builder.rs and in icu_capi) to update the datetime FFI. I intend to continue with those changes even though it will cause a merge conflict.

In the future, we should discuss large/disruptive changes before we spend time on them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants