summaryrefslogtreecommitdiffstats
path: root/rust/src/python/types/precise_diff.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-17 14:36:26 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-17 14:36:33 +0000
commit665666d6f4213da8db57ebb480947b7caf1fe382 (patch)
tree0cac5d322dfe861a6de62b04fb916cef6dbe4510 /rust/src/python/types/precise_diff.rs
parentReleasing debian version 3.0.0~a1-2. (diff)
downloadpendulum-665666d6f4213da8db57ebb480947b7caf1fe382.tar.xz
pendulum-665666d6f4213da8db57ebb480947b7caf1fe382.zip
Merging upstream version 3.0.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rust/src/python/types/precise_diff.rs')
-rw-r--r--rust/src/python/types/precise_diff.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/rust/src/python/types/precise_diff.rs b/rust/src/python/types/precise_diff.rs
new file mode 100644
index 0000000..64ca3a6
--- /dev/null
+++ b/rust/src/python/types/precise_diff.rs
@@ -0,0 +1,53 @@
+use pyo3::prelude::*;
+
+#[pyclass(module = "_pendulum")]
+pub struct PreciseDiff {
+ #[pyo3(get, set)]
+ pub years: i32,
+ #[pyo3(get, set)]
+ pub months: i32,
+ #[pyo3(get, set)]
+ pub days: i32,
+ #[pyo3(get, set)]
+ pub hours: i32,
+ #[pyo3(get, set)]
+ pub minutes: i32,
+ #[pyo3(get, set)]
+ pub seconds: i32,
+ #[pyo3(get, set)]
+ pub microseconds: i32,
+ #[pyo3(get, set)]
+ pub total_days: i32,
+}
+
+#[pymethods]
+impl PreciseDiff {
+ #[new]
+ #[pyo3(signature = (years=0, months=0, days=0, hours=0, minutes=0, seconds=0, microseconds=0, total_days=0))]
+ #[allow(clippy::too_many_arguments)]
+ pub fn new(
+ years: Option<i32>,
+ months: Option<i32>,
+ days: Option<i32>,
+ hours: Option<i32>,
+ minutes: Option<i32>,
+ seconds: Option<i32>,
+ microseconds: Option<i32>,
+ total_days: Option<i32>,
+ ) -> Self {
+ Self {
+ years: years.unwrap_or(0),
+ months: months.unwrap_or(0),
+ days: days.unwrap_or(0),
+ hours: hours.unwrap_or(0),
+ minutes: minutes.unwrap_or(0),
+ seconds: seconds.unwrap_or(0),
+ microseconds: microseconds.unwrap_or(0),
+ total_days: total_days.unwrap_or(0),
+ }
+ }
+
+ fn __repr__(&self) -> String {
+ 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)
+ }
+}