in src/serialize/per_type/numpy.rs [1295:1338]
fn datetime(&self, val: i64, opts: Opt) -> Result<NumpyDatetime64Repr, NumpyDateTimeError> {
match self {
Self::Years => Ok(DateTime::new(
(val + 1970)
.try_into()
.map_err(|_| NumpyDateTimeError::Unrepresentable { unit: *self, val })?,
1,
1,
0,
0,
0,
0,
)
.unwrap()),
Self::Months => Ok(DateTime::new(
(val / 12 + 1970)
.try_into()
.map_err(|_| NumpyDateTimeError::Unrepresentable { unit: *self, val })?,
(val % 12 + 1)
.try_into()
.map_err(|_| NumpyDateTimeError::Unrepresentable { unit: *self, val })?,
1,
0,
0,
0,
0,
)
.unwrap()),
Self::Weeks => {
to_jiff_datetime!(Timestamp::from_second(val * 7 * 24 * 60 * 60), self, val)
}
Self::Days => to_jiff_datetime!(Timestamp::from_second(val * 24 * 60 * 60), self, val),
Self::Hours => to_jiff_datetime!(Timestamp::from_second(val * 60 * 60), self, val),
Self::Minutes => to_jiff_datetime!(Timestamp::from_second(val * 60), self, val),
Self::Seconds => to_jiff_datetime!(Timestamp::from_second(val), self, val),
Self::Milliseconds => to_jiff_datetime!(Timestamp::from_millisecond(val), self, val),
Self::Microseconds => to_jiff_datetime!(Timestamp::from_microsecond(val), self, val),
Self::Nanoseconds => {
to_jiff_datetime!(Timestamp::from_nanosecond(val as i128), self, val)
}
_ => Err(NumpyDateTimeError::UnsupportedUnit(*self)),
}
.map(|dt| NumpyDatetime64Repr { dt, opts })
}