Skip to content

Commit a67194d

Browse files
committed
Merge remote-tracking branch 'origin/main' into remove/surf
Conflicts: .github/PULL_REQUEST_TEMPLATE.md .github/workflows/rust.yml README.md influxdb/Cargo.toml
2 parents 4c58cd1 + 9174a4f commit a67194d

File tree

6 files changed

+95
-54
lines changed

6 files changed

+95
-54
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Checklist
66
- [ ] Formatted code using `cargo fmt --all`
7-
- [ ] Linted code using clippy with reqwest feature: `cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features serde,derive,reqwest-client-rustls -- -D warnings`
7+
- [ ] Linted code using clippy with reqwest feature: `cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features chrono,time,serde,derive,reqwest-client-rustls -- -D warnings`
88
- [ ] Updated README.md using `cargo doc2readme -p influxdb --expand-macros`
99
- [ ] Reviewed the diff. Did you leave any print statements or unnecessary comments?
1010
- [ ] Any unfinished work that warrants a separate issue captured in an issue with a TODO code comment

.github/workflows/rust.yml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: README Format Check
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@v5
1616
- uses: docker://codeberg.org/msrd0/cargo-doc2readme:nightly
1717
with:
1818
entrypoint: cargo
@@ -23,21 +23,21 @@ jobs:
2323
name: Style Check (clippy)
2424
runs-on: ubuntu-latest
2525
steps:
26-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v5
2727
- uses: dtolnay/[email protected]
2828
with:
2929
components: clippy
3030
- name: Update Cargo.lock
3131
run: cargo --config 'resolver.incompatible-rust-versions="fallback"' update
3232
- name: Check Clippy lints (reqwest)
33-
run: cargo clippy --manifest-path influxdb/Cargo.toml --locked --all-targets --no-default-features --features serde,derive,reqwest-client-rustls -- -D warnings
33+
run: cargo clippy --manifest-path influxdb/Cargo.toml --locked --all-targets --no-default-features --features chrono,time,serde,derive,reqwest-client-rustls -- -D warnings
3434

3535
# this checks that the code is formatted with rustfmt
3636
rustfmt:
3737
name: Style Checks (rustfmt)
3838
runs-on: ubuntu-latest
3939
steps:
40-
- uses: actions/checkout@v4
40+
- uses: actions/checkout@v5
4141
- uses: dtolnay/rust-toolchain@nightly
4242
with:
4343
components: rustfmt
@@ -70,7 +70,7 @@ jobs:
7070
nightly: false
7171
os: ubuntu-latest
7272
steps:
73-
- uses: actions/checkout@v4
73+
- uses: actions/checkout@v5
7474
- uses: dtolnay/rust-toolchain@master
7575
with:
7676
toolchain: ${{matrix.rust.toolchain}}
@@ -106,8 +106,8 @@ jobs:
106106
key: "${{runner.os}} Rust ${{steps.msrv-toolchain.outputs.cachekey}}"
107107
if: matrix.rust.name == 'MSRV'
108108
# finally we can run tests
109-
- run: cargo test --lib --locked
110-
- run: cargo test --doc --locked
109+
- run: cargo test --lib --locked --features 'chrono time serde derive'
110+
- run: cargo test --doc --locked --features 'chrono time serde derive'
111111

112112
# this tests that all integration tests are successful
113113
integration_tests:
@@ -152,7 +152,7 @@ jobs:
152152
DOCKER_INFLUXDB_INIT_BUCKET: mydb
153153
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: admintoken
154154
steps:
155-
- uses: actions/checkout@v4
155+
- uses: actions/checkout@v5
156156
- uses: dtolnay/rust-toolchain@master
157157
with:
158158
toolchain: ${{matrix.rust.toolchain}}
@@ -166,10 +166,12 @@ jobs:
166166
key: "${{runner.os}} Rust ${{steps.rust-toolchain.outputs.cachekey}}"
167167
- name: Run tests
168168
run: |
169-
for test in integration_tests{,_v2}
170-
do
171-
cargo test -p influxdb --no-default-features --features 'serde derive ${{matrix.http-backend}}' --no-fail-fast --test $test
172-
done
169+
cargo test -p influxdb \
170+
--no-default-features \
171+
--features "serde derive chrono time ${{matrix.http-backend}}" \
172+
--no-fail-fast \
173+
--test integration_tests \
174+
--test integration_tests_v2
173175
174176
# this uses cargo-tarpaulin to inspect the code coverage
175177
coverage:
@@ -192,7 +194,7 @@ jobs:
192194
INFLUXDB_USER_PASSWORD: password
193195

194196
steps:
195-
- uses: actions/checkout@v4
197+
- uses: actions/checkout@v5
196198
- uses: dtolnay/rust-toolchain@stable
197199
id: rust-toolchain
198200
- name: Get Tarpaulin Version
@@ -215,7 +217,7 @@ jobs:
215217
cargo tarpaulin -v \
216218
--target-dir target/tarpaulin \
217219
--workspace \
218-
--features serde,derive \
220+
--features chrono,time,serde,derive \
219221
--exclude-files 'derive/*' \
220222
--exclude-files 'target/*' \
221223
--ignore-panics --ignore-tests \
@@ -237,10 +239,10 @@ jobs:
237239
- coverage
238240
if: github.ref == 'refs/heads/main'
239241
steps:
240-
- uses: actions/checkout@v4
242+
- uses: actions/checkout@v5
241243
with:
242244
ref: gh-pages
243-
- uses: actions/download-artifact@v4
245+
- uses: actions/download-artifact@v5
244246
with:
245247
name: tarpaulin-report
246248
- run: |

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resolver = "2"
77
[workspace.package]
88
authors = ["Gero Gerke <[email protected]>", "Dominic <[email protected]>"]
99
edition = "2018"
10-
rust-version = "1.65"
10+
rust-version = "1.67.1"
1111
license = "MIT"
1212
repository = "https://github.com/influxdb-rs/influxdb-rust"
1313

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
<a href="https://www.rust-lang.org/en-US/">
2626
<img src="https://img.shields.io/badge/Made%20with-Rust-orange.svg" alt='Build with Rust' />
2727
</a>
28-
<a href="https://github.com/rust-lang/rust/releases/tag/1.65.0">
29-
<img src="https://img.shields.io/badge/rustc-1.65.0+-yellow.svg" alt='Minimum Rust Version: 1.65.0' />
28+
<a href="https://github.com/rust-lang/rust/releases/tag/1.67.1">
29+
<img src="https://img.shields.io/badge/rustc-1.67.1+-yellow.svg" alt='Minimum Rust Version: 1.67.1' />
3030
</a>
3131
</p>
3232

influxdb/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repository.workspace = true
1717
workspace = true
1818

1919
[dependencies]
20-
chrono = { version = "0.4.23", features = ["serde"], default-features = false }
20+
chrono = { version = "0.4.23", features = ["serde"], default-features = false, optional = true }
2121
futures-util = "0.3.17"
2222
http = "0.2.4"
2323
influxdb_derive = { version = "0.5.1", optional = true }
@@ -26,7 +26,9 @@ reqwest = { version = "0.11.4", default-features = false }
2626
serde = { version = "1.0.186", optional = true }
2727
serde_derive = { version = "1.0.186", optional = true }
2828
serde_json = { version = "1.0.48", optional = true }
29+
surf = { version = "2.2.0", default-features = false, optional = true }
2930
thiserror = "1.0"
31+
time = { version = "0.3.39", optional = true }
3032

3133
[features]
3234
default = ["serde", "reqwest-client-rustls"]
@@ -38,6 +40,10 @@ reqwest-client-rustls = ["reqwest/rustls-tls-webpki-roots"]
3840
reqwest-client-native-tls = ["reqwest/native-tls-alpn"]
3941
reqwest-client-native-tls-vendored = ["reqwest/native-tls-vendored"]
4042

43+
# etc
44+
time = ["dep:time"]
45+
chrono = ["dep:chrono"]
46+
4147
[dev-dependencies]
4248
indoc = "1.0"
4349
tokio = { version = "1.7", features = ["macros", "rt-multi-thread"] }

influxdb/src/query/mod.rs

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
//! assert!(read_query.is_ok());
2121
//! ```
2222
23-
use chrono::prelude::{DateTime, TimeZone, Utc};
24-
use std::convert::TryInto;
25-
2623
pub mod consts;
2724
mod line_proto_term;
2825
pub mod read_query;
@@ -47,6 +44,21 @@ pub enum Timestamp {
4744
Hours(u128),
4845
}
4946

47+
impl Timestamp {
48+
pub fn nanos(&self) -> u128 {
49+
match self {
50+
Timestamp::Hours(h) => {
51+
h * MINUTES_PER_HOUR * SECONDS_PER_MINUTE * MILLIS_PER_SECOND * NANOS_PER_MILLI
52+
}
53+
Timestamp::Minutes(m) => m * SECONDS_PER_MINUTE * MILLIS_PER_SECOND * NANOS_PER_MILLI,
54+
Timestamp::Seconds(s) => s * MILLIS_PER_SECOND * NANOS_PER_MILLI,
55+
Timestamp::Milliseconds(millis) => millis * NANOS_PER_MILLI,
56+
Timestamp::Microseconds(micros) => micros * NANOS_PER_MICRO,
57+
Timestamp::Nanoseconds(nanos) => *nanos,
58+
}
59+
}
60+
}
61+
5062
impl fmt::Display for Timestamp {
5163
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5264
use Timestamp::*;
@@ -57,44 +69,52 @@ impl fmt::Display for Timestamp {
5769
}
5870
}
5971

60-
impl From<Timestamp> for DateTime<Utc> {
61-
fn from(ts: Timestamp) -> DateTime<Utc> {
62-
match ts {
63-
Timestamp::Hours(h) => {
64-
let nanos =
65-
h * MINUTES_PER_HOUR * SECONDS_PER_MINUTE * MILLIS_PER_SECOND * NANOS_PER_MILLI;
66-
Utc.timestamp_nanos(nanos.try_into().unwrap())
67-
}
68-
Timestamp::Minutes(m) => {
69-
let nanos = m * SECONDS_PER_MINUTE * MILLIS_PER_SECOND * NANOS_PER_MILLI;
70-
Utc.timestamp_nanos(nanos.try_into().unwrap())
71-
}
72-
Timestamp::Seconds(s) => {
73-
let nanos = s * MILLIS_PER_SECOND * NANOS_PER_MILLI;
74-
Utc.timestamp_nanos(nanos.try_into().unwrap())
75-
}
76-
Timestamp::Milliseconds(millis) => {
77-
let nanos = millis * NANOS_PER_MILLI;
78-
Utc.timestamp_nanos(nanos.try_into().unwrap())
79-
}
80-
Timestamp::Nanoseconds(nanos) => Utc.timestamp_nanos(nanos.try_into().unwrap()),
81-
Timestamp::Microseconds(micros) => {
82-
let nanos = micros * NANOS_PER_MICRO;
83-
Utc.timestamp_nanos(nanos.try_into().unwrap())
84-
}
85-
}
72+
#[cfg(feature = "chrono")]
73+
impl From<Timestamp> for chrono::DateTime<chrono::Utc> {
74+
fn from(ts: Timestamp) -> chrono::DateTime<chrono::Utc> {
75+
use chrono::TimeZone as _;
76+
chrono::Utc.timestamp_nanos(ts.nanos() as i64)
8677
}
8778
}
8879

89-
impl<T> From<DateTime<T>> for Timestamp
80+
#[cfg(feature = "chrono")]
81+
impl<T> From<chrono::DateTime<T>> for Timestamp
9082
where
91-
T: TimeZone,
83+
T: chrono::TimeZone,
9284
{
93-
fn from(date_time: DateTime<T>) -> Self {
85+
fn from(date_time: chrono::DateTime<T>) -> Self {
9486
Timestamp::Nanoseconds(date_time.timestamp_nanos_opt().unwrap() as u128)
9587
}
9688
}
9789

90+
#[cfg(feature = "time")]
91+
impl From<Timestamp> for time::UtcDateTime {
92+
fn from(value: Timestamp) -> Self {
93+
time::UtcDateTime::from_unix_timestamp_nanos(value.nanos() as i128).unwrap()
94+
}
95+
}
96+
97+
#[cfg(feature = "time")]
98+
impl From<time::UtcDateTime> for Timestamp {
99+
fn from(value: time::UtcDateTime) -> Self {
100+
Timestamp::Nanoseconds(value.unix_timestamp_nanos() as u128)
101+
}
102+
}
103+
104+
#[cfg(feature = "time")]
105+
impl From<Timestamp> for time::OffsetDateTime {
106+
fn from(value: Timestamp) -> Self {
107+
time::OffsetDateTime::from_unix_timestamp_nanos(value.nanos() as i128).unwrap()
108+
}
109+
}
110+
111+
#[cfg(feature = "time")]
112+
impl From<time::OffsetDateTime> for Timestamp {
113+
fn from(value: time::OffsetDateTime) -> Self {
114+
Timestamp::Nanoseconds(value.unix_timestamp_nanos() as u128)
115+
}
116+
}
117+
98118
pub trait Query {
99119
/// Builds valid InfluxSQL which can be run against the Database.
100120
/// In case no fields have been specified, it will return an error,
@@ -235,7 +255,6 @@ mod tests {
235255
MILLIS_PER_SECOND, MINUTES_PER_HOUR, NANOS_PER_MICRO, NANOS_PER_MILLI, SECONDS_PER_MINUTE,
236256
};
237257
use crate::query::{Timestamp, ValidQuery};
238-
use chrono::prelude::{DateTime, TimeZone, Utc};
239258
use std::convert::TryInto;
240259
#[test]
241260
fn test_equality_str() {
@@ -252,8 +271,10 @@ mod tests {
252271
fn test_format_for_timestamp_else() {
253272
assert!(format!("{}", Timestamp::Nanoseconds(100)) == "100");
254273
}
274+
#[cfg(feature = "chrono")]
255275
#[test]
256276
fn test_chrono_datetime_from_timestamp_hours() {
277+
use chrono::prelude::*;
257278
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Hours(2).into();
258279
assert_eq!(
259280
Utc.timestamp_nanos(
@@ -264,8 +285,10 @@ mod tests {
264285
datetime_from_timestamp
265286
)
266287
}
288+
#[cfg(feature = "chrono")]
267289
#[test]
268290
fn test_chrono_datetime_from_timestamp_minutes() {
291+
use chrono::prelude::*;
269292
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Minutes(2).into();
270293
assert_eq!(
271294
Utc.timestamp_nanos(
@@ -276,8 +299,10 @@ mod tests {
276299
datetime_from_timestamp
277300
)
278301
}
302+
#[cfg(feature = "chrono")]
279303
#[test]
280304
fn test_chrono_datetime_from_timestamp_seconds() {
305+
use chrono::prelude::*;
281306
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Seconds(2).into();
282307
assert_eq!(
283308
Utc.timestamp_nanos(
@@ -288,29 +313,37 @@ mod tests {
288313
datetime_from_timestamp
289314
)
290315
}
316+
#[cfg(feature = "chrono")]
291317
#[test]
292318
fn test_chrono_datetime_from_timestamp_millis() {
319+
use chrono::prelude::*;
293320
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Milliseconds(2).into();
294321
assert_eq!(
295322
Utc.timestamp_nanos((2 * NANOS_PER_MILLI).try_into().unwrap()),
296323
datetime_from_timestamp
297324
)
298325
}
326+
#[cfg(feature = "chrono")]
299327
#[test]
300328
fn test_chrono_datetime_from_timestamp_nanos() {
329+
use chrono::prelude::*;
301330
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Nanoseconds(1).into();
302331
assert_eq!(Utc.timestamp_nanos(1), datetime_from_timestamp)
303332
}
333+
#[cfg(feature = "chrono")]
304334
#[test]
305335
fn test_chrono_datetime_from_timestamp_micros() {
336+
use chrono::prelude::*;
306337
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Microseconds(2).into();
307338
assert_eq!(
308339
Utc.timestamp_nanos((2 * NANOS_PER_MICRO).try_into().unwrap()),
309340
datetime_from_timestamp
310341
)
311342
}
343+
#[cfg(feature = "chrono")]
312344
#[test]
313345
fn test_timestamp_from_chrono_date() {
346+
use chrono::prelude::*;
314347
let timestamp_from_datetime: Timestamp = Utc
315348
.with_ymd_and_hms(1970, 1, 1, 0, 0, 1)
316349
.single()

0 commit comments

Comments
 (0)