This commit is contained in:
Mateusz Gruszczyński
2026-07-20 20:45:20 +02:00
parent 588e65c6c2
commit 8666583435
3 changed files with 39 additions and 7 deletions
+20 -4
View File
@@ -1,7 +1,7 @@
use argon2::{
password_hash::SaltString, Argon2, PasswordHash, PasswordHasher, PasswordVerifier,
};
use chrono::{DateTime, Utc};
use chrono::{DateTime, NaiveDateTime, Utc};
use rand_core::{OsRng, RngCore};
use serde::Serialize;
use sqlx::FromRow;
@@ -198,9 +198,25 @@ fn hash_password(password: &str) -> String {
}
pub fn normalize_timestamp(value: &str) -> String {
DateTime::parse_from_rfc3339(value)
.map(|dt| dt.with_timezone(&Utc).to_rfc3339())
.unwrap_or_else(|_| value.replace(' ', "T") + "Z")
let value = value.trim();
if let Ok(timestamp) = DateTime::parse_from_rfc3339(value) {
return timestamp.with_timezone(&Utc).to_rfc3339();
}
for format in ["%Y-%m-%d %H:%M:%S%.f%:z", "%Y-%m-%d %H:%M:%S%.f%#z"] {
if let Ok(timestamp) = DateTime::parse_from_str(value, format) {
return timestamp.with_timezone(&Utc).to_rfc3339();
}
}
for format in ["%Y-%m-%d %H:%M:%S%.f", "%Y-%m-%dT%H:%M:%S%.f"] {
if let Ok(timestamp) = NaiveDateTime::parse_from_str(value, format) {
return timestamp.and_utc().to_rfc3339();
}
}
value.to_string()
}
#[derive(Debug, Clone, FromRow)]