Skip to content

Commit

Permalink
Merge branch 'main' into uts46bis
Browse files Browse the repository at this point in the history
  • Loading branch information
hsivonen committed May 20, 2024
2 parents 3a07fe7 + 79480df commit 608fdfe
Show file tree
Hide file tree
Showing 177 changed files with 7,080 additions and 2,102 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `icu_calendar`
- New `DateTime::local_unix_epoch()` convenience constructor (https://github.com/unicode-org/icu4x/pull/4479)
- Improved approximation for Persian calendrical calculations (https://github.com/unicode-org/icu4x/issues/4713)
- Fix weekday calculations in negative ISO years (https://github.com/unicode-org/icu4x/pull/4894)
- `icu_datetime`
- `FormattedDateTime` and `FormattedZonedDateTime` now implement `Clone` and `Copy` (https://github.com/unicode-org/icu4x/pull/4476)
- `icu_locid`
Expand All @@ -20,6 +21,7 @@
- Add `Aran` script code (https://github.com/unicode-org/icu4x/pull/4426)
- Mark additional constructors as `const` (https://github.com/unicode-org/icu4x/pull/4584, https://github.com/unicode-org/icu4x/pull/4574)
- Implement Joining_Type property (https://github.com/unicode-org/icu4x/pull/4599)
- Implement Hangul_Syllable_Type property (https://github.com/unicode-org/icu4x/pull/4885)
- `icu_segmenter`
- Fix Unicode 15.0 line breaking (https://github.com/unicode-org/icu4x/pull/4389)
- Data model and providers
Expand All @@ -38,6 +40,7 @@
- All languages
- Correctly handle invalid UTF8 (https://github.com/unicode-org/icu4x/pull/4353)
- Correctly handle chars (https://github.com/unicode-org/icu4x/pull/4349)
- Add `day_of_year` getter (https://github.com/unicode-org/icu4x/issues/4891)
- JS
- Fixed a bug where slice length is computed incorrectly (https://github.com/rust-diplomat/diplomat/pull/372)
- Changed file extensions for better compatibility with nodejs modules (https://github.com/rust-diplomat/diplomat/pull/387)
Expand All @@ -61,6 +64,7 @@
- `zerotrie`
- Add `as_borrowed_slice` and `AsRef` impl (https://github.com/unicode-org/icu4x/pull/4381)
- Add `ZeroTrieSimpleAsciiCursor` for manual iteration (https://github.com/unicode-org/icu4x/pull/4383)
- Increase bound of `p` to solve more perfect hash functions; _might_ break serialized ZeroTriePerfectHash from previous versions (https://github.com/unicode-org/icu4x/pull/4888)
- `zerovec`
- Change `ZeroHashMap` to use `twox-hash` (https://github.com/unicode-org/icu4x/pull/4592)
- `writeable`
Expand Down
22 changes: 21 additions & 1 deletion Cargo.lock

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

72 changes: 47 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,65 +209,87 @@ diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat.git", rev
diplomat_core = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "3167e39e89ae612233706f1ade3d9e8a5c6ad358" }
diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "3167e39e89ae612233706f1ade3d9e8a5c6ad358" }

# External deps from crates.io
bincode = { version = "1.3.1", default-features = false }
clap = { version = "4.2.0", default-features = false }
combine = { version = "4.3.1", default-features = false }
# EXTERNAL DEPENDENCIES
#
# Due to semver-related constraints, we generally want to consume crates.io dependencies with
# default features, with some notable exceptions:
#
# 1. Dependencies of core library crates need to be `no_std`
# 2. Some crates have a lot of default features that pull in undesirable transitive deps
#
# We therefore have three groups for our crates.io dependencies.

## External Deps Group 1: Library deps except datagen. No default features.
# Keep in sync with allowlist.rs:
# BASIC_RUNTIME_DEPS
# BASIC_BUILD_DEPS
# EXTRA_SERDE_DEPS
# EXTRA_EXPERIMENTAL_DEPS
# EXTRA_LSTM_DEPS
# EXTRA_RYU_DEPS
# EXTRA_CAPI_DEPS
# EXTRA_BLOB_DEPS
# EXTRA_FS_DEPS
core_maths = { version = "0.1.0", default-features = false }
displaydoc = { version = "0.2.3", default-features = false }
either = { version = "1.9.0", default-features = false }
elsa = { version = "1.10.0", default-features = false }
erased-serde = { version = "0.3.11", default-features = false }
eyre = { version = "0.6.0", default-features = false }
indexmap = { version = "1.0.0", default-features = false }
itertools = { version = "0.10.3", default-features = false}
libc_alloc = { version = "1.0.6", default-features = false }
log = { version = "0.4.17", default-features = false }
memchr = { version = "2.6.0", default-features = false }
ndarray = { version = "0.15.0", default-features = false }
nom = { version = "7.0.0", default-features = false }
num-bigint = { version = "0.4.3", default-features = false }
num-rational = { version = "0.4.0", default-features = false }
num-traits = { version = "0.2.0", default-features = false }
once_cell = {version = "1.15.0", default-features = false}
postcard = { version = "1.0.1", default-features = false }
proc-macro2 = { version = "1.0.61", default-features = false }
quote = { version = "1.0.28", default-features = false }
rayon = { version = "1.3.0", default-features = false }
regex-automata = { version = "0.2.0", default-features = false }
ryu = { version = "1.0.5", default-features = false }
serde = { version = "1.0.110", default-features = false }
serde_json = { version = "1.0.45", default-features = false, features = ["alloc"] } # requires either alloc or std to build
serde-aux = { version = "4.0.0", default-features = false }
serde-json-core = { version = "0.4.0", default-features = false }
simple_logger = { version = "4.0.0", default-features = false }
smallvec = { version = "1.10.0", default-features = false }
stable_deref_trait = { version = "1.2.0", default-features = false }
syn = { version = "2.0.21", default-features = false }
synstructure = { version = "0.13.0", default-features = false }
toml = { version = "0.5.8", default-features = false }
twox-hash = { version = "1.4.2", default-features = false }
unicode-bidi = { version = "0.3.11", default-features = false }
ureq = { version = "2.3.0", default-features = false }
utf16_iter = { version = "1.0.2", default-features = false }
utf8_iter = { version = "1.0.2", default-features = false }
wasmi = { version = "0.31.2", default-features = false }
write16 = { version = "1.0.0", default-features = false }

## External Deps Group 2: Heavy Dev and Datagen deps. No default features.
zip = { version = "0.6.0", default-features = false }
serde-aux = { version = "4.0.0", default-features = false }

## Dev only
## External Deps Group 3: Dev and Datagen deps. Include default features.
arraystring = "0.3.0"
arrayvec = "0.7.2"
atoi = "1.0.0"
bincode = "1.3.1"
clap = "4.2.0"
combine = "4.3.1"
criterion = "0.5.0"
detone = "1.0.0"
elsa = "1.10.0"
erased-serde = "0.3.11"
eyre = "0.6.0"
getrandom = "0.2"
iai = "0.1.1"
indexmap = "1.0.0"
itertools = "0.10.3"
ndarray = "0.15.0"
nom = "7.0.0"
once_cell = "1.15.0"
proc-macro2 = "1.0.61"
quote = "1.0.28"
rand = "0.8"
rand_distr = "0.4"
rand_pcg = "0.3"
rayon = "1.3.0"
rkyv = "0.7"
serde_json = "1.0.45"
simple_logger = "4.0.0"
syn = "2.0.21"
synstructure = "0.13.0"
toml = "0.5.8"
twox-hash = "1.4.2"
ureq = "2.3.0"
walkdir = "2.3.2"
wasmi = "0.31.2"

# Size optimized builds
[profile.release-opt-size]
Expand Down
2 changes: 1 addition & 1 deletion components/calendar/src/any_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use core::fmt;
///
/// let calendar = AnyCalendar::new_for_locale(&locale.into());
/// let calendar = Rc::new(calendar); // Avoid cloning it each time
/// // If everything is a local reference, you may use icu_calendar::Ref instead.
/// // If everything is a local reference, you may use icu::calendar::Ref instead.
///
/// // manually construct a datetime in this calendar
/// let manual_time = Time::try_new(12, 33, 12, 0).expect("failed to construct Time");
Expand Down
2 changes: 1 addition & 1 deletion components/calendar/src/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub trait Calendar {
fn day_of_year_info(&self, date: &Self::DateInner) -> types::DayOfYearInfo;

/// The [`AnyCalendarKind`] corresponding to this calendar,
/// if one exists. Implementors outside of `icu_calendar` should return `None`
/// if one exists. Implementors outside of `icu::calendar` should return `None`
fn any_calendar_kind(&self) -> Option<AnyCalendarKind> {
None
}
Expand Down
4 changes: 2 additions & 2 deletions components/calendar/src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::marker::PhantomData;
/// # Example
///
/// ```rust
/// use icu_calendar::{
/// use icu::calendar::{
/// types::IsoWeekday, Date, DateDuration, DateDurationUnit,
/// };
///
Expand Down Expand Up @@ -114,7 +114,7 @@ impl<C: Calendar + ?Sized> DateDuration<C> {
/// Construct a DateDuration
///
/// ```rust
/// # use icu_calendar::*;
/// # use icu::calendar::*;
/// // two years, three months, and five days
/// let duration: DateDuration<Iso> = DateDuration::new(2, 3, 0, 5);
/// ```
Expand Down
4 changes: 2 additions & 2 deletions components/calendar/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl CalendarError {
/// # Examples
///
/// ```
/// use icu_calendar::AnyCalendarKind;
/// use icu_calendar::CalendarError;
/// use icu::calendar::AnyCalendarKind;
/// use icu::calendar::CalendarError;
///
/// let cal_str = "maori";
///
Expand Down
17 changes: 15 additions & 2 deletions components/calendar/src/hebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl Date<Hebrew> {
///
///
/// ```rust
/// use icu_calendar::Date;
/// use icu::calendar::Date;
///
/// let date_hebrew =
/// Date::try_new_hebrew_date(3425, 4, 25)
Expand Down Expand Up @@ -470,7 +470,7 @@ impl<A: AsCalendar<Calendar = Hebrew>> DateTime<A> {
mod tests {

use super::*;
use crate::types::MonthCode;
use crate::types::{Era, MonthCode};
use calendrical_calculations::hebrew_keviyah::*;

// Sentinel value for Adar I
Expand Down Expand Up @@ -587,4 +587,17 @@ mod tests {
let yi = YearInfo::compute_for(88369);
assert_eq!(yi.keviyah.year_length(), 383);
}

#[test]
fn test_weekdays() {
// https://github.com/unicode-org/icu4x/issues/4893
let cal = Hebrew::new();
let era = "am".parse::<Era>().unwrap();
let month_code = "M01".parse::<MonthCode>().unwrap();
let dt = cal.date_from_codes(era, 3760, month_code, 1).unwrap();

// Should be Saturday per:
// https://www.hebcal.com/converter?hd=1&hm=Tishrei&hy=3760&h2g=1
assert_eq!(6, cal.day_of_week(&dt) as usize);
}
}
51 changes: 49 additions & 2 deletions components/calendar/src/iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ impl Calendar for Iso {

// The days of the week are the same every 400 years
// so we normalize to the nearest multiple of 400
let years_since_400 = date.0.year % 400;
let years_since_400 = date.0.year.rem_euclid(400);
debug_assert!(years_since_400 >= 0); // rem_euclid returns positive numbers
let years_since_400 = years_since_400 as u32;
let leap_years_since_400 = years_since_400 / 4 - years_since_400 / 100;
// The number of days to the current year
// Can never cause an overflow because years_since_400 has a maximum value of 399.
Expand Down Expand Up @@ -169,7 +171,7 @@ impl Calendar for Iso {
}
};
let january_1_2000 = 5; // Saturday
let day_offset = (january_1_2000 + year_offset + month_offset + date.0.day as i32) % 7;
let day_offset = (january_1_2000 + year_offset + month_offset + date.0.day as u32) % 7;

// We calculated in a zero-indexed fashion, but ISO specifies one-indexed
types::IsoWeekday::from((day_offset + 1) as usize)
Expand Down Expand Up @@ -832,4 +834,49 @@ mod test {
check(-1439, 1969, 12, 31, 0, 1);
check(-2879, 1969, 12, 30, 0, 1);
}

#[test]
fn test_continuity_near_year_zero() {
// https://github.com/unicode-org/icu4x/issues/4893
const ONE_DAY_DURATION: DateDuration<Iso> = DateDuration {
years: 0,
months: 0,
weeks: 0,
days: 1,
marker: core::marker::PhantomData,
};

let mut iso_date = Date::try_new_iso_date(-10, 1, 1).unwrap();
let mut rata_die = iso_date.to_fixed();
let mut weekday = iso_date.day_of_week();

for _ in 0..(366 * 20) {
let next_iso_date = iso_date.added(ONE_DAY_DURATION);
let next_rata_die = next_iso_date.to_fixed();
assert_eq!(
next_rata_die,
rata_die + 1,
"{iso_date:?}..{next_iso_date:?}"
);
let next_weekday = next_iso_date.day_of_week();
assert_eq!(
(next_weekday as usize) % 7,
(weekday as usize + 1) % 7,
"{iso_date:?}..{next_iso_date:?}"
);
if iso_date.month().code.parsed().unwrap().0 == 2 && iso_date.day_of_month().0 == 28 {
assert_eq!(next_iso_date.is_in_leap_year(), iso_date.is_in_leap_year());
if iso_date.is_in_leap_year() {
assert_eq!(next_iso_date.month().code.parsed().unwrap().0, 2);
assert_eq!(next_iso_date.day_of_month().0, 29);
} else {
assert_eq!(next_iso_date.month().code.parsed().unwrap().0, 3);
assert_eq!(next_iso_date.day_of_month().0, 1);
}
}
iso_date = next_iso_date;
rata_die = next_rata_die;
weekday = next_weekday;
}
}
}
2 changes: 1 addition & 1 deletion components/calendar/src/japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ impl Date<JapaneseExtended> {
Ok(Date::from_raw(inner, japanext_calendar))
}

/// For testing era fallback in icu_datetime
// For testing era fallback in icu_datetime
#[doc(hidden)]
pub fn into_japanese_date(self) -> Date<Japanese> {
Date::from_raw(self.inner, self.calendar.0)
Expand Down
Loading

0 comments on commit 608fdfe

Please sign in to comment.