Skip to content

Commit

Permalink
fix: human_time mismatch (#2558)
Browse files Browse the repository at this point in the history
* fix: human_time mismatch.

* fix: add comment
  • Loading branch information
QuenKar authored Oct 10, 2023
1 parent 8a5ef82 commit 4fe7e16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/common/time/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,22 @@ impl From<Date> 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> {
NaiveDateTime::from_timestamp_millis(self.0)
}

/// Convert to [common_time::date].
pub fn to_date(&self) -> Option<Date> {
self.to_chrono_datetime().map(|d| Date::from(d.date()))
}
Expand Down
2 changes: 1 addition & 1 deletion src/meta-srv/src/service/admin/node_lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
Expand Down

0 comments on commit 4fe7e16

Please sign in to comment.