From e5444dde725102e1e7adff26fbdd96b3c3604338 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Wed, 1 Nov 2023 11:40:05 +0100 Subject: [PATCH] fix error on daylight saving time change --- src/ip.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/ip.rs b/src/ip.rs index acfe6c3..0a4ea2d 100644 --- a/src/ip.rs +++ b/src/ip.rs @@ -1,6 +1,7 @@ use crate::config::httpclient; use crate::utils::gethostname; +use chrono::offset::LocalResult; use chrono::prelude::*; use ipnet::IpNet; use lazy_static::lazy_static; @@ -156,16 +157,18 @@ fn parse_date(input: regex::Captures) -> DateTime { hms.push(input.get(i).unwrap().as_str().parse::().unwrap()); } - let date = Local - .with_ymd_and_hms( - ymd[0] as i32, - ymd[1] as u32, - ymd[2] as u32, - hms[0] as u32, - hms[1] as u32, - hms[2] as u32, - ) - .unwrap(); + let date: DateTime = match Local.with_ymd_and_hms( + ymd[0] as i32, + ymd[1] as u32, + ymd[2] as u32, + hms[0] as u32, + hms[1] as u32, + hms[2] as u32, + ) { + LocalResult::Single(s) => s, + LocalResult::Ambiguous(a, _b) => a, + LocalResult::None => Local::now(), + }; date }