-
Notifications
You must be signed in to change notification settings - Fork 183
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
IXDTF parser calendared APIs (was: Consider adding an AnyCalendarFactory) #5739
Comments
Are they short-lived? The intent of the whole AsCalendar infrastructure was to make it easy to have long lived calendars. |
There are lots of cases when you might want a short-lived Actually, perhaps a more efficient approach here would be a type that pairs In other words: pub struct SecretCalendarDate {
iso_date: Date<Iso>,
kind: AnyCalendarKind,
}
// With this impl, SecretCalendarDate can be passed directly to DateTimeFormatter
impl IsInCalendar for SecretCalendarDate { ... }
impl SecretCalendarDate {
pub fn to_any_date_unstable(&self, provider: ...) -> Result<Date<AnyCalendar>, DataError> { ... }
pub fn to_iso_date(&self) -> Date<Iso> { ... }
}
impl IxdtfParser {
pub fn parse_date(&self) -> Result<SecretCalendarDate, ParseError> { ... }
} |
To me this seems like more an IxdtfParser issue. I don't think we need a factory type here. I think it returning |
It occurs to me that my claim about |
So the main functional difference (beyond the type system) of Ideally the output of the IXDTF parser can be passed into https://unicode-org.github.io/icu4x/rustdoc/icu/datetime/scaffold/trait.ConvertCalendar.html It could return We could instead make a new trait |
Not a huge fan of adding another format function, but I get it. I think it's fine to require an explicit conversion |
It's not about the explicit conversion; it's about the general problem of having data that is tagged with a calendar be able to use a DateTimeFormatter without having to load the calendar object an extra time (since it already lives inside of the DateTimeFormatter) but also still enforce that the calendar in the formatter matches the calendar annotation. So there are basically 3 situations for formatting with DateTimeFormatter:
|
Agree with the approach, but don't like the name "tagged". |
Partial discussion:
|
Conclusions: // icu_calendar
impl<A: AsCalendar> Date<A> {
pub fn try_new_from_codes(
era: Option<Era>,
year: i32,
month_code: MonthCode,
day: u8,
calendar: A,
) -> Result<Self, DateError>
pub fn try_from_str(
s: &str,
calendar: A,
) -> Result<Self, ParseError>
}
enum ParseError {
....
MismatchedCalendar(AnyCalendarKind /* or id string */),
}
impl DateTimeFormatter {
pub fn get_calendar(&self) -> Ref<AnyCalendar>
}
// Call site
let date = Date::try_from_str("...", dtf.get_calendar())?;
let fdt = dtf.strict_format(date)?;
// Possible future
let fdt = dtf.format_ixdtf("...")?; LGTM: @sffc @Manishearth @robertbastian Time zone parser: impl IxdtfParser {
pub fn try_location_only_iso_from_str(
&self,
ixdtf_str: &str,
) -> Result<CustomZonedDateTime<Iso, TimeZoneInfo<models::AtTime>>, ParseError> { ... }
pub fn try_location_only_from_str<A: AsCalendar>(
&self,
ixdtf_str: &str,
calendar: A,
) -> Result<CustomZonedDateTime<A, TimeZoneInfo<models::AtTime>>, ParseError> { ... }
} LGTM: @sffc @robertbastian @Manishearth |
This probably can be done alongside #5859 and #5929, which @robertbastian is already working on. |
Currently
AnyCalendar::try_new_unstable
loads the data every time, making it seem inefficient since calendars are often (but not always) short-lived objects.Should we consider adding
AnyCalendarFactory
?This type could be used internally in the IxdtfParser (#5736).
@Manishearth @robertbastian
The text was updated successfully, but these errors were encountered: