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

Function checked_tm_from_struct_time

crates/vm/src/stdlib/time.rs:350–487  ·  view source on GitHub ↗
(
        t: &StructTimeData,
        vm: &VirtualMachine,
        func_name: &'static str,
    )

Source from the content-addressed store, hash-verified

348
349 #[cfg(any(unix, windows))]
350 fn checked_tm_from_struct_time(
351 t: &StructTimeData,
352 vm: &VirtualMachine,
353 func_name: &'static str,
354 ) -> PyResult<CheckedTm> {
355 let invalid_tuple =
356 || vm.new_type_error(format!("{func_name}(): illegal time tuple argument"));
357
358 let year: i64 = t.tm_year.clone().try_into_value(vm).map_err(|e| {
359 if e.class().is(vm.ctx.exceptions.overflow_error) {
360 vm.new_overflow_error("year out of range")
361 } else {
362 invalid_tuple()
363 }
364 })?;
365 if year < i64::from(i32::MIN) + 1900 || year > i64::from(i32::MAX) {
366 return Err(vm.new_overflow_error("year out of range"));
367 }
368 let year = year as i32;
369 let tm_mon = t
370 .tm_mon
371 .clone()
372 .try_into_value::<i32>(vm)
373 .map_err(|_| invalid_tuple())?
374 - 1;
375 let tm_mday = t
376 .tm_mday
377 .clone()
378 .try_into_value(vm)
379 .map_err(|_| invalid_tuple())?;
380 let tm_hour = t
381 .tm_hour
382 .clone()
383 .try_into_value(vm)
384 .map_err(|_| invalid_tuple())?;
385 let tm_min = t
386 .tm_min
387 .clone()
388 .try_into_value(vm)
389 .map_err(|_| invalid_tuple())?;
390 let tm_sec = t
391 .tm_sec
392 .clone()
393 .try_into_value(vm)
394 .map_err(|_| invalid_tuple())?;
395 let tm_wday = (t
396 .tm_wday
397 .clone()
398 .try_into_value::<i32>(vm)
399 .map_err(|_| invalid_tuple())?
400 + 1)
401 % 7;
402 let tm_yday = t
403 .tm_yday
404 .clone()
405 .try_into_value::<i32>(vm)
406 .map_err(|_| invalid_tuple())?
407 - 1;

Callers 3

asctimeFunction · 0.85
ctimeFunction · 0.85
strftimeFunction · 0.85

Calls 9

newFunction · 0.85
try_into_valueMethod · 0.80
isMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
cloneMethod · 0.45
classMethod · 0.45
as_strMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected