summaryrefslogtreecommitdiffstats
path: root/rust/src/python/types/interval.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-17 14:32:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-12-17 14:32:20 +0000
commitdb51f7f103bbbd6c91c8f47d75b3482ef8939691 (patch)
treeab59b1147bd0cd39f31a48073cff236ede4ec1df /rust/src/python/types/interval.rs
parentAdding upstream version 3.0.0~a1. (diff)
downloadpendulum-db51f7f103bbbd6c91c8f47d75b3482ef8939691.tar.xz
pendulum-db51f7f103bbbd6c91c8f47d75b3482ef8939691.zip
Adding upstream version 3.0.0.upstream/3.0.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rust/src/python/types/interval.rs')
-rw-r--r--rust/src/python/types/interval.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/rust/src/python/types/interval.rs b/rust/src/python/types/interval.rs
new file mode 100644
index 0000000..7137493
--- /dev/null
+++ b/rust/src/python/types/interval.rs
@@ -0,0 +1,46 @@
+use pyo3::prelude::*;
+
+use pyo3::types::PyDelta;
+
+#[pyclass(extends=PyDelta)]
+#[derive(Default)]
+pub struct Interval {
+ pub days: i32,
+ pub seconds: i32,
+ pub microseconds: i32,
+}
+
+#[pymethods]
+impl Interval {
+ #[new]
+ #[pyo3(signature = (days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0))]
+ pub fn new(
+ py: Python,
+ days: Option<i32>,
+ seconds: Option<i32>,
+ microseconds: Option<i32>,
+ milliseconds: Option<i32>,
+ minutes: Option<i32>,
+ hours: Option<i32>,
+ weeks: Option<i32>,
+ ) -> PyResult<Self> {
+ println!("{} days", 31);
+ PyDelta::new(
+ py,
+ days.unwrap_or(0),
+ seconds.unwrap_or(0),
+ microseconds.unwrap_or(0),
+ true,
+ )?;
+
+ let f = Ok(Self {
+ days: days.unwrap_or(0),
+ seconds: seconds.unwrap_or(0),
+ microseconds: microseconds.unwrap_or(0),
+ });
+
+ println!("{} days", 31);
+
+ f
+ }
+}