Debian Codegraph @

rust/src/python/types/duration.rs

raw
1 use pyo3::prelude::*;
2
3 #[pyclass(module = "_pendulum")]
4 pub struct Duration {
5 #[pyo3(get, set)]
6 pub years: u32,
7 #[pyo3(get, set)]
8 pub months: u32,
9 #[pyo3(get, set)]
10 pub weeks: u32,
11 #[pyo3(get, set)]
12 pub days: u32,
13 #[pyo3(get, set)]
14 pub hours: u32,
15 #[pyo3(get, set)]
16 pub minutes: u32,
17 #[pyo3(get, set)]
18 pub seconds: u32,
19 #[pyo3(get, set)]
20 pub microseconds: u32,
21 }
22
23 #[pymethods]
24 impl Duration {
25 #[new]
26 #[pyo3(signature = (years=0, months=0, weeks=0, days=0, hours=0, minutes=0, seconds=0, microseconds=0))]
27 #[allow(clippy::too_many_arguments)]
28 pub fn new(
29 years: Option<u32>,
30 months: Option<u32>,
31 weeks: Option<u32>,
32 days: Option<u32>,
33 hours: Option<u32>,
34 minutes: Option<u32>,
35 seconds: Option<u32>,
36 microseconds: Option<u32>,
37 ) -> Self {
38 Self {
39 years: years.unwrap_or(0),
40 months: months.unwrap_or(0),
41 weeks: weeks.unwrap_or(0),
42 days: days.unwrap_or(0),
43 hours: hours.unwrap_or(0),
44 minutes: minutes.unwrap_or(0),
45 seconds: seconds.unwrap_or(0),
46 microseconds: microseconds.unwrap_or(0),
47 }
48 }
49
50 #[getter]
51 fn remaining_days(&self) -> PyResult<u32> {
52 Ok(self.days)
53 }
54
55 #[getter]
56 fn remaining_seconds(&self) -> PyResult<u32> {
57 Ok(self.seconds)
58 }
59 }