diff --git a/Cargo.lock b/Cargo.lock index e37ffb8..597846c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,12 +176,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", - "js-sys", "num-integer", "num-traits", "serde", - "time 0.1.45", - "wasm-bindgen", "winapi", ] @@ -368,7 +365,6 @@ version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4391a22b19c916e50bec4d6140f29bdda3e3bb187223fe6e3ea0b6e4d1021c04" dependencies = [ - "chrono", "diesel_derives", "libsqlite3-sys", "r2d2", @@ -613,7 +609,7 @@ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -861,9 +857,9 @@ checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "is-terminal" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", @@ -1061,7 +1057,7 @@ checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.45.0", ] @@ -1686,7 +1682,6 @@ name = "secubot" version = "2.1.0" dependencies = [ "anyhow", - "chrono", "config", "diesel", "diesel_migrations", @@ -1700,6 +1695,7 @@ dependencies = [ "regex", "serde", "serde_derive", + "time", "tokio", "tokio-stream", "url_encoded_data", @@ -1815,7 +1811,7 @@ dependencies = [ "serde", "serde-value", "serde_json", - "time 0.3.19", + "time", "tokio", "tracing", "typemap_rev", @@ -1853,7 +1849,7 @@ dependencies = [ "num-bigint", "num-traits", "thiserror", - "time 0.3.19", + "time", ] [[package]] @@ -1918,9 +1914,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.107" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "d56e159d99e6c2b93995d171050271edb50ecc5288fbc7cc17de8fdce4e58c14" dependencies = [ "proc-macro2", "quote", @@ -1970,17 +1966,6 @@ dependencies = [ "syn", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "time" version = "0.3.19" @@ -2283,12 +2268,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index cd3b8a2..e5a7907 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,9 +18,9 @@ maintenance = { status = "experimental" } poise = { version = "0.5" } tokio = { version = "1.20", features = ["rt-multi-thread"] } tokio-stream = { version = "0.1" } -diesel = { version = "2.0", features = ["sqlite", "returning_clauses_for_sqlite_3_35", "r2d2", "chrono"] } +diesel = { version = "2.0", features = ["sqlite", "returning_clauses_for_sqlite_3_35", "r2d2"] } diesel_migrations = { version = "2.0" } -chrono = { version = "0.4", features = ["serde"] } +time = { version = "0.3"} serde = { version = "1.0", features = ["derive"] } serde_derive = { version = "1.0" } regex = { version = "1.6" } diff --git a/src/commands/todo.rs b/src/commands/todo.rs index e29b7aa..4de4c9b 100644 --- a/src/commands/todo.rs +++ b/src/commands/todo.rs @@ -11,15 +11,18 @@ use std::{ }, }; -use chrono::{NaiveDateTime, Utc}; use diesel::{ prelude::*, result::{Error::NotFound, QueryResult}, }; use itertools::Itertools; +use lazy_static::lazy_static; use poise::serenity_prelude::{ ChannelId, CreateEmbed, GuildChannel, Member, MessageBuilder, UserId, }; +use time::{ + format_description, format_description::FormatItem, formatting::Formattable, OffsetDateTime, +}; use tokio_stream::{self as stream, StreamExt}; use crate::{ @@ -27,6 +30,11 @@ use crate::{ Conn, Context, Result, }; +lazy_static! { + static ref TIME_FORMAT: Vec> = + format_description::parse("[year]-[month]-[day] [hour]:[minute]:[second]").unwrap(); +} + struct TodoEntry { id: i32, assignee: Option, @@ -190,7 +198,7 @@ pub async fn add( let data = if content.len() > 1024 { EmbedData::Text("Content can't have more than 1024 characters.".to_string()) } else { - let time = NaiveDateTime::from_timestamp_opt(Utc::now().timestamp(), 0).unwrap(); + let time = OffsetDateTime::now_utc().format(&TIME_FORMAT).unwrap(); let new_id = ctx.data().todo_data.get_id(ctx.channel_id()); let text = content.replace('@', "@\u{200B}").replace('`', "'"); let nickname = match &assignee { @@ -262,7 +270,7 @@ pub async fn delete(ctx: Context<'_>, #[description = "TODO id"] todo_id: i64) - pub async fn complete(ctx: Context<'_>, #[description = "TODO id"] todo_id: i64) -> Result<()> { use crate::schema::todos::dsl::{channel_id, completion_date, id, todo, todos}; - let time = NaiveDateTime::from_timestamp_opt(Utc::now().timestamp(), 0).unwrap(); + let time = OffsetDateTime::now_utc().format(&TIME_FORMAT).unwrap(); let completed: QueryResult = diesel::update(todos) .filter(channel_id.eq(i64::from(ctx.channel_id())))