Skip to content
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

Failing debug_assert when formatting week_of_year #4977

Closed
iyzana opened this issue May 30, 2024 · 1 comment · Fixed by #4986
Closed

Failing debug_assert when formatting week_of_year #4977

iyzana opened this issue May 30, 2024 · 1 comment · Fixed by #4986

Comments

@iyzana
Copy link
Contributor

iyzana commented May 30, 2024

Formatting the first 13 days of the year fails when including the week_of_year.

Steps to reproduce

Run the following code in debug-mode (i.e. cargo run without --release)

use icu_calendar::{DateTime, Gregorian, Time};
use icu_datetime::options::components;
use icu_datetime::TypedDateTimeFormatter;
use icu_locid::locale;

fn main() {
    let mut elements = components::Bag::empty();
    elements.week = Some(components::Week::NumericWeekOfYear);
    let formatter = TypedDateTimeFormatter::<Gregorian>::try_new_experimental(
        &locale!("en_US").into(),
        elements.into(),
    )
    .expect("valid formatter");
    let date = icu_calendar::Date::try_new_gregorian_date(2024, 1, 1).expect("valid date");
    formatter.format_to_string(&DateTime::new(date, Time::midnight()));
}

Expected behaviour

The formatter formats the date to "1"

Actual behaviour

The program panics on format_to_string

thread 'main' panicked at .local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/icu_datetime-1.5.0/src/input.rs:352:9:
assertion failed: day_of_year_info.day_of_year >= icu_calendar::week::MIN_UNIT_DAYS
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:145:5
   3: icu_datetime::input::ExtractedDateTimeInput::week_of_year
             at .local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/icu_datetime-1.5.0/src/input.rs:352:9
   4: icu_datetime::format::datetime::try_write_field::{{closure}}
             at .local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/icu_datetime-1.5.0/src/format/datetime.rs:531:21
   5: core::result::Result<T,E>::and_then
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/result.rs:1321:22
   6: icu_datetime::format::datetime::try_write_field
             at .local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/icu_datetime-1.5.0/src/format/datetime.rs:528:39
   7: icu_datetime::format::datetime::try_write_pattern_items
             at .local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/icu_datetime-1.5.0/src/format/datetime.rs:246:27
   8: icu_datetime::format::datetime::try_write_pattern
             at .local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/icu_datetime-1.5.0/src/format/datetime.rs:212:5
   9: <icu_datetime::format::datetime::FormattedDateTime as writeable::Writeable>::write_to
             at .local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/icu_datetime-1.5.0/src/format/datetime.rs:131:19
  10: writeable::Writeable::write_to_string
             at .local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/writeable-0.5.5/src/lib.rs:279:17
  11: icu_datetime::datetime::TypedDateTimeFormatter<C>::format_to_string
             at .local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/icu_datetime-1.5.0/src/datetime.rs:788:9
  12: icu4x_reproduce::main
             at ./src/main.rs:15:5
  13: core::ops::function::FnOnce::call_once
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/ops/function.rs:250:5

Versions

  • icu_datetime version 1.5.0
  • icu_calendar version 1.5.0
  • icu_locid version 1.5.0
  • rustc 1.78.0
iyzana added a commit to iyzana/icu4x that referenced this issue Jun 1, 2024
iyzana added a commit to iyzana/icu4x that referenced this issue Jun 1, 2024
robertbastian pushed a commit that referenced this issue Jun 4, 2024
The assert was probably meant to ensure the complete year has at least
14 days, and not that the given day is at least the 14th day of the year

Fixes: #4977
sffc added a commit that referenced this issue Jun 4, 2024
sffc pushed a commit that referenced this issue Jun 6, 2024
The assert was probably meant to ensure the complete year has at least
14 days, and not that the given day is at least the 14th day of the year

Fixes: #4977
(cherry picked from commit e83fd9b)
sffc added a commit that referenced this issue Jun 6, 2024
#4977
(cherry picked from commit fe96085)
@sffc
Copy link
Member

sffc commented Jun 6, 2024

icu_datetime version 1.5.1 has been released with this fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants