summaryrefslogtreecommitdiffstats
path: root/vendor/chrono/src/naive/isoweek.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/chrono/src/naive/isoweek.rs')
-rw-r--r--vendor/chrono/src/naive/isoweek.rs45
1 files changed, 40 insertions, 5 deletions
diff --git a/vendor/chrono/src/naive/isoweek.rs b/vendor/chrono/src/naive/isoweek.rs
index 6a4fcfd11..df5556a12 100644
--- a/vendor/chrono/src/naive/isoweek.rs
+++ b/vendor/chrono/src/naive/isoweek.rs
@@ -46,7 +46,8 @@ pub(super) fn iso_week_from_yof(year: i32, of: Of) -> IsoWeek {
(year, rawweek)
}
};
- IsoWeek { ywf: (year << 10) | (week << 4) as DateImpl | DateImpl::from(of.flags().0) }
+ let flags = YearFlags::from_year(year);
+ IsoWeek { ywf: (year << 10) | (week << 4) as DateImpl | DateImpl::from(flags.0) }
}
impl IsoWeek {
@@ -57,7 +58,7 @@ impl IsoWeek {
/// ```
/// use chrono::{NaiveDate, Datelike, Weekday};
///
- /// let d = NaiveDate::from_isoywd(2015, 1, Weekday::Mon);
+ /// let d = NaiveDate::from_isoywd_opt(2015, 1, Weekday::Mon).unwrap();
/// assert_eq!(d.iso_week().year(), 2015);
/// ```
///
@@ -66,7 +67,7 @@ impl IsoWeek {
///
/// ```
/// # use chrono::{NaiveDate, Datelike, Weekday};
- /// # let d = NaiveDate::from_isoywd(2015, 1, Weekday::Mon);
+ /// # let d = NaiveDate::from_isoywd_opt(2015, 1, Weekday::Mon).unwrap();
/// assert_eq!(d.year(), 2014);
/// assert_eq!(d, NaiveDate::from_ymd_opt(2014, 12, 29).unwrap());
/// ```
@@ -84,7 +85,7 @@ impl IsoWeek {
/// ```
/// use chrono::{NaiveDate, Datelike, Weekday};
///
- /// let d = NaiveDate::from_isoywd(2015, 15, Weekday::Mon);
+ /// let d = NaiveDate::from_isoywd_opt(2015, 15, Weekday::Mon).unwrap();
/// assert_eq!(d.iso_week().week(), 15);
/// ```
#[inline]
@@ -101,7 +102,7 @@ impl IsoWeek {
/// ```
/// use chrono::{NaiveDate, Datelike, Weekday};
///
- /// let d = NaiveDate::from_isoywd(2015, 15, Weekday::Mon);
+ /// let d = NaiveDate::from_isoywd_opt(2015, 15, Weekday::Mon).unwrap();
/// assert_eq!(d.iso_week().week0(), 14);
/// ```
#[inline]
@@ -164,4 +165,38 @@ mod tests {
assert_eq!(maxweek.week0(), 0);
assert_eq!(format!("{:?}", maxweek), NaiveDate::MAX.format("%G-W%V").to_string());
}
+
+ #[test]
+ fn test_iso_week_equivalence_for_first_week() {
+ let monday = NaiveDate::from_ymd_opt(2024, 12, 30).unwrap();
+ let friday = NaiveDate::from_ymd_opt(2025, 1, 3).unwrap();
+
+ assert_eq!(monday.iso_week(), friday.iso_week());
+ }
+
+ #[test]
+ fn test_iso_week_equivalence_for_last_week() {
+ let monday = NaiveDate::from_ymd_opt(2026, 12, 28).unwrap();
+ let friday = NaiveDate::from_ymd_opt(2027, 1, 1).unwrap();
+
+ assert_eq!(monday.iso_week(), friday.iso_week());
+ }
+
+ #[test]
+ fn test_iso_week_ordering_for_first_week() {
+ let monday = NaiveDate::from_ymd_opt(2024, 12, 30).unwrap();
+ let friday = NaiveDate::from_ymd_opt(2025, 1, 3).unwrap();
+
+ assert!(monday.iso_week() >= friday.iso_week());
+ assert!(monday.iso_week() <= friday.iso_week());
+ }
+
+ #[test]
+ fn test_iso_week_ordering_for_last_week() {
+ let monday = NaiveDate::from_ymd_opt(2026, 12, 28).unwrap();
+ let friday = NaiveDate::from_ymd_opt(2027, 1, 1).unwrap();
+
+ assert!(monday.iso_week() >= friday.iso_week());
+ assert!(monday.iso_week() <= friday.iso_week());
+ }
}