Source code

Revision control

Copy as Markdown

Other Tools

// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// @generated by tools/make/codegen/src/capi_datetime.rs
#[rustfmt::skip]
#[diplomat::bridge]
#[diplomat::abi_rename = "icu4x_{0}_mv1"]
#[diplomat::attr(auto, namespace = "icu4x")]
pub mod ffi {
use alloc::boxed::Box;
use writeable::TryWriteable;
#[allow(unused_imports)]
use crate::datetime_helpers::{self, map_or_default};
#[allow(unused_imports)]
use crate::unstable::{
date_formatter::ffi::{DateFormatter, DateFormatterGregorian},
date_time_formatter::ffi::{DateTimeFormatter, DateTimeFormatterGregorian},
date::ffi::IsoDate,
datetime_options::ffi::{DateTimeAlignment, DateTimeLength, TimePrecision},
errors::ffi::DateTimeFormatterLoadError,
errors::ffi::DateTimeWriteError,
locale_core::ffi::Locale,
time_formatter::ffi::TimeFormatter,
time::ffi::Time,
timezone::ffi::TimeZoneInfo,
};
#[cfg(feature = "buffer_provider")]
use crate::unstable::provider::ffi::DataProvider;
#[diplomat::opaque]
#[diplomat::rust_link(icu::datetime::NoCalendarFormatter, Typedef)]
pub struct ZonedTimeFormatter(
pub icu_datetime::FixedCalendarDateTimeFormatter<
(),
icu_datetime::fieldsets::enums::ZonedTimeFieldSet
>,
);
impl ZonedTimeFormatter {
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_long")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::SpecificLong, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "compiled_data")]
pub fn create_specific_long(
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let zone = icu_datetime::fieldsets::zone::SpecificLong;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new(
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_long_with_provider")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::SpecificLong, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "buffer_provider")]
pub fn create_specific_long_with_provider(
provider: &DataProvider,
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let provider = provider.get()?;
let zone = icu_datetime::fieldsets::zone::SpecificLong;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new_with_buffer_provider(
provider,
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_short")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::SpecificShort, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "compiled_data")]
pub fn create_specific_short(
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let zone = icu_datetime::fieldsets::zone::SpecificShort;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new(
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "specific_short_with_provider")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::SpecificShort, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "buffer_provider")]
pub fn create_specific_short_with_provider(
provider: &DataProvider,
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let provider = provider.get()?;
let zone = icu_datetime::fieldsets::zone::SpecificShort;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new_with_buffer_provider(
provider,
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_long")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::LocalizedOffsetLong, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "compiled_data")]
pub fn create_localized_offset_long(
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let zone = icu_datetime::fieldsets::zone::LocalizedOffsetLong;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new(
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_long_with_provider")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::LocalizedOffsetLong, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "buffer_provider")]
pub fn create_localized_offset_long_with_provider(
provider: &DataProvider,
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let provider = provider.get()?;
let zone = icu_datetime::fieldsets::zone::LocalizedOffsetLong;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new_with_buffer_provider(
provider,
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_short")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::LocalizedOffsetShort, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "compiled_data")]
pub fn create_localized_offset_short(
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let zone = icu_datetime::fieldsets::zone::LocalizedOffsetShort;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new(
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "localized_offset_short_with_provider")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::LocalizedOffsetShort, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "buffer_provider")]
pub fn create_localized_offset_short_with_provider(
provider: &DataProvider,
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let provider = provider.get()?;
let zone = icu_datetime::fieldsets::zone::LocalizedOffsetShort;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new_with_buffer_provider(
provider,
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_long")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::GenericLong, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "compiled_data")]
pub fn create_generic_long(
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let zone = icu_datetime::fieldsets::zone::GenericLong;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new(
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_long_with_provider")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::GenericLong, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "buffer_provider")]
pub fn create_generic_long_with_provider(
provider: &DataProvider,
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let provider = provider.get()?;
let zone = icu_datetime::fieldsets::zone::GenericLong;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new_with_buffer_provider(
provider,
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_short")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::GenericShort, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[diplomat::demo(default_constructor)]
#[cfg(feature = "compiled_data")]
pub fn create_generic_short(
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let zone = icu_datetime::fieldsets::zone::GenericShort;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new(
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "generic_short_with_provider")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::GenericShort, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "buffer_provider")]
pub fn create_generic_short_with_provider(
provider: &DataProvider,
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let provider = provider.get()?;
let zone = icu_datetime::fieldsets::zone::GenericShort;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new_with_buffer_provider(
provider,
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "location")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::Location, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "compiled_data")]
pub fn create_location(
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let zone = icu_datetime::fieldsets::zone::Location;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new(
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "location_with_provider")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::Location, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "buffer_provider")]
pub fn create_location_with_provider(
provider: &DataProvider,
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let provider = provider.get()?;
let zone = icu_datetime::fieldsets::zone::Location;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new_with_buffer_provider(
provider,
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplar_city")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::ExemplarCity, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "compiled_data")]
pub fn create_exemplar_city(
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let zone = icu_datetime::fieldsets::zone::ExemplarCity;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new(
prefs,
options
)?
.cast_into_fset(),
)))
}
/// Creates a zoned formatter based on a non-zoned formatter.
///
/// Caution: The locale provided here must match the locale used to construct the non-zoned formatter,
/// or else unexpected behavior may occur!
#[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "exemplar_city_with_provider")]
#[diplomat::rust_link(icu::datetime::fieldsets::zone::ExemplarCity, Struct)]
#[diplomat::rust_link(icu::datetime::fieldsets::Combo, Struct, hidden)]
#[cfg(feature = "buffer_provider")]
pub fn create_exemplar_city_with_provider(
provider: &DataProvider,
locale: &Locale,
length: Option<DateTimeLength>,
time_precision: Option<TimePrecision>,
alignment: Option<DateTimeAlignment>,
) -> Result<Box<Self>, DateTimeFormatterLoadError> {
let provider = provider.get()?;
let zone = icu_datetime::fieldsets::zone::ExemplarCity;
let prefs = (&locale.0).into();
let mut options = icu_datetime::fieldsets::T::for_length(map_or_default(length));
options.time_precision = time_precision.map(Into::into);
options.alignment = alignment.map(Into::into);
let options = options.with_zone(zone);
Ok(Box::new(Self(
icu_datetime
::FixedCalendarDateTimeFormatter
::try_new_with_buffer_provider(
provider,
prefs,
options
)?
.cast_into_fset(),
)))
}
#[diplomat::rust_link(icu::datetime::FixedCalendarDateTimeFormatter::format, FnInStruct)]
#[diplomat::rust_link(icu::datetime::FormattedDateTime, Struct, hidden)]
#[diplomat::rust_link(icu::datetime::FormattedDateTime::to_string, FnInStruct, hidden)]
pub fn format(
&self,
time: &Time,
zone: &TimeZoneInfo,
write: &mut diplomat_runtime::DiplomatWrite,
) -> Result<(), DateTimeWriteError> {
let mut input = icu_datetime::unchecked::DateTimeInputUnchecked::default();
input.set_time_fields(time.0);
input.set_time_zone_id(zone.id);
if let Some(offset) = zone.offset {
input.set_time_zone_utc_offset(offset);
}
if let Some(zone_name_timestamp) = zone.zone_name_timestamp {
input.set_time_zone_name_timestamp(zone_name_timestamp);
}
else {
input.set_time_zone_name_timestamp(icu_time::zone::ZoneNameTimestamp::far_in_future())
}
if let Some(variant) = zone.variant {
input.set_time_zone_variant(variant);
}
let _infallible = self
.0
.format_unchecked(input)
.try_write_to(write)
.ok()
.transpose()?;
Ok(())
}
}
}