chrono -> time

This commit is contained in:
Robin Appelman 2022-01-23 15:29:23 +01:00
commit f920def82c
3 changed files with 12 additions and 13 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "demostf-client"
version = "0.2.0"
version = "0.3.0"
authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018"
description = "Api client for demos.tf"
@ -11,7 +11,7 @@ exclude = [ "tests/data/gully.dem" ]
[dependencies]
serde = { version = "1", features = ["derive"] }
chrono = { version = "0.4", features = ["serde"] }
time = { version = "0.3", features = ["serde"] }
reqwest = { version = "0.11", default-features = false, features = ["json", "multipart"] }
thiserror = "1"
hex = "0.4"

View file

@ -1,4 +1,3 @@
use chrono::{DateTime, Utc};
use reqwest::{multipart, Client, IntoUrl, StatusCode, Url};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::Cow;
@ -6,6 +5,7 @@ use std::fmt;
use std::str::FromStr;
pub use steamid_ng::SteamID;
use thiserror::Error;
use time::OffsetDateTime;
#[derive(Debug, Error)]
pub enum Error {
@ -37,8 +37,8 @@ pub struct Demo {
pub duration: u16,
pub nick: String,
pub map: String,
#[serde(with = "chrono::serde::ts_seconds")]
pub time: DateTime<Utc>,
#[serde(with = "time::serde::timestamp")]
pub time: OffsetDateTime,
pub red: String,
pub blue: String,
pub red_score: u8,
@ -235,17 +235,17 @@ pub struct ListParams {
#[serde(rename = "type")]
ty: Option<GameType>,
#[serde(serialize_with = "serialize_option_time")]
after: Option<DateTime<Utc>>,
after: Option<OffsetDateTime>,
#[serde(serialize_with = "serialize_option_time")]
before: Option<DateTime<Utc>>,
before: Option<OffsetDateTime>,
}
fn serialize_option_time<S>(dt: &Option<DateTime<Utc>>, serializer: S) -> Result<S::Ok, S::Error>
fn serialize_option_time<S>(dt: &Option<OffsetDateTime>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match dt {
Some(time) => chrono::serde::ts_seconds::serialize(time, serializer),
Some(time) => time::serde::timestamp::serialize(time, serializer),
None => Option::<i64>::serialize(&None, serializer),
}
}
@ -296,14 +296,14 @@ impl ListParams {
}
}
pub fn with_before(self, before: DateTime<Utc>) -> Self {
pub fn with_before(self, before: OffsetDateTime) -> Self {
ListParams {
before: Some(before),
..self
}
}
pub fn with_after(self, after: DateTime<Utc>) -> Self {
pub fn with_after(self, after: OffsetDateTime) -> Self {
ListParams {
after: Some(after),
..self

View file

@ -21,7 +21,6 @@ async fn setup() {
let tables = [
"chat",
"demos",
"kills",
"players",
"storage_keys",
"teams",