added unix timestamp options for to/from parameters

This commit is contained in:
TotallyNot 2023-02-27 01:44:00 +01:00
parent 9109720d15
commit d6e4582f62
2 changed files with 17 additions and 5 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "torn-api" name = "torn-api"
version = "0.5.10" version = "0.5.11"
edition = "2021" edition = "2021"
authors = ["Pyrit [2111649]"] authors = ["Pyrit [2111649]"]
license = "MIT" license = "MIT"

View file

@ -140,8 +140,8 @@ where
A: ApiSelection, A: ApiSelection,
{ {
pub selections: Vec<&'static str>, pub selections: Vec<&'static str>,
pub from: Option<DateTime<Utc>>, pub from: Option<i64>,
pub to: Option<DateTime<Utc>>, pub to: Option<i64>,
pub comment: Option<String>, pub comment: Option<String>,
phantom: std::marker::PhantomData<A>, phantom: std::marker::PhantomData<A>,
} }
@ -175,11 +175,11 @@ where
write!(url, "?selections={}&key={}", self.selections.join(","), key).unwrap(); write!(url, "?selections={}&key={}", self.selections.join(","), key).unwrap();
if let Some(from) = self.from { if let Some(from) = self.from {
write!(url, "&from={}", from.timestamp()).unwrap(); write!(url, "&from={}", from).unwrap();
} }
if let Some(to) = self.to { if let Some(to) = self.to {
write!(url, "&to={}", to.timestamp()).unwrap(); write!(url, "&to={}", to).unwrap();
} }
if let Some(comment) = &self.comment { if let Some(comment) = &self.comment {
@ -224,12 +224,24 @@ where
#[must_use] #[must_use]
pub fn from(mut self, from: DateTime<Utc>) -> Self { pub fn from(mut self, from: DateTime<Utc>) -> 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.request.from = Some(from);
self self
} }
#[must_use] #[must_use]
pub fn to(mut self, to: DateTime<Utc>) -> Self { pub fn to(mut self, to: DateTime<Utc>) -> 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.request.to = Some(to);
self self
} }