Debian Codegraph @

rust/src/python/types/interval.rs

raw
1 use pyo3::prelude::*;
2
3 use pyo3::types::PyDelta;
4
5 #[pyclass(extends=PyDelta)]
6 #[derive(Default)]
7 pub struct Interval {
8 pub days: i32,
9 pub seconds: i32,
10 pub microseconds: i32,
11 }
12
13 #[pymethods]
14 impl Interval {
15 #[new]
16 #[pyo3(signature = (days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0))]
17 pub fn new(
18 py: Python,
19 days: Option<i32>,
20 seconds: Option<i32>,
21 microseconds: Option<i32>,
22 milliseconds: Option<i32>,
23 minutes: Option<i32>,
24 hours: Option<i32>,
25 weeks: Option<i32>,
26 ) -> PyResult<Self> {
27 println!("{} days", 31);
28 PyDelta::new(
29 py,
30 days.unwrap_or(0),
31 seconds.unwrap_or(0),
32 microseconds.unwrap_or(0),
33 true,
34 )?;
35
36 let f = Ok(Self {
37 days: days.unwrap_or(0),
38 seconds: seconds.unwrap_or(0),
39 microseconds: microseconds.unwrap_or(0),
40 });
41
42 println!("{} days", 31);
43
44 f
45 }
46 }