Skip to content

Add support for non-ISO yearmonths and monthdays#490

Merged
Manishearth merged 11 commits intoboa-dev:mainfrom
Manishearth:non-iso-ym
Aug 5, 2025
Merged

Add support for non-ISO yearmonths and monthdays#490
Manishearth merged 11 commits intoboa-dev:mainfrom
Manishearth:non-iso-ym

Conversation

@Manishearth
Copy link
Copy Markdown
Contributor

@Manishearth Manishearth commented Aug 5, 2025

This adds support for non-ISO yearmonths, as well as some non-ISO monthdays.

It currently does not support this for Ethiopic or Chinese/Dangi, since it needs working extended years.

Progress on #412, fixes #450

@Manishearth Manishearth requested a review from nekevss August 5, 2025 10:14
@Manishearth Manishearth force-pushed the non-iso-ym branch 3 times, most recently from e069247 to ce9abdc Compare August 5, 2025 12:59
@Manishearth
Copy link
Copy Markdown
Contributor Author

I used a little search script to generate the dates here:

use icu_calendar::Date;
use icu_calendar::Ref;
use icu_calendar::cal::HijriTabularEpoch;
use icu_calendar::cal::HijriTabularLeapYears;
use icu_calendar::types::MonthCode;
fn main() {
    let iso = Date::try_new_iso(1972, 12, 31).unwrap();
    let calendar = icu_calendar::cal::HijriSimulated::new_mecca();
    let calendar = Ref(&calendar);
    let iso_converted = iso.to_calendar(calendar);
    println!("{:?}", iso_converted);
    'outer: for i in 1..=12 {
        let month = MonthCode::new_normal(i).unwrap();
        let day = 30;
        let mut year = iso_converted.extended_year();
        if i >= iso_converted.month().month_number() {
            year -= 1;
        }
        while (iso_converted.extended_year() - year) < 1000 {
            let attempted_date = Date::try_new_from_codes(None, year, month, day, calendar);
            if let Ok(date) = attempted_date {
                println!("Found {:?} (ISO: {:?})", date, date.to_iso());
                continue 'outer;
            }
            year -= 1;
        }
        println!("No workable year found!");
    }
}

@Manishearth
Copy link
Copy Markdown
Contributor Author

I think we should try and fix Chinese after unicode-org/icu4x#6800 or unicode-org/icu4x#6762 lands.

Copy link
Copy Markdown
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, looks good to me. Have a couple doc specific misspellings / nits, but nothing blocking.

Comment thread src/builtins/core/calendar/types.rs Outdated
}
}
// For simple calendars with a single leap day.
// This needs the date of 1972-12-31 represented in that calendar, the month-day of th eleap day,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spelling

Comment thread src/builtins/core/calendar/types.rs Outdated
Comment thread src/builtins/core/calendar/types.rs Outdated
Manishearth and others added 4 commits August 6, 2025 02:50
Co-authored-by: Kevin Ness <46825870+nekevss@users.noreply.github.com>
Co-authored-by: Kevin Ness <46825870+nekevss@users.noreply.github.com>
@Manishearth Manishearth merged commit 2f79447 into boa-dev:main Aug 5, 2025
8 checks passed
@Manishearth Manishearth deleted the non-iso-ym branch August 5, 2025 21:37
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 this pull request may close these issues.

PlainYearMonth, PlainMonthDay should support non-ISO calendars

2 participants