Skip to content

Commit

Permalink
[fix] move from chrono to time (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
seqre committed Feb 24, 2023
1 parent 6069835 commit a0abd21
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
39 changes: 9 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
14 changes: 11 additions & 3 deletions src/commands/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,30 @@ 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::{
models::{NewTodo, Todo},
Conn, Context, Result,
};

lazy_static! {
static ref TIME_FORMAT: Vec<FormatItem<'static>> =
format_description::parse("[year]-[month]-[day] [hour]:[minute]:[second]").unwrap();
}

struct TodoEntry {
id: i32,
assignee: Option<String>,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String> = diesel::update(todos)
.filter(channel_id.eq(i64::from(ctx.channel_id())))
Expand Down

0 comments on commit a0abd21

Please sign in to comment.