use non-panicky timestamp_opt where appropriate
by either printing the original, out-of-range timestamp as-is, or bailing with a proper error message instead of panicking. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
committed by
Dietmar Maurer
parent
151acf5d96
commit
833eca6d2f
@ -1,6 +1,6 @@
|
||||
use anyhow::{Error};
|
||||
use serde_json::Value;
|
||||
use chrono::{Local, TimeZone};
|
||||
use chrono::{Local, TimeZone, LocalResult};
|
||||
|
||||
pub fn strip_server_file_expenstion(name: &str) -> String {
|
||||
|
||||
@ -25,8 +25,11 @@ pub fn render_epoch(value: &Value, _record: &Value) -> Result<String, Error> {
|
||||
if value.is_null() { return Ok(String::new()); }
|
||||
let text = match value.as_i64() {
|
||||
Some(epoch) => {
|
||||
Local.timestamp(epoch, 0).format("%c").to_string()
|
||||
}
|
||||
match Local.timestamp_opt(epoch, 0) {
|
||||
LocalResult::Single(epoch) => epoch.format("%c").to_string(),
|
||||
_ => epoch.to_string(),
|
||||
}
|
||||
},
|
||||
None => {
|
||||
value.to_string()
|
||||
}
|
||||
|
Reference in New Issue
Block a user