From 7a7aa6b16389ba271353b9797f5d1040f099975f Mon Sep 17 00:00:00 2001 From: TotallyNot <44345987+TotallyNot@users.noreply.github.com> Date: Mon, 27 Feb 2023 01:44:00 +0100 Subject: [PATCH] added unix timestamp options for to/from parameters --- torn-api/Cargo.toml | 2 +- torn-api/src/lib.rs | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/torn-api/Cargo.toml b/torn-api/Cargo.toml index d1edf5e..3c3f6fe 100644 --- a/torn-api/Cargo.toml +++ b/torn-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "torn-api" -version = "0.5.10" +version = "0.5.11" edition = "2021" authors = ["Pyrit [2111649]"] license = "MIT" diff --git a/torn-api/src/lib.rs b/torn-api/src/lib.rs index 21943da..01f7dbe 100644 --- a/torn-api/src/lib.rs +++ b/torn-api/src/lib.rs @@ -140,8 +140,8 @@ where A: ApiSelection, { pub selections: Vec<&'static str>, - pub from: Option>, - pub to: Option>, + pub from: Option, + pub to: Option, pub comment: Option, phantom: std::marker::PhantomData, } @@ -175,11 +175,11 @@ where write!(url, "?selections={}&key={}", self.selections.join(","), key).unwrap(); if let Some(from) = self.from { - write!(url, "&from={}", from.timestamp()).unwrap(); + write!(url, "&from={}", from).unwrap(); } if let Some(to) = self.to { - write!(url, "&to={}", to.timestamp()).unwrap(); + write!(url, "&to={}", to).unwrap(); } if let Some(comment) = &self.comment { @@ -224,12 +224,24 @@ where #[must_use] pub fn from(mut self, from: DateTime) -> Self { + self.request.from = Some(from.timestamp()); + self + } + + #[must_use] + pub fn from_timestamp(mut self, from: i64) -> Self { self.request.from = Some(from); self } #[must_use] pub fn to(mut self, to: DateTime) -> Self { + self.request.to = Some(to.timestamp()); + self + } + + #[must_use] + pub fn to_timestamp(mut self, to: i64) -> Self { self.request.to = Some(to); self }