-
Notifications
You must be signed in to change notification settings - Fork 161
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
Create TimeZoneFormatConfig enum #1256
Conversation
This looks great so far, and just the kind of enum we want for this. As part of this same PR, we will want to also create a new constructor for For now I'm going to convert this PR to a draft PR and remove the other reviewers. |
So there are still a couple things left to do for this PR.
|
Sure, I will do both in this PR. But I have some questions:
|
The goal of this PR is to make
We are not differentiating between The reason that we only have one function called Rather than let developers arbitrarily choose between long or short GMT format, it seems like a better decision to always use the localized form that is specified by the locale. So in ICU4X, both
I went back and revisited my reasoning for not including
I appreciate you calling this out. I thought that I had made |
Thanks Eric! I took a closer look at the code again. I found that
It feels like I need to create a mapping from pattern in |
For now, this is why we're creating two constructors: the pre-existing For this PR, it would be fine to keep the It would be great if we could find a way to consolidate and eventually remove This is what I meant when I said:
But after thinking about it further, since we're not including the For now, I think the best option would be to keep |
Sounds good! |
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.
Looking great so far!
There are just a couple changes to make in the review comments, and we also need to add tests for this new functionality before we can land this.
I'm happy to sync up on a call about testing and walk you through how our test suites work in more detail if that would be helpful.
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.
Looks really great @samchen61661!
Just a few minor changes, and I'll also add Shane back on as a reviewer.
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.
Just a couple small things I missed on the first pass, otherwise this looks really great to me!
I'll leave it to Shane to lend a second pair of eyes before we land this.
Really excited to make this public!
Thanks for your guidance Eric! I learnt a lot from you these days! I did not expect that it touched so many files eventually and I felt that I am more comfortable to read and write Rust code. And I am very happy to make |
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.
Thanks so much for working on this. This looks good to me.
Technically it's missing some documentation comments, such as on the newly added function TimeZoneFormat::try_from_config()
, but once this lands I'm planning to go through and read all the docs/update them/add anything that's missing, so I'm comfortable landing this as is with docs as a follow-up.
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.
Looks good overall. I found some small areas for improvement. We'll probably need to add more configs to this enum in the future, but now we have a straightforward place to add them.
For example:
https://tc39.es/proposal-intl-extend-timezonename/#sec-basicformatmatcher
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 looks good. Just one small nitpick from me.
Good call on removing those expect
calls @sffc.
} | ||
(None, None) => unreachable!( | ||
"TimeZoneFormat should have either a configuration or a pattern, but found neither" | ||
), |
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.
By your same logic about the expect
potentially adding unwanted panic machinery, should we remove the unreachable!()
calls here and return an error instead?
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.
I'm not quite as concerned about a plain unreachable!()
because it's more self-contained; .expect()
pulls in the formatting machinery since it prints a formatted message*. If we build with panic_abort
, then any unreachable!()
should basically compile away.
That being said, if you want to avoid the unreachable code path, you can use an internal exhaustive enum such as
enum TimeZoneFormatKind {
Config(TimeZoneFormatConfig),
Pattern(DataPayload<'data, PatternPluralsFromPatternsV1Marker>),
}
This would likely be a good cleanup to your code regardless.
* It actually appears that the fmt::Debug bound gets pulled in for Result but maybe not Option
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.
I'm re-opening this thread because I think switching to use an enum may be a beneficial change for @samchen61661 to consider.
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.
Yeah, it is a good suggestion. I am not familiar with the open source policy. What do you think to improve it in a separate PR?
The main concern here is that this PR is big and the fix is relatively small.
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.
Got it.
When you said "This would likely be a good cleanup to your code regardless." I thought you meant as a follow-up.
Happy to add it in here to as I agree that it is a good change.
@samchen61661 you can go ahead and add it to this PR.
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.
I'm fine landing this as-is and doing this refactor in a small follow-up PR. But since you still need to resolve the merge conflict in this PR, it seems to make sense to fix this while you're at it.
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.
I see. sg and I will refactor it in this PR.
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.
Shane, when you talked about you can use an INTERNAL exhaustive enum
, are you saying that I just need to use TimeZoneFormatKind
in the write_zone
method?
I think we can make TimeZoneFormatKind
as an external attribute in TimeZoneFormat
to replace config
and patterns
.
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.
What we would need to do is:
pub(super) TimeZoneFormatKind<'data> {
...
}
The enum should only be internal (i.e. pub(super)
) because users of the public API shouldn't have to worry about this type.
And then instead of having data members for config
and patterns
, you would just have one data member kind
that is a TimeZoneFormatKind
.
pub struct TimeZoneFormat<'data> {
+ pub(super) kind: TimeZoneFormatKind<'data>,
- pub(super) config: ...
- pub(super) patterns: ...
...
}
Note that the enum TimeZoneFormatKind
will need to have a lifetime specifier since it holds the DataPayload
for the pattern 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 looks good to me, just pending my one question to Shane regarding the panic handling:
#1256 (comment)
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.
Looks good to me!
Thanks for being willing to make all of these small changes over several iterations.
I think the code is overall cleaner because of it.
e6a8b3b
to
aba20ed
Compare
Notice: the branch changed across the force-push!
~ Your Friendly Jira-GitHub PR Checker Bot |
Create TimeZoneFormatConfig enum for #622