Skip to content

Commit

Permalink
bee-common: only deal with UTC time (#804)
Browse files Browse the repository at this point in the history
* Only deal with UTC time

* Fmt
  • Loading branch information
Adam Gleave committed Nov 4, 2021
1 parent e026b4c commit 7427332
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bee-common/bee-common/src/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ macro_rules! log_format {
($target:expr, $level:expr, $message:expr, $target_width:expr, $level_width:expr) => {
format_args!(
"{} {:target_width$} {:level_width$} {}",
crate::time::format(&crate::time::now_local()),
crate::time::format(&crate::time::now_utc()),
$target,
$level,
$message,
Expand Down
8 changes: 2 additions & 6 deletions bee-common/bee-common/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

//! A module that provides common functions for timestamps.

/// Retrieves the current timestamp, including UTC offset. If offset cannot be determined, return UTC time.
pub fn now_local() -> time::OffsetDateTime {
time::OffsetDateTime::now_local().unwrap_or_else(|_| now_utc())
}

/// Retrieves the current timestamp, at UTC.
pub fn now_utc() -> time::OffsetDateTime {
time::OffsetDateTime::now_utc()
Expand All @@ -21,7 +16,8 @@ pub fn from_unix_timestamp(timestamp: i64) -> time::OffsetDateTime {
/// Produces a formatted `String` from a timestamp, displayed as local time.
pub fn format(time: &time::OffsetDateTime) -> String {
// This format string is correct, so unwrapping is fine.
let format_description = time::format_description::parse("[year]-[month]-[day] [hour]:[minute]:[second]").unwrap();
let format_description =
time::format_description::parse("[year]-[month]-[day] [hour]:[minute]:[second] (UTC)").unwrap();

// We know this is correct.
time.format(&format_description).unwrap()
Expand Down

0 comments on commit 7427332

Please sign in to comment.