mirror of
https://github.com/encounter/decomp.dev.git
synced 2026-07-10 03:18:48 -07:00
Improve timeago/date filter error handling
This commit is contained in:
+11
-6
@@ -31,15 +31,20 @@ where S: serde::Serialize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn timeago(value: String) -> String {
|
fn timeago(value: String) -> String {
|
||||||
let value = DateTime::parse_from_rfc3339(&value).unwrap_or_default();
|
let Ok(value) = DateTime::parse_from_rfc3339(&value) else {
|
||||||
let duration = Utc::now().signed_duration_since(value);
|
return "[invalid]".to_string();
|
||||||
timeago::Formatter::new().convert(duration.to_std().unwrap())
|
};
|
||||||
|
let Ok(duration) = Utc::now().signed_duration_since(value).to_std() else {
|
||||||
|
return "[out of range]".to_string();
|
||||||
|
};
|
||||||
|
timeago::Formatter::new().convert(duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn date(value: String, format: Option<String>) -> String {
|
fn date(value: String, format: Option<String>) -> String {
|
||||||
let value = DateTime::parse_from_rfc3339(&value).unwrap_or_default();
|
let Ok(value) = DateTime::parse_from_rfc3339(&value) else {
|
||||||
let format = format.as_deref().unwrap_or("%Y-%m-%d %H:%M:%S %Z");
|
return "[invalid]".to_string();
|
||||||
value.format(format).to_string()
|
};
|
||||||
|
value.format(format.as_deref().unwrap_or("%Y-%m-%d %H:%M:%S %Z")).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format a size in bytes to a human-readable string.
|
/// Format a size in bytes to a human-readable string.
|
||||||
|
|||||||
Reference in New Issue
Block a user