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

Function mktime

crates/vm/src/stdlib/time.rs:567–589  ·  view source on GitHub ↗
(t: StructTimeData, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

565
566 #[pyfunction]
567 fn mktime(t: StructTimeData, vm: &VirtualMachine) -> PyResult<f64> {
568 #[cfg(unix)]
569 {
570 unix_mktime(&t, vm)
571 }
572
573 #[cfg(windows)]
574 {
575 win_mktime(&t, vm)
576 }
577
578 #[cfg(not(any(unix, windows)))]
579 {
580 let datetime = t.to_date_time(vm)?;
581 // mktime interprets struct_time as local time
582 let local_dt = chrono::Local
583 .from_local_datetime(&datetime)
584 .single()
585 .ok_or_else(|| vm.new_overflow_error("mktime argument out of range"))?;
586 let seconds_since_epoch = local_dt.timestamp() as f64;
587 Ok(seconds_since_epoch)
588 }
589 }
590
591 #[cfg(not(any(unix, windows)))]
592 const CFMT: &str = "%a %b %e %H:%M:%S %Y";

Callers 1

unix_mktimeFunction · 0.85

Calls 5

unix_mktimeFunction · 0.85
win_mktimeFunction · 0.85
to_date_timeMethod · 0.80
ok_or_elseMethod · 0.80
timestampMethod · 0.80

Tested by

no test coverage detected