Skip to content

Commit

Permalink
Merge branch 'main' into propapi
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Sep 18, 2024
2 parents 2360886 + b279bdc commit 73b4cd1
Show file tree
Hide file tree
Showing 90 changed files with 6,047 additions and 5,276 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,16 @@ icu = "1.5.0"

```rust
use icu::calendar::DateTime;
use icu::datetime::{options::length, DateTimeFormatter};
use icu::datetime::{NeoFormatter, NeoSkeletonLength, neo_marker::NeoAutoDateTimeMarker};
use icu::locale::locale;

let options =
length::Bag::from_date_time_style(length::Date::Long, length::Time::Medium).into();

let dtf = DateTimeFormatter::try_new(&locale!("es").into(), options)
let dtf = NeoFormatter::<NeoAutoDateTimeMarker>::try_new(&locale!("es").into(), NeoSkeletonLength::Long.into())
.expect("locale should be present in compiled data");

let date = DateTime::try_new_iso_datetime(2020, 9, 12, 12, 35, 0).expect("datetime should be valid");
let date = date.to_any();

let formatted_date = dtf.format_to_string(&date).expect("formatting should succeed");
let formatted_date = dtf.convert_and_format(&date).to_string_lossy();
assert_eq!(
formatted_date,
"12 de septiembre de 2020, 12:35:00"
Expand Down
74 changes: 19 additions & 55 deletions components/datetime/README.md

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

6 changes: 0 additions & 6 deletions components/datetime/benches/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
mod fixtures;

use criterion::{criterion_group, criterion_main, Criterion};
#[cfg(feature = "experimental")]
use icu_datetime::neo::TypedNeoFormatter;

use icu_calendar::{DateTime, Gregorian};
use icu_locale_core::Locale;
use icu_timezone::{CustomTimeZone, CustomZonedDateTime};
#[cfg(feature = "experimental")]
use writeable::TryWriteable;

#[path = "../tests/mock.rs"]
Expand All @@ -20,7 +18,6 @@ mod mock;
fn datetime_benches(c: &mut Criterion) {
let mut group = c.benchmark_group("datetime");

#[cfg(feature = "experimental")]
let mut bench_neoneo_datetime_with_fixture = |name, file, has_zones| {
let fxs = serde_json::from_str::<fixtures::Fixture>(file).unwrap();
group.bench_function(&format!("semantic/{name}"), |b| {
Expand Down Expand Up @@ -71,21 +68,18 @@ fn datetime_benches(c: &mut Criterion) {
});
};

#[cfg(feature = "experimental")]
bench_neoneo_datetime_with_fixture(
"lengths",
include_str!("fixtures/tests/lengths.json"),
false,
);

#[cfg(feature = "experimental")]
bench_neoneo_datetime_with_fixture(
"components",
include_str!("fixtures/tests/components.json"),
false,
);

#[cfg(feature = "experimental")]
bench_neoneo_datetime_with_fixture(
"lengths_with_zones",
include_str!("fixtures/tests/lengths_with_zones.json"),
Expand Down
4 changes: 0 additions & 4 deletions components/datetime/benches/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ pub struct TestInput {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TestOptions {
pub length: Option<icu_datetime::options::length::Bag>,
#[cfg(feature = "experimental")]
pub components: Option<icu_datetime::options::components::Bag>,
#[cfg(feature = "experimental")]
pub semantic: Option<icu_datetime::neo_skeleton::NeoSkeleton>,
#[cfg(feature = "experimental")]
pub preferences: Option<icu_datetime::options::preferences::Bag>,
}

Expand Down Expand Up @@ -57,7 +54,6 @@ pub fn get_options(input: &TestOptions) -> Option<DateTimeFormatterOptions> {
if let Some(bag) = input.length {
return Some(bag.into());
}
#[cfg(feature = "experimental")]
if let Some(bag) = input.components {
return Some(bag.into());
}
Expand Down
18 changes: 10 additions & 8 deletions components/datetime/examples/work_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ icu_benchmark_macros::instrument!();
use icu_benchmark_macros::println;

use icu_calendar::{DateTime, Gregorian};
use icu_datetime::{options::length, TypedDateTimeFormatter};
use icu_datetime::{
neo::TypedNeoFormatter, neo_marker::NeoYearMonthDayHourMinuteMarker,
neo_skeleton::NeoSkeletonLength,
};
use icu_locale_core::locale;

const DATES_ISO: &[(i32, u8, u8, u8, u8, u8)] = &[
Expand All @@ -27,19 +30,18 @@ const DATES_ISO: &[(i32, u8, u8, u8, u8, u8)] = &[
];

fn main() {
let mut options = length::Bag::default();
options.date = Some(length::Date::Medium);
options.time = Some(length::Time::Short);

let dtf = TypedDateTimeFormatter::<Gregorian>::try_new(&locale!("en").into(), options.into())
.expect("Failed to create TypedDateTimeFormatter instance.");
let dtf = TypedNeoFormatter::<Gregorian, NeoYearMonthDayHourMinuteMarker>::try_new(
&locale!("en").into(),
NeoSkeletonLength::Medium.into(),
)
.expect("Failed to create TypedDateTimeFormatter instance.");

println!("\n====== Work Log (en) example ============");

for (idx, &(year, month, day, hour, minute, second)) in DATES_ISO.iter().enumerate() {
let date = DateTime::try_new_gregorian_datetime(year, month, day, hour, minute, second)
.expect("datetime should parse");
let fdt = dtf.format(&date);
println!("{idx}) {}", fdt);
println!("{idx}) {}", writeable::adapters::LossyWrap(fdt));
}
}
Loading

0 comments on commit 73b4cd1

Please sign in to comment.