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

Expose if a date is in a leap year #4273

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/calendar/src/any_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ impl Calendar for AnyCalendar {
match_cal_and_date!(match (self, date): (c, d) => c.year(d))
}

/// The calendar-specific check if year is a leap year represented by `date`
fn year_is_leap(&self, date: &Self::DateInner) -> bool {
match_cal_and_date!(match (self, date): (c, d) => c.year_is_leap(d))
}

/// The calendar-specific month represented by `date`
fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
match_cal_and_date!(match (self, date): (c, d) => c.month(d))
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/buddhist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ impl Calendar for Buddhist {
iso_year_as_buddhist(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Iso.year_is_leap(date)
}

/// The calendar-specific month represented by `date`
fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
Iso.month(date)
Expand Down
3 changes: 3 additions & 0 deletions components/calendar/src/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub trait Calendar {
/// The calendar-specific year represented by `date`
fn year(&self, date: &Self::DateInner) -> types::FormattableYear;

/// Calculate if a date is in a leap year
fn year_is_leap(&self, date: &Self::DateInner) -> bool;

/// The calendar-specific month represented by `date`
fn month(&self, date: &Self::DateInner) -> types::FormattableMonth;

Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/chinese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ impl Calendar for Chinese {
Self::format_chinese_year(date.0 .0.year, Some(date.0 .1))
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0 .0.year)
}

/// The calendar-specific month code represented by `date`;
/// since the Chinese calendar has leap months, an "L" is appended to the month code for
/// leap months. For example, in a year where an intercalary month is added after the second
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/coptic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ impl Calendar for Coptic {
year_as_coptic(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
}
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/dangi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ impl Calendar for Dangi {
Self::format_dangi_year(date.0 .0.year, Some(date.0 .1))
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0 .0.year)
}

fn month(&self, date: &Self::DateInner) -> crate::types::FormattableMonth {
let ordinal = date.0 .0.month;
let leap_month_option = date.0 .1.get_leap_month();
Expand Down
6 changes: 6 additions & 0 deletions components/calendar/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ impl<A: AsCalendar> Date<A> {
self.calendar.as_calendar().year(&self.inner)
}

/// The calendar-specific year represented by `self` is a leap year
#[inline]
pub fn year_is_leap(&self) -> bool {
self.calendar.as_calendar().year_is_leap(&self.inner)
}

/// The calendar-specific month represented by `self`
#[inline]
pub fn month(&self) -> types::FormattableMonth {
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/ethiopian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ impl Calendar for Ethiopian {
Self::year_as_ethiopian(date.0.year, self.0)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
}
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/gregorian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ impl Calendar for Gregorian {
year_as_gregorian(date.0 .0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Iso.year_is_leap(&date.0)
}

/// The calendar-specific month represented by `date`
fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
Iso.month(&date.0)
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/hebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ impl Calendar for Hebrew {
Self::year_as_hebrew(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

fn month(&self, date: &Self::DateInner) -> FormattableMonth {
let mut ordinal = date.0.month;
let is_leap_year = Self::is_leap_year(date.0.year);
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/indian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ impl Calendar for Indian {
}
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
}
Expand Down
16 changes: 16 additions & 0 deletions components/calendar/src/islamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ impl Calendar for IslamicObservational {
Self::year_as_islamic(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
}
Expand Down Expand Up @@ -464,6 +468,10 @@ impl Calendar for IslamicUmmAlQura {
Self::year_as_islamic(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
}
Expand Down Expand Up @@ -704,6 +712,10 @@ impl Calendar for IslamicCivil {
Self::year_as_islamic(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
}
Expand Down Expand Up @@ -944,6 +956,10 @@ impl Calendar for IslamicTabular {
Self::year_as_islamic(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
}
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ impl Calendar for Iso {
Self::year_as_iso(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

/// The calendar-specific month represented by `date`
fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
Expand Down
8 changes: 8 additions & 0 deletions components/calendar/src/japanese.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ impl Calendar for Japanese {
}
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Iso.year_is_leap(&date.inner)
}

/// The calendar-specific month represented by `date`
fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
Iso.month(&date.inner)
Expand Down Expand Up @@ -379,6 +383,10 @@ impl Calendar for JapaneseExtended {
Japanese::year(&self.0, date)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Japanese::year_is_leap(&self.0, date)
}

/// The calendar-specific month represented by `date`
fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
Japanese::month(&self.0, date)
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/julian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ impl Calendar for Julian {
year_as_gregorian(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

/// The calendar-specific month represented by `date`
fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/persian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ impl Calendar for Persian {
Self::year_as_persian(date.0.year)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Self::is_leap_year(date.0.year)
}

fn month(&self, date: &Self::DateInner) -> types::FormattableMonth {
date.0.month()
}
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/roc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ impl Calendar for Roc {
year_as_roc(date.0 .0.year as i64)
}

fn year_is_leap(&self, date: &Self::DateInner) -> bool {
Iso.year_is_leap(&date.0)
}

fn month(&self, date: &Self::DateInner) -> crate::types::FormattableMonth {
Iso.month(&date.0)
}
Expand Down
2 changes: 2 additions & 0 deletions ffi/capi/c/include/ICU4XIsoDate.h

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

2 changes: 2 additions & 0 deletions ffi/capi/c/include/ICU4XIsoDateTime.h

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

7 changes: 7 additions & 0 deletions ffi/capi/cpp/docs/source/date_ffi.rst

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

7 changes: 7 additions & 0 deletions ffi/capi/cpp/docs/source/datetime_ffi.rst

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

2 changes: 2 additions & 0 deletions ffi/capi/cpp/include/ICU4XIsoDate.h

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

10 changes: 10 additions & 0 deletions ffi/capi/cpp/include/ICU4XIsoDate.hpp

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

2 changes: 2 additions & 0 deletions ffi/capi/cpp/include/ICU4XIsoDateTime.h

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

10 changes: 10 additions & 0 deletions ffi/capi/cpp/include/ICU4XIsoDateTime.hpp

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

28 changes: 28 additions & 0 deletions ffi/capi/dart/package/lib/src/lib.g.dart

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

Loading