diff --git a/crates/polars-time/src/windows/duration.rs b/crates/polars-time/src/windows/duration.rs index c8ce6832f6ac..ce5e7e7280e5 100644 --- a/crates/polars-time/src/windows/duration.rs +++ b/crates/polars-time/src/windows/duration.rs @@ -350,13 +350,15 @@ impl Duration { #[doc(hidden)] pub const fn duration_us(&self) -> i64 { self.months * 28 * 24 * 3600 * MICROSECONDS - + (self.weeks * NS_WEEK + self.nsecs + self.days * NS_DAY) / 1000 + + (self.weeks * NS_WEEK / 1000 + self.nsecs / 1000 + self.days * NS_DAY / 1000) } #[doc(hidden)] pub const fn duration_ms(&self) -> i64 { self.months * 28 * 24 * 3600 * MILLISECONDS - + (self.weeks * NS_WEEK + self.nsecs + self.days * NS_DAY) / 1_000_000 + + (self.weeks * NS_WEEK / 1_000_000 + + self.nsecs / 1_000_000 + + self.days * NS_DAY / 1_000_000) } #[doc(hidden)] @@ -689,7 +691,7 @@ impl Duration { } if d.weeks > 0 { - let t_weeks = nsecs_to_unit(self.weeks * NS_WEEK); + let t_weeks = nsecs_to_unit(NS_WEEK) * self.weeks; match tz { #[cfg(feature = "timezones")] Some(tz) => { @@ -707,7 +709,7 @@ impl Duration { } if d.days > 0 { - let t_days = nsecs_to_unit(self.days * NS_DAY); + let t_days = nsecs_to_unit(NS_DAY) * self.days; match tz { #[cfg(feature = "timezones")] Some(tz) => { diff --git a/py-polars/tests/unit/functions/range/test_date_range.py b/py-polars/tests/unit/functions/range/test_date_range.py index b5fc889ab008..a8ce8ccf0c28 100644 --- a/py-polars/tests/unit/functions/range/test_date_range.py +++ b/py-polars/tests/unit/functions/range/test_date_range.py @@ -369,3 +369,10 @@ def test_date_range_24h_interval_results_in_datetime() -> None: "date", [datetime(2022, 1, 1), datetime(2022, 1, 2), datetime(2022, 1, 3)] ) assert_series_equal(result.collect().to_series(), expected) + + +def test_long_date_range_12461() -> None: + result = pl.date_range(date(1900, 1, 1), date(2300, 1, 1), "1d", eager=True) + assert result[0] == date(1900, 1, 1) + assert result[-1] == date(2300, 1, 1) + assert (result.diff()[1:].dt.total_days() == 1).all()