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

Function gmtime

crates/vm/src/stdlib/time.rs:519–542  ·  view source on GitHub ↗
(
        secs: OptionalArg<Option<Either<f64, i64>>>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

517 /// https://docs.python.org/3/library/time.html?highlight=gmtime#time.gmtime
518 #[pyfunction]
519 fn gmtime(
520 secs: OptionalArg<Option<Either<f64, i64>>>,
521 vm: &VirtualMachine,
522 ) -> PyResult<StructTimeData> {
523 #[cfg(any(unix, windows))]
524 {
525 let ts = match secs {
526 OptionalArg::Present(Some(value)) => pyobj_to_time_t(value, vm)?,
527 OptionalArg::Present(None) | OptionalArg::Missing => current_time_t(),
528 };
529 gmtime_from_timestamp(ts, vm)
530 }
531
532 #[cfg(not(any(unix, windows)))]
533 {
534 let instant = match secs {
535 OptionalArg::Present(Some(secs)) => pyobj_to_date_time(secs, vm)?.naive_utc(),
536 OptionalArg::Present(None) | OptionalArg::Missing => {
537 chrono::offset::Utc::now().naive_utc()
538 }
539 };
540 Ok(StructTimeData::new_utc(vm, instant))
541 }
542 }
543
544 #[pyfunction]
545 fn localtime(

Callers 1

_getdateFunction · 0.90

Calls 4

pyobj_to_time_tFunction · 0.85
current_time_tFunction · 0.85
gmtime_from_timestampFunction · 0.85
pyobj_to_date_timeFunction · 0.85

Tested by

no test coverage detected