From 4f796e788cd36e03c4e658097cf2ddcf27cbb2c7 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Fri, 6 Jan 2023 23:38:38 +0900 Subject: [PATCH] Clippy --- plume-models/src/posts.rs | 2 +- plume-models/src/search/query.rs | 10 +++++----- src/routes/search.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 74ff21d8..b78690d9 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -756,7 +756,7 @@ impl FromId for Post { let timestamp_secs = published.unix_timestamp(); let timestamp_nanos = published.unix_timestamp_nanos() - (timestamp_secs as i128) * 1000i128 * 1000i128 * 1000i128; - NaiveDateTime::from_timestamp(timestamp_secs, timestamp_nanos as u32) + NaiveDateTime::from_timestamp_opt(timestamp_secs, timestamp_nanos as u32).unwrap() }), subtitle: article .summary() diff --git a/plume-models/src/search/query.rs b/plume-models/src/search/query.rs index a2c4f252..edab5711 100644 --- a/plume-models/src/search/query.rs +++ b/plume-models/src/search/query.rs @@ -94,7 +94,7 @@ macro_rules! gen_to_string { )* $( for val in &$self.$date { - $result.push_str(&format!("{}:{} ", stringify!($date), NaiveDate::from_num_days_from_ce(*val as i32).format("%Y-%m-%d"))); + $result.push_str(&format!("{}:{} ", stringify!($date), NaiveDate::from_num_days_from_ce_opt(*val as i32).unwrap().format("%Y-%m-%d"))); } )* } @@ -182,10 +182,10 @@ impl PlumeQuery { // if at least one range bound is provided let after = self .after - .unwrap_or_else(|| i64::from(NaiveDate::from_ymd(2000, 1, 1).num_days_from_ce())); + .unwrap_or_else(|| i64::from(NaiveDate::from_ymd_opt(2000, 1, 1).unwrap().num_days_from_ce())); let before = self .before - .unwrap_or_else(|| i64::from(Utc::today().num_days_from_ce())); + .unwrap_or_else(|| i64::from(Utc::now().date_naive().num_days_from_ce())); let field = Searcher::schema().get_field("creation_date").unwrap(); let range = RangeQuery::new_i64_bounds(field, Bound::Included(after), Bound::Included(before)); @@ -202,7 +202,7 @@ impl PlumeQuery { pub fn before(&mut self, date: &D) -> &mut Self { let before = self .before - .unwrap_or_else(|| i64::from(Utc::today().num_days_from_ce())); + .unwrap_or_else(|| i64::from(Utc::now().date_naive().num_days_from_ce())); self.before = Some(cmp::min(before, i64::from(date.num_days_from_ce()))); self } @@ -211,7 +211,7 @@ impl PlumeQuery { pub fn after(&mut self, date: &D) -> &mut Self { let after = self .after - .unwrap_or_else(|| i64::from(NaiveDate::from_ymd(2000, 1, 1).num_days_from_ce())); + .unwrap_or_else(|| i64::from(NaiveDate::from_ymd_opt(2000, 1, 1).unwrap().num_days_from_ce())); self.after = Some(cmp::max(after, i64::from(date.num_days_from_ce()))); self } diff --git a/src/routes/search.rs b/src/routes/search.rs index 33d8443f..0807b792 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -65,7 +65,7 @@ pub fn search(query: Option>, conn: DbConn, rockets: PlumeRock if str_query.is_empty() { render!(search::index( &(&conn, &rockets).to_context(), - &format!("{}", Utc::today().format("%Y-%m-d")) + &format!("{}", Utc::now().date_naive().format("%Y-%m-d")) )) } else { let res = rockets