MCPcopy Index your code
hub / github.com/RustPython/RustPython / pyobj_to_date_time

Function pyobj_to_date_time

crates/vm/src/stdlib/time.rs:312–327  ·  view source on GitHub ↗
(
        value: Either<f64, i64>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

310
311 #[cfg(not(any(unix, windows)))]
312 fn pyobj_to_date_time(
313 value: Either<f64, i64>,
314 vm: &VirtualMachine,
315 ) -> PyResult<DateTime<chrono::offset::Utc>> {
316 let secs = match value {
317 Either::A(float) => {
318 if !float.is_finite() {
319 return Err(vm.new_value_error("Invalid value for timestamp"));
320 }
321 float.floor() as i64
322 }
323 Either::B(int) => int,
324 };
325 DateTime::<chrono::offset::Utc>::from_timestamp(secs, 0)
326 .ok_or_else(|| vm.new_overflow_error("timestamp out of range for platform time_t"))
327 }
328
329 #[cfg(not(any(unix, windows)))]
330 impl OptionalArg<Option<Either<f64, i64>>> {

Callers 2

naive_or_localMethod · 0.85
gmtimeFunction · 0.85

Calls 3

ok_or_elseMethod · 0.80
ErrClass · 0.50
is_finiteMethod · 0.45

Tested by

no test coverage detected