Skip to content

Commit

Permalink
move from chrono to time crate
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Feb 11, 2022
1 parent a0de725 commit 704f635
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 33 deletions.
67 changes: 52 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blockchain/chain_sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interpreter = { path = "../../vm/interpreter/" }
message_pool = { path = "../message_pool" }
networks = { path = "../../types/networks" }
forest_json_utils = { path = "../../utils/json_utils", version = "0.1" }
chrono = { version = "0.4", features = ["serde"] }
time = { version = "0.3", features = ["serde"] }
prometheus = { version = "0.12.0", features = ["process"] }
lazy_static = "1.4.0"

Expand Down
22 changes: 11 additions & 11 deletions blockchain/chain_sync/src/sync_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use blocks::{tipset::tipset_json::TipsetJsonRef, Tipset};
use chrono::{DateTime, Duration, Utc};
use clock::ChainEpoch;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;
use std::sync::Arc;
use time::{Duration, OffsetDateTime};

/// Current state of the ChainSyncer using the ChainExchange protocol.
#[derive(PartialEq, Debug, Clone, Copy)]
Expand Down Expand Up @@ -83,8 +83,8 @@ pub struct SyncState {
stage: SyncStage,
epoch: ChainEpoch,

start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
start: Option<OffsetDateTime>,
end: Option<OffsetDateTime>,
message: String,
}

Expand All @@ -94,7 +94,7 @@ impl SyncState {
*self = Self {
target: Some(target),
base: Some(base),
start: Some(Utc::now()),
start: Some(OffsetDateTime::now_utc()),
..Default::default()
}
}
Expand Down Expand Up @@ -123,7 +123,7 @@ impl SyncState {
/// Returns `None` if syncing has not started
pub fn get_elapsed_time(&self) -> Option<Duration> {
if let Some(start) = self.start {
let elapsed_time = Utc::now() - start;
let elapsed_time = OffsetDateTime::now_utc() - start;
Some(elapsed_time)
} else {
None
Expand All @@ -133,7 +133,7 @@ impl SyncState {
/// Sets the sync stage for the syncing state. If setting to complete, sets end timer to now.
pub fn set_stage(&mut self, stage: SyncStage) {
if let SyncStage::Complete = stage {
self.end = Some(Utc::now());
self.end = Some(OffsetDateTime::now_utc());
}
self.stage = stage;
}
Expand All @@ -147,7 +147,7 @@ impl SyncState {
pub fn error(&mut self, err: String) {
self.message = err;
self.stage = SyncStage::Error;
self.end = Some(Utc::now());
self.end = Some(OffsetDateTime::now_utc());
}
}

Expand All @@ -165,8 +165,8 @@ impl Serialize for SyncState {
stage: SyncStage,
epoch: ChainEpoch,

start: &'a Option<DateTime<Utc>>,
end: &'a Option<DateTime<Utc>>,
start: &'a Option<OffsetDateTime>,
end: &'a Option<OffsetDateTime>,
message: &'a str,
}

Expand Down Expand Up @@ -200,8 +200,8 @@ impl<'de> Deserialize<'de> for SyncState {
stage: SyncStage,
epoch: ChainEpoch,

start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
start: Option<OffsetDateTime>,
end: Option<OffsetDateTime>,
message: String,
}

Expand Down
2 changes: 1 addition & 1 deletion forest/src/cli/sync_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl SyncCommands {
println!("Height:\t{}", state.epoch());

if let Some(duration) = elapsed_time {
println!("Elapsed time:\t{}s", duration.num_seconds());
println!("Elapsed time:\t{}s", duration.whole_seconds());
}
}
Self::CheckBad { cid } => {
Expand Down
2 changes: 1 addition & 1 deletion node/clock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2018"
repository = "https://github.com/ChainSafe/forest"

[dependencies]
chrono = "0.4.9"
time = "0.3"
2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ features = ["json"]

[dependencies]
address = { package = "forest_address", features = ["json"], version = "0.3" }
chrono = "0.4.9"
time = { version = "0.3", features = ["serde", "serde-well-known" ] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.56"
commcid = { path = "../utils/commcid", version = "0.1.1", optional = true }
Expand Down
7 changes: 4 additions & 3 deletions types/src/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

use super::SectorSize;
use address::{json as addr_json, Address};
use chrono::Utc;
use num_bigint::bigint_ser::json as bigint_json;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use vm::TokenAmount;

/// Different account variants. This is used with genesis utils to define the possible
Expand Down Expand Up @@ -54,7 +54,8 @@ pub struct Template {
pub accounts: Vec<Actor>,
pub miners: Vec<Miner>,
pub network_name: String,
timestamp: String,
#[serde(with = "time::serde::rfc3339")]
timestamp: OffsetDateTime,
}

impl Template {
Expand All @@ -63,7 +64,7 @@ impl Template {
accounts: Vec::new(),
miners: Vec::new(),
network_name,
timestamp: Utc::now().to_rfc3339(),
timestamp: OffsetDateTime::now_utc(),
}
}
}

0 comments on commit 704f635

Please sign in to comment.