fix: use naivedate for zodiac signs

This commit is contained in:
Anna 2023-12-18 14:00:51 -05:00
parent 63dbe9c20c
commit 228f7129d1
Signed by: anna
GPG Key ID: D0943384CD9F87D1
1 changed files with 3 additions and 19 deletions

View File

@ -12,7 +12,7 @@ use axum::http::StatusCode;
use axum::routing::{get, post};
use axum::{Router, Json};
use axum::extract::{State, Path};
use chrono::{NaiveDate, Utc, TimeZone, Datelike, Duration};
use chrono::{NaiveDate, Utc, Datelike, Duration};
use rand::distributions::{Alphanumeric, DistString};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
@ -455,17 +455,6 @@ async fn stat_breakdown(
match &stat {
Breakdown::Age => {
for rec in records {
// let date = match NaiveDate::parse_from_str(&rec.key, "%Y-%m-%d")
// .ok()
// .and_then(|date| date.and_hms_opt(0, 0, 0))
// .map(|date| Utc.from_utc_datetime(&date))
// {
// Some(d) => d,
// None => continue,
// };
// let age = question.publish_date - date;
// let years = age.num_days() / 365;
let years: u32 = match rec.key.parse() {
Ok(y) => y,
Err(_) => continue,
@ -490,13 +479,8 @@ async fn stat_breakdown(
}
Breakdown::ZodiacSign => {
for rec in records {
let date = match NaiveDate::parse_from_str(&rec.key, "%Y-%m-%d")
.ok()
.and_then(|date| date.and_hms_opt(0, 0, 0))
.map(|date| Utc.from_utc_datetime(&date))
{
Some(d) => d,
None => continue,
let Ok(date) = NaiveDate::parse_from_str(&rec.key, "%Y-%m-%d") else {
continue;
};
let birthday = (date.month() * 100) + date.day();