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