Skip to content

Commit

Permalink
s/format_any_calendar/format (#6020)
Browse files Browse the repository at this point in the history
Fixes #6013
  • Loading branch information
robertbastian authored Jan 20, 2025
1 parent 5c458b2 commit 6533329
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let dtf = DateTimeFormatter::try_new(
let date = Date::try_new_iso(2020, 9, 12).expect("date should be valid");
let date = date.to_any();

let formatted_date = dtf.format_any_calendar(&date).to_string();
let formatted_date = dtf.format(&date).to_string();
assert_eq!(
formatted_date,
"12 de septiembre de 2020"
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/datetime/src/combo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{provider::neo::*, scaffold::*};
/// .unwrap();
///
/// assert_writeable_eq!(
/// formatter.format_any_calendar(&zdt),
/// formatter.format(&zdt),
/// "Fri, 3:44 PM Los Angeles Time"
/// );
/// ```
Expand Down Expand Up @@ -94,7 +94,7 @@ use crate::{provider::neo::*, scaffold::*};
/// .unwrap();
///
/// assert_writeable_eq!(
/// formatter.format_any_calendar(&zdt),
/// formatter.format(&zdt),
/// "October 18, 2024 PT"
/// );
/// ```
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
//! DateTimeFormatter::try_new(locale!("en-US").into(), field_set)
//! .unwrap()
//! })
//! .map(|formatter| formatter.format_any_calendar(&datetime).to_string());
//! .map(|formatter| formatter.format(&datetime).to_string());
//!
//! assert_eq!(results, ["Jan 15, 4:00 PM", "Jan 15"])
//! ```
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/fieldsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ macro_rules! impl_date_or_calendar_period_marker {
/// let dt = Date::try_new_iso(2024, 5, 17).unwrap();
///
/// assert_writeable_eq!(
/// fmt.format_any_calendar(&dt),
/// fmt.format(&dt),
#[doc = concat!(" \"", $sample, "\"")]
/// );
/// ```
Expand Down Expand Up @@ -575,7 +575,7 @@ macro_rules! impl_date_marker {
/// let dt = DateTime { date: Date::try_new_iso(2024, 5, 17).unwrap(), time: Time::try_new(15, 47, 50, 0).unwrap() };
///
/// assert_writeable_eq!(
/// fmt.format_any_calendar(&dt),
/// fmt.format(&dt),
#[doc = concat!(" \"", $sample_time, "\"")]
/// );
/// ```
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//!
//! // Format something:
//! let datetime = DateTime { date: Date::try_new_iso(2025, 1, 15).unwrap(), time: Time::try_new(16, 9, 35, 0).unwrap() };
//! let formatted_date = dtf.format_any_calendar(&datetime);
//! let formatted_date = dtf.format(&datetime);
//!
//! assert_writeable_eq!(formatted_date, "15 de ene de 2025, 4:09 p. m.");
//! ```
Expand Down
16 changes: 8 additions & 8 deletions components/datetime/src/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ where
/// let date = Date::try_new_iso(2024, 5, 8).unwrap();
///
/// assert_writeable_eq!(
/// formatter.format_any_calendar(&date),
/// formatter.format(&date),
/// "30 Nisan 5784"
/// );
/// ```
Expand Down Expand Up @@ -631,7 +631,7 @@ where
///
/// let date = Date::try_new_roc(113, 5, 8).unwrap();
///
/// assert_writeable_eq!(formatter.format_any_calendar(&date), "30 Nisan 5784");
/// assert_writeable_eq!(formatter.format(&date), "30 Nisan 5784");
/// ```
///
/// A time cannot be passed into the formatter when a date is expected:
Expand All @@ -649,9 +649,9 @@ where
/// .unwrap();
///
/// // error[E0277]: the trait bound `Time: AllInputMarkers<fieldsets::YMD>` is not satisfied
/// formatter.format_any_calendar(&Time::midnight());
/// formatter.format(&Time::midnight());
/// ```
pub fn format_any_calendar<'a, I>(&'a self, datetime: &I) -> FormattedDateTime<'a>
pub fn format<'a, I>(&'a self, datetime: &I) -> FormattedDateTime<'a>
where
I: ?Sized + ConvertCalendar,
I::Converted<'a>: Sized + AllInputMarkers<FSet>,
Expand Down Expand Up @@ -695,7 +695,7 @@ impl<C: CldrCalendar, FSet: DateTimeMarkers> FixedCalendarDateTimeFormatter<C, F
/// let date = Date::try_new_iso(2024, 10, 14).unwrap();
///
/// assert_writeable_eq!(
/// formatter.format_any_calendar(&date),
/// formatter.format(&date),
/// "12 Tishri 5785"
/// );
/// ```
Expand Down Expand Up @@ -852,7 +852,7 @@ impl<FSet: DateTimeMarkers> DateTimeFormatter<FSet> {
/// // Test that the specific formatter works:
/// let date = Date::try_new_gregorian(2024, 12, 20).unwrap();
/// assert_writeable_eq!(
/// specific_formatter.format_any_calendar(&date),
/// specific_formatter.format(&date),
/// "20 déc. 2024"
/// );
///
Expand All @@ -861,7 +861,7 @@ impl<FSet: DateTimeMarkers> DateTimeFormatter<FSet> {
///
/// // Test that it still works:
/// assert_writeable_eq!(
/// general_formatter.format_any_calendar(&date),
/// general_formatter.format(&date),
/// "20 déc. 2024"
/// );
/// ```
Expand Down Expand Up @@ -892,7 +892,7 @@ impl<FSet: DateTimeMarkers> DateTimeFormatter<FSet> {
/// .unwrap();
///
/// assert_writeable_eq!(
/// formatter.format_any_calendar(&Date::try_new_iso(2024, 12, 16).unwrap()),
/// formatter.format(&Date::try_new_iso(2024, 12, 16).unwrap()),
/// "16 ธันวาคม 2567"
/// );
///
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//!
//! // Missing data is filled in on a best-effort basis, and an error is signaled.
//! assert_writeable_parts_eq!(
//! dtf.format_any_calendar(&dtz),
//! dtf.format(&dtz),
//! "Nov 20, 2566 BE, 11:35:03.50 AM GMT",
//! [
//! (0, 3, datetime_parts::MONTH),
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/tests/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ fn assert_fixture_element<C>(
description
);

let actual3 = any_dtf.format_any_calendar(&iso_any_input);
let actual3 = any_dtf.format(&iso_any_input);
assert_writeable_eq!(
actual3,
output_value.expectation(),
Expand Down
2 changes: 1 addition & 1 deletion components/icu/examples/jiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn main() -> Result<(), Box<dyn core::error::Error>> {
let formatter =
DateTimeFormatter::try_new(prefs, fieldsets::YMDT::medium().with_zone_specific_long())?;

println!("{}", formatter.format_any_calendar(&zoned_date_time)); // 11 Sept 6 Reiwa, 08:37:20 Japan Standard Time
println!("{}", formatter.format(&zoned_date_time)); // 11 Sept 6 Reiwa, 08:37:20 Japan Standard Time

Ok(())
}
4 changes: 2 additions & 2 deletions ffi/capi/bindings/dart/DateFormatter.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ffi/capi/bindings/dart/DateTimeFormatter.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ffi/capi/bindings/dart/ZonedDateTimeFormatter.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions ffi/capi/src/datetime_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,29 +257,29 @@ pub mod ffi {
}

/// Formats a [`Date`] to a string.
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format_any_calendar, FnInStruct)]
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format, FnInStruct)]
#[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)]
pub fn format(
&self,
value: &Date,
write: &mut diplomat_runtime::DiplomatWrite,
) -> Result<(), DateTimeFormatError> {
let _infallible = self.0.format_any_calendar(&value.0).write_to(write);
let _infallible = self.0.format(&value.0).write_to(write);
Ok(())
}

/// Formats a [`IsoDate`] to a string.
///
/// Will convert to this formatter's calendar first
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format_any_calendar, FnInStruct)]
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format, FnInStruct)]
#[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)]
pub fn format_iso(
&self,
value: &IsoDate,
write: &mut diplomat_runtime::DiplomatWrite,
) -> Result<(), DateTimeFormatError> {
let any = value.0.to_any();
let _infallible = self.0.format_any_calendar(&any).write_to(write);
let _infallible = self.0.format(&any).write_to(write);
Ok(())
}

Expand Down Expand Up @@ -337,7 +337,7 @@ pub mod ffi {
}

/// Formats a [`Date`] and a [`Time`] to a string.
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format_any_calendar, FnInStruct)]
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format, FnInStruct)]
#[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)]
pub fn format(
&self,
Expand All @@ -347,7 +347,7 @@ pub mod ffi {
) -> Result<(), DateTimeFormatError> {
let _infallible = self
.0
.format_any_calendar(&icu_timezone::DateTime {
.format(&icu_timezone::DateTime {
date: date.0.wrap_calendar_in_ref(),
time: time.0,
})
Expand All @@ -358,7 +358,7 @@ pub mod ffi {
/// Formats an [`IsoDate`] and a [`Time`] to a string.
///
/// Will convert to this formatter's calendar first
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format_any_calendar, FnInStruct)]
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format, FnInStruct)]
#[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)]
pub fn format_iso(
&self,
Expand All @@ -368,7 +368,7 @@ pub mod ffi {
) -> Result<(), DateTimeFormatError> {
let _infallible = self
.0
.format_any_calendar(&icu_timezone::DateTime {
.format(&icu_timezone::DateTime {
date: date.0,
time: time.0,
})
Expand Down
8 changes: 4 additions & 4 deletions ffi/capi/src/zoned_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub mod ffi {
)))
}
/// Formats a [`Date`] a [`Time`], and a [`TimeZoneInfo`] to a string.
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format_any_calendar, FnInStruct)]
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format, FnInStruct)]
#[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)]
pub fn format(
&self,
Expand All @@ -179,12 +179,12 @@ pub mod ffi {
.ok_or(DateTimeFormatError::ZoneInfoMissingFields)?,
),
};
let _infallible = self.0.format_any_calendar(&zdt).write_to(write);
let _infallible = self.0.format(&zdt).write_to(write);
Ok(())
}

/// Formats an [`IsoDate`] a [`Time`], and a [`TimeZoneInfo`] to a string.
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format_any_calendar, FnInStruct)]
#[diplomat::rust_link(icu::datetime::DateTimeFormatter::format, FnInStruct)]
#[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)]
pub fn format_iso(
&self,
Expand All @@ -205,7 +205,7 @@ pub mod ffi {
.ok_or(DateTimeFormatError::ZoneInfoMissingFields)?,
),
};
let _infallible = self.0.format_any_calendar(&zdt).write_to(write);
let _infallible = self.0.format(&zdt).write_to(write);
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions tutorials/data_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn main() {
.expect("date should be valid");
let date = date.to_any();
let formatted_date = dtf.format_any_calendar(&date).to_string();
let formatted_date = dtf.format(&date).to_string();
println!("📅: {}", formatted_date);
}
Expand Down Expand Up @@ -182,7 +182,7 @@ fn main() {
.expect("date should be valid");
let date = date.to_any();
let formatted_date = dtf.format_any_calendar(&date).to_string();
let formatted_date = dtf.format(&date).to_string();
println!("📅: {}", formatted_date);
}
Expand Down
2 changes: 1 addition & 1 deletion tutorials/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn main() {
// For smaller codesize you can use FixedCalendarDateTimeFormatter<Gregorian> with a DateTime<Gregorian>
let date = date.to_any();

let formatted_date = dtf.format_any_calendar(&date).to_string();
let formatted_date = dtf.format(&date).to_string();

println!("📅: {}", formatted_date);
}
Expand Down
2 changes: 1 addition & 1 deletion tutorials/intro_interactive.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ let date_formatter = DateTimeFormatter::try_new(
println!(
"Date: {}",
date_formatter
.format_any_calendar(&iso_date.to_any()).to_string()
.format(&iso_date.to_any()).to_string()
);
```

Expand Down

0 comments on commit 6533329

Please sign in to comment.