Skip to content

Commit 945867d

Browse files
committed
Make time and chrono optional
1 parent bd69769 commit 945867d

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ jobs:
2828
with:
2929
components: clippy
3030
- name: Check Clippy lints (reqwest)
31-
run: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features serde,derive,reqwest-client-rustls -- -D warnings
31+
run: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features chrono,time,serde,derive,reqwest-client-rustls -- -D warnings
3232
- name: Check Clippy lints (surf)
33-
run: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features serde,derive,hyper-client -- -D warnings
33+
run: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features chrono,time,serde,derive,hyper-client -- -D warnings
3434

3535
# this checks that the code is formatted with rustfmt
3636
rustfmt:
@@ -145,7 +145,7 @@ jobs:
145145
run: |
146146
for test in integration_tests{,_v2}
147147
do
148-
cargo test -p influxdb --no-default-features --features 'serde derive ${{matrix.http-backend}}' --no-fail-fast --test $test
148+
cargo test -p influxdb --no-default-features --features 'chrono time serde derive ${{matrix.http-backend}}' --no-fail-fast --test $test
149149
done
150150
151151
# this uses cargo-tarpaulin to inspect the code coverage
@@ -192,7 +192,7 @@ jobs:
192192
cargo tarpaulin -v \
193193
--target-dir target/tarpaulin \
194194
--workspace \
195-
--features serde,derive \
195+
--features chrono,time,serde,derive \
196196
--exclude-files 'derive/*' \
197197
--exclude-files 'target/*' \
198198
--ignore-panics --ignore-tests \

influxdb/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ include = ["src/**/*", "tests/**/*", "Cargo.toml", "LICENSE"]
1313
repository = "https://github.com/influxdb-rs/influxdb-rust"
1414

1515
[dependencies]
16-
chrono = { version = "0.4.23", features = ["serde"], default-features = false }
16+
chrono = { version = "0.4.23", features = ["serde"], default-features = false, optional = true }
1717
futures-util = "0.3.17"
1818
http = "0.2.4"
1919
influxdb_derive = { version = "0.5.1", optional = true }
2020
lazy-regex = "3.1"
2121
reqwest = { version = "0.11.4", default-features = false, optional = true }
22-
surf = { version = "2.2.0", default-features = false, optional = true }
2322
serde = { version = "1.0.186", optional = true }
2423
serde_derive = { version = "1.0.186", optional = true }
2524
serde_json = { version = "1.0.48", optional = true }
25+
surf = { version = "2.2.0", default-features = false, optional = true }
2626
thiserror = "1.0"
27-
time = "0.3.34"
27+
time = { version = "0.3.34", optional = true }
2828

2929
[features]
3030
default = ["serde", "reqwest-client-rustls"]
@@ -41,6 +41,10 @@ reqwest-client-native-tls = ["reqwest", "reqwest/native-tls-alpn"]
4141
reqwest-client-native-tls-vendored = ["reqwest", "reqwest/native-tls-vendored"]
4242
wasm-client = ["surf", "surf/wasm-client"]
4343

44+
# etc
45+
time = ["dep:time"]
46+
chrono = ["dep:chrono"]
47+
4448
[dev-dependencies]
4549
async-std = { version = "1.6.5", features = ["attributes", "tokio02", "tokio1"] }
4650
indoc = "1.0"

influxdb/src/query/mod.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
//! assert!(read_query.is_ok());
2121
//! ```
2222
23-
use chrono::prelude::{DateTime, TimeZone, Utc};
24-
2523
pub mod consts;
2624
mod line_proto_term;
2725
pub mod read_query;
@@ -71,27 +69,32 @@ impl fmt::Display for Timestamp {
7169
}
7270
}
7371

74-
impl From<Timestamp> for DateTime<Utc> {
75-
fn from(ts: Timestamp) -> DateTime<Utc> {
76-
Utc.timestamp_nanos(ts.nanos() as i64)
72+
#[cfg(feature = "chrono")]
73+
impl From<Timestamp> for chrono::prelude::DateTime<chrono::prelude::Utc> {
74+
fn from(ts: Timestamp) -> chrono::prelude::DateTime<chrono::prelude::Utc> {
75+
use chrono::prelude::TimeZone;
76+
chrono::prelude::Utc.timestamp_nanos(ts.nanos() as i64)
7777
}
7878
}
7979

80-
impl<T> From<DateTime<T>> for Timestamp
80+
#[cfg(feature = "chrono")]
81+
impl<T> From<chrono::prelude::DateTime<T>> for Timestamp
8182
where
82-
T: TimeZone,
83+
T: chrono::prelude::TimeZone,
8384
{
84-
fn from(date_time: DateTime<T>) -> Self {
85+
fn from(date_time: chrono::prelude::DateTime<T>) -> Self {
8586
Timestamp::Nanoseconds(date_time.timestamp_nanos_opt().unwrap() as u128)
8687
}
8788
}
8889

90+
#[cfg(feature = "time")]
8991
impl From<Timestamp> for time::OffsetDateTime {
9092
fn from(value: Timestamp) -> Self {
9193
time::OffsetDateTime::from_unix_timestamp_nanos(value.nanos() as i128).unwrap()
9294
}
9395
}
9496

97+
#[cfg(feature = "time")]
9598
impl From<time::OffsetDateTime> for Timestamp {
9699
fn from(value: time::OffsetDateTime) -> Self {
97100
Timestamp::Nanoseconds(value.unix_timestamp_nanos() as u128)
@@ -238,7 +241,6 @@ mod tests {
238241
MILLIS_PER_SECOND, MINUTES_PER_HOUR, NANOS_PER_MICRO, NANOS_PER_MILLI, SECONDS_PER_MINUTE,
239242
};
240243
use crate::query::{Timestamp, ValidQuery};
241-
use chrono::prelude::{DateTime, TimeZone, Utc};
242244
use std::convert::TryInto;
243245
#[test]
244246
fn test_equality_str() {
@@ -255,8 +257,10 @@ mod tests {
255257
fn test_format_for_timestamp_else() {
256258
assert!(format!("{}", Timestamp::Nanoseconds(100)) == "100");
257259
}
260+
#[cfg(feature = "chrono")]
258261
#[test]
259262
fn test_chrono_datetime_from_timestamp_hours() {
263+
use chrono::prelude::*;
260264
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Hours(2).into();
261265
assert_eq!(
262266
Utc.timestamp_nanos(
@@ -267,8 +271,10 @@ mod tests {
267271
datetime_from_timestamp
268272
)
269273
}
274+
#[cfg(feature = "chrono")]
270275
#[test]
271276
fn test_chrono_datetime_from_timestamp_minutes() {
277+
use chrono::prelude::*;
272278
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Minutes(2).into();
273279
assert_eq!(
274280
Utc.timestamp_nanos(
@@ -279,8 +285,10 @@ mod tests {
279285
datetime_from_timestamp
280286
)
281287
}
288+
#[cfg(feature = "chrono")]
282289
#[test]
283290
fn test_chrono_datetime_from_timestamp_seconds() {
291+
use chrono::prelude::*;
284292
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Seconds(2).into();
285293
assert_eq!(
286294
Utc.timestamp_nanos(
@@ -291,29 +299,37 @@ mod tests {
291299
datetime_from_timestamp
292300
)
293301
}
302+
#[cfg(feature = "chrono")]
294303
#[test]
295304
fn test_chrono_datetime_from_timestamp_millis() {
305+
use chrono::prelude::*;
296306
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Milliseconds(2).into();
297307
assert_eq!(
298308
Utc.timestamp_nanos((2 * NANOS_PER_MILLI).try_into().unwrap()),
299309
datetime_from_timestamp
300310
)
301311
}
312+
#[cfg(feature = "chrono")]
302313
#[test]
303314
fn test_chrono_datetime_from_timestamp_nanos() {
315+
use chrono::prelude::*;
304316
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Nanoseconds(1).into();
305317
assert_eq!(Utc.timestamp_nanos(1), datetime_from_timestamp)
306318
}
319+
#[cfg(feature = "chrono")]
307320
#[test]
308321
fn test_chrono_datetime_from_timestamp_micros() {
322+
use chrono::prelude::*;
309323
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Microseconds(2).into();
310324
assert_eq!(
311325
Utc.timestamp_nanos((2 * NANOS_PER_MICRO).try_into().unwrap()),
312326
datetime_from_timestamp
313327
)
314328
}
329+
#[cfg(feature = "chrono")]
315330
#[test]
316331
fn test_timestamp_from_chrono_date() {
332+
use chrono::prelude::*;
317333
let timestamp_from_datetime: Timestamp = Utc
318334
.with_ymd_and_hms(1970, 1, 1, 0, 0, 1)
319335
.single()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy