diff --git a/Cargo.lock b/Cargo.lock index fc61aed..65b176a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,11 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + [[package]] name = "base-x" version = "0.2.8" @@ -36,6 +42,19 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time 0.1.44", + "winapi", +] + [[package]] name = "chunked_transfer" version = "1.3.0" @@ -55,7 +74,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "784ad0fbab4f3e9cef09f20e0aea6000ae08d2cb98ac4c0abc53df18803d702f" dependencies = [ "percent-encoding", - "time", + "time 0.2.22", "version_check", ] @@ -71,7 +90,7 @@ dependencies = [ "publicsuffix", "serde", "serde_json", - "time", + "time 0.2.22", "url", ] @@ -104,6 +123,7 @@ dependencies = [ name = "gitea-timings" version = "0.1.0" dependencies = [ + "chrono", "serde", "unicode-width", "ureq", @@ -162,6 +182,25 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.5.2" @@ -415,6 +454,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + [[package]] name = "time" version = "0.2.22" @@ -543,6 +593,12 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasm-bindgen" version = "0.2.68" diff --git a/Cargo.toml b/Cargo.toml index f3cb3b6..9644b2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ authors = ["DuckDuckWhale"] edition = "2018" [dependencies] +chrono = "0.4.19" serde = "1.0.117" unicode-width = "0.1.8" ureq = { version = "1.5.2", features = ["json"] } diff --git a/src/main.rs b/src/main.rs index 9c82668..9d6116c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::fs; +use chrono::{Duration as OldDuration, SecondsFormat, Utc}; use serde::Deserialize; use unicode_width::UnicodeWidthStr; @@ -19,8 +20,14 @@ struct Issue { fn main() { let token = fs::read_to_string("time-tracker-token") .expect("Failed to read token from `time-tracker-token`."); + let since = Utc::now() + .checked_sub_signed(OldDuration::hours(24)) + .expect("Overflowed while trying to subtract 24 hours from now."); let response = ureq::get("https://git.duckduckwhale.com/api/v1/user/times") - .query("since", "2020-11-12T01:18:22-08:00") + .query( + "since", + since.to_rfc3339_opts(SecondsFormat::Secs, true).as_ref(), + ) .set("Authorization", format!("token {}", token).as_ref()) .timeout_connect(10_000) .call();