-
Notifications
You must be signed in to change notification settings - Fork 214
DateTimeNames: Support loading of AnyCalendar names #6107
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
Comments
I'm not sure if this is the right issue. My use case is a binding for a scripting language, where I want to add the possibility to specify patterns. For the "regular" formatting, I take a date specification, a locale, and a A bit related to this: It would be great if one could check which parts of a zoned datetime are actually required for a pattern. Because |
For now, I'm working with CLDR to refine the official string representation, which we hope to leverage in MF2. See e.g. unicode-org/message-format-wg#1067 |
Also, forgot to mention this, but thank you for the feedback on 2.0 Beta! This is really helpful to make sure 2.0 serves the needs of clients.
So, the way this is designed, the TimeZoneInfo only needs the fields that are required by the time zone style being formatted, assuming that you are using static field sets. If you are using If you know for sure that you are only ever displaying a TimeZone with an offset, but you want runtime selection of the date fields, you can use On the main branch, new since 2.0-beta2, I added a |
Sorry for the late response.
Thank you, this does fit my needs for the For the date time pattern formatting, I should've made my question a bit clearer (and I don't know if that's the right way to use the API). fn format_ideal(pattern_str: &str, locale: &str, zdt: &ZonedDateTime<Iso, TimeZoneInfo<Full>>) {
let prefs = Locale::from_str(locale).unwrap().into(); // potentially includes -u-ca-
let pattern = DateTimePattern::try_from_pattern_str(pattern_str).unwrap();
let mut names = AnyCalendarDateTimeNames::try_new(prefs).unwrap();
let _ = names.include_for_pattern(&pattern).unwrap().format(zdt);
// ...
} Not sure if this would require a new |
Yeah, that use case would be served with adding functions onto DateTimeNames. You found the right issue for that. Always worth verifying, though: are you sure you want DateTimeNames? Where do you get your patterns from? |
The patterns are from users who (should) know the formatting rules for the specific locale. |
Currently we only support names-loading in
TypedDateTimeNames
(which should be renamed toFixedCalendarDateTimeNames
). We could also add the AnyCalendar variant of this.For example, we could add
DateTimeNames::load_month_names
.If you need this feature, please reply here to explain your use case.
The text was updated successfully, but these errors were encountered: