From 6f3c4f63bfc9e7568981c60e75efb2eb532afa08 Mon Sep 17 00:00:00 2001 From: QuenKar <47681251+QuenKar@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:48:19 +0800 Subject: [PATCH 1/2] fix: human_time mismatch. --- src/meta-srv/src/service/admin/node_lease.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta-srv/src/service/admin/node_lease.rs b/src/meta-srv/src/service/admin/node_lease.rs index 3655cd3aae11..4b94674a25eb 100644 --- a/src/meta-srv/src/service/admin/node_lease.rs +++ b/src/meta-srv/src/service/admin/node_lease.rs @@ -43,7 +43,7 @@ impl HttpHandler for NodeLeaseHandler { .into_iter() .map(|(k, v)| HumanLease { name: k, - human_time: common_time::DateTime::new(v.timestamp_millis / 1000).to_string(), + human_time: common_time::DateTime::new(v.timestamp_millis).to_string(), lease: v, }) .collect::>(); From d9dab4bdaa260c5ad3f8d84626697a848b5e6688 Mon Sep 17 00:00:00 2001 From: QuenKar <47681251+QuenKar@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:10:30 +0800 Subject: [PATCH 2/2] fix: add comment --- src/common/time/src/datetime.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/common/time/src/datetime.rs b/src/common/time/src/datetime.rs index 39f451db8e11..451dc57cf7ed 100644 --- a/src/common/time/src/datetime.rs +++ b/src/common/time/src/datetime.rs @@ -93,18 +93,22 @@ impl From for DateTime { } impl DateTime { - pub fn new(val: i64) -> Self { - Self(val) + /// Create a new [DateTime] from milliseconds elapsed since "1970-01-01 00:00:00 UTC" (UNIX Epoch). + pub fn new(millis: i64) -> Self { + Self(millis) } + /// Get the milliseconds elapsed since "1970-01-01 00:00:00 UTC" (UNIX Epoch). pub fn val(&self) -> i64 { self.0 } + /// Convert to [NaiveDateTime]. pub fn to_chrono_datetime(&self) -> Option { NaiveDateTime::from_timestamp_millis(self.0) } + /// Convert to [common_time::date]. pub fn to_date(&self) -> Option { self.to_chrono_datetime().map(|d| Date::from(d.date())) }