Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace chrono with time #72

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ serde_json = "1.0.68"
serde_plain = "1.0.0"
surf = { version = "2.3.1", optional = true }

[dependencies.chrono]
[dependencies.time]
default-features = false
features = ["clock", "serde"]
version = "0.4.19"
features = ["std", "serde"]
version = "0.3.30"

[dependencies.reqwest]
default-features = false
Expand Down
11 changes: 5 additions & 6 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::collections::HashMap;
use std::default::Default;

use chrono::Utc;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -29,7 +28,7 @@ pub struct Feature {
pub strategies: Vec<Strategy>,
pub variants: Option<Vec<Variant>>,
#[serde(rename = "createdAt")]
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
pub created_at: Option<time::OffsetDateTime>,
}

#[derive(Clone, Default, Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -85,7 +84,7 @@ pub struct Registration {
#[serde(rename = "sdkVersion")]
pub sdk_version: String,
pub strategies: Vec<String>,
pub started: chrono::DateTime<chrono::Utc>,
pub started: time::OffsetDateTime,
pub interval: u64,
}

Expand All @@ -102,7 +101,7 @@ impl Default for Registration {
instance_id: "".into(),
sdk_version: "unleash-client-rust-0.1.0".into(),
strategies: vec![],
started: Utc::now(),
started: time::OffsetDateTime::now_utc(),
interval: 15 * 1000,
}
}
Expand Down Expand Up @@ -132,8 +131,8 @@ pub struct ToggleMetrics {

#[derive(Serialize, Deserialize, Debug)]
pub struct MetricsBucket {
pub start: chrono::DateTime<chrono::Utc>,
pub stop: chrono::DateTime<chrono::Utc>,
pub start: time::OffsetDateTime,
pub stop: time::OffsetDateTime,
pub toggles: HashMap<String, ToggleMetrics>,
}

Expand Down
5 changes: 2 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::sync::{Arc, Mutex};
use std::time::Duration;

use arc_swap::ArcSwapOption;
use chrono::Utc;
use enum_map::{EnumArray, EnumMap};
use futures_timer::Delay;
use log::{debug, trace, warn};
Expand Down Expand Up @@ -202,7 +201,7 @@ pub struct CachedState<F>
where
F: EnumArray<CachedFeature>,
{
start: chrono::DateTime<chrono::Utc>,
start: time::OffsetDateTime,
// user supplies F defining the features they need
// The default value of F is defined as 'fallback to string lookups'.
features: EnumMap<F, CachedFeature>,
Expand Down Expand Up @@ -668,7 +667,7 @@ where
&self,
features: Vec<Feature>,
) -> Result<Option<Metrics>, Box<dyn std::error::Error + Send + Sync>> {
let now = Utc::now();
let now = time::OffsetDateTime::now_utc();
trace!("memoize: start with {} features", features.len());
let source_strategies = self.strategies.lock().unwrap();
let mut unenumerated_features: HashMap<String, CachedFeature> = HashMap::new();
Expand Down
Loading