Skip to content

Commit ac6f3c7

Browse files
authored
Remove Timestamp::Now (#66)
* Remove Timestamp::Now
1 parent 0566811 commit ac6f3c7

File tree

9 files changed

+53
-33
lines changed

9 files changed

+53
-33
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
### Checklist
66
- [ ] Formatted code using `cargo fmt --all`
77
- [ ] Linted code using clippy `cargo clippy --all-targets --all-features -- -D warnings`
8-
- [ ] Updated README.md using `cargo readme > README.md`
8+
- [ ] Updated README.md using `cargo readme -r influxdb -t ../README.tpl > README.md`
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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
name: Rust
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
48

59
jobs:
10+
readmecheck:
11+
name: README Format Check
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v1
15+
- uses: actions-rs/toolchain@v1
16+
with:
17+
toolchain: nightly
18+
override: true
19+
- run: bash ./auxiliary/update_cargo-readme.sh
20+
- run: bash ./auxiliary/check_readme_consistency.sh
21+
622
style:
723
name: Style Checks (stable/ubuntu-latest)
824
runs-on: ubuntu-latest
@@ -37,7 +53,6 @@ jobs:
3753
integration_test:
3854
name: Integration Tests (stable/ubuntu-latest)
3955
runs-on: ubuntu-latest
40-
needs: [style, compile]
4156
services:
4257
influxdb:
4358
image: influxdb

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- Due to InfluxDb inconsistencies between versions and ambiguities, `Timestamp::Now` has been removed. Please calculate the current timestamp since the epoch yourself and use the other available `Timestamp` values like so:
11+
12+
```
13+
use influxdb::{Timestamp};
14+
use std::time::{SystemTime, UNIX_EPOCH};
15+
let start = SystemTime::now();
16+
let since_the_epoch = start
17+
.duration_since(UNIX_EPOCH)
18+
.expect("Time went backwards")
19+
.as_millis();
20+
let query = Timestamp::Milliseconds(since_the_epoch)
21+
.into_query("weather")
22+
.add_field("temperature", 82);
23+
```
24+
25+
- `WriteQuery` and `ReadQuery` now derive `Debug` and `Clone` ([@jaredwolff](https://github.com/jaredwolff) in [#63](https://github.com/Empty2k12/influxdb-rust/pull/63))
26+
1027
## [0.1.0] - 2020-03-17
1128
1229
This adds `#[derive(InfluxDbWriteable)]` for Structs, fixes escaping for the line-protocol and improves timestamp handling.

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
</a>
2828
</p>
2929

30-
This library is a work in progress. Although we've been using it in production at [OpenVelo](https://openvelo.org/),
31-
we've prioritized features that fit our use cases. This means a feature you might need is not implemented
30+
This library is a work in progress. This means a feature you might need is not implemented
3231
yet or could be handled better.
3332

3433
Pull requests are always welcome. See [Contributing](https://github.com/Empty2k12/influxdb-rust/blob/master/CONTRIBUTING.md) and [Code of Conduct](https://github.com/Empty2k12/influxdb-rust/blob/master/CODE_OF_CONDUCT.md).
@@ -100,5 +99,4 @@ in the repository.
10099
## License
101100

102101
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
103-
104102
@ 2019 Gero Gerke, All rights reserved.

influxdb/src/client/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,22 @@ impl Client {
163163
/// ```rust,no_run
164164
/// use influxdb::{Client, Query, Timestamp};
165165
/// use influxdb::InfluxDbWriteable;
166+
/// use std::time::{SystemTime, UNIX_EPOCH};
166167
///
167168
/// # #[tokio::main]
168169
/// # async fn main() -> Result<(), failure::Error> {
170+
/// let start = SystemTime::now();
171+
/// let since_the_epoch = start
172+
/// .duration_since(UNIX_EPOCH)
173+
/// .expect("Time went backwards")
174+
/// .as_millis();
175+
///
169176
/// let client = Client::new("http://localhost:8086", "test");
170-
/// let query = Timestamp::Now
177+
/// let query = Timestamp::Milliseconds(since_the_epoch)
171178
/// .into_query("weather")
172179
/// .add_field("temperature", 82);
173180
/// let results = client.query(&query).await?;
181+
///
174182
/// # Ok(())
175183
/// # }
176184
/// ```

influxdb/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//! This library is a work in progress. Although we've been using it in production at [OpenVelo](https://openvelo.org/),
2-
//! we've prioritized features that fit our use cases. This means a feature you might need is not implemented
1+
//! This library is a work in progress. This means a feature you might need is not implemented
32
//! yet or could be handled better.
43
//!
54
//! Pull requests are always welcome. See [Contributing](https://github.com/Empty2k12/influxdb-rust/blob/master/CONTRIBUTING.md) and [Code of Conduct](https://github.com/Empty2k12/influxdb-rust/blob/master/CODE_OF_CONDUCT.md).
@@ -71,7 +70,6 @@
7170
//! # License
7271
//!
7372
//! [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
74-
//!
7573
7674
#![allow(clippy::needless_doctest_main)]
7775

influxdb/src/query/mod.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! use influxdb::{Query, Timestamp};
88
//! use influxdb::InfluxDbWriteable;
99
//!
10-
//! let write_query = Timestamp::Now.into_query("measurement")
10+
//! let write_query = Timestamp::Nanoseconds(0).into_query("measurement")
1111
//! .add_field("field1", 5)
1212
//! .add_tag("author", "Gero")
1313
//! .build();
@@ -37,7 +37,6 @@ pub use influxdb_derive::InfluxDbWriteable;
3737

3838
#[derive(PartialEq, Debug, Copy, Clone)]
3939
pub enum Timestamp {
40-
Now,
4140
Nanoseconds(u128),
4241
Microseconds(u128),
4342
Milliseconds(u128),
@@ -50,7 +49,6 @@ impl fmt::Display for Timestamp {
5049
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5150
use Timestamp::*;
5251
match self {
53-
Now => write!(f, ""),
5452
Nanoseconds(ts) | Microseconds(ts) | Milliseconds(ts) | Seconds(ts) | Minutes(ts)
5553
| Hours(ts) => write!(f, "{}", ts),
5654
}
@@ -60,7 +58,6 @@ impl fmt::Display for Timestamp {
6058
impl Into<DateTime<Utc>> for Timestamp {
6159
fn into(self) -> DateTime<Utc> {
6260
match self {
63-
Timestamp::Now => Utc::now(),
6461
Timestamp::Hours(h) => {
6562
let nanos =
6663
h * MINUTES_PER_HOUR * SECONDS_PER_MINUTE * MILLIS_PER_SECOND * NANOS_PER_MILLI;
@@ -125,10 +122,10 @@ pub trait Query {
125122
/// use influxdb::{Query, Timestamp};
126123
/// use influxdb::InfluxDbWriteable;
127124
///
128-
/// let invalid_query = Timestamp::Now.into_query("measurement").build();
125+
/// let invalid_query = Timestamp::Nanoseconds(0).into_query("measurement").build();
129126
/// assert!(invalid_query.is_err());
130127
///
131-
/// let valid_query = Timestamp::Now.into_query("measurement").add_field("myfield1", 11).build();
128+
/// let valid_query = Timestamp::Nanoseconds(0).into_query("measurement").add_field("myfield1", 11).build();
132129
/// assert!(valid_query.is_ok());
133130
/// ```
134131
fn build(&self) -> Result<ValidQuery, Error>;
@@ -218,19 +215,10 @@ mod tests {
218215
);
219216
}
220217
#[test]
221-
fn test_format_for_timestamp_now() {
222-
assert!(format!("{}", Timestamp::Now) == "");
223-
}
224-
#[test]
225218
fn test_format_for_timestamp_else() {
226219
assert!(format!("{}", Timestamp::Nanoseconds(100)) == "100");
227220
}
228221
#[test]
229-
fn test_chrono_datetime_from_timestamp_now() {
230-
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Now.into();
231-
assert_eq!(Utc::now().date(), datetime_from_timestamp.date())
232-
}
233-
#[test]
234222
fn test_chrono_datetime_from_timestamp_hours() {
235223
let datetime_from_timestamp: DateTime<Utc> = Timestamp::Hours(2).into();
236224
assert_eq!(

influxdb/src/query/write_query.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl WriteQuery {
5757
/// use influxdb::{Query, Timestamp};
5858
/// use influxdb::InfluxDbWriteable;
5959
///
60-
/// Timestamp::Now.into_query("measurement").add_field("field1", 5).build();
60+
/// Timestamp::Nanoseconds(0).into_query("measurement").add_field("field1", 5).build();
6161
/// ```
6262
pub fn add_field<S, F>(mut self, field: S, value: F) -> Self
6363
where
@@ -79,7 +79,7 @@ impl WriteQuery {
7979
/// use influxdb::{Query, Timestamp};
8080
/// use influxdb::InfluxDbWriteable;
8181
///
82-
/// Timestamp::Now
82+
/// Timestamp::Nanoseconds(0)
8383
/// .into_query("measurement")
8484
/// .add_tag("field1", 5); // calling `.build()` now would result in a `Err(Error::InvalidQueryError)`
8585
/// ```
@@ -94,7 +94,6 @@ impl WriteQuery {
9494

9595
pub fn get_precision(&self) -> String {
9696
let modifier = match self.timestamp {
97-
Timestamp::Now => "rfc3339",
9897
Timestamp::Nanoseconds(_) => "ns",
9998
Timestamp::Microseconds(_) => "u",
10099
Timestamp::Milliseconds(_) => "ms",
@@ -201,10 +200,7 @@ impl Query for WriteQuery {
201200
measurement = LineProtoTerm::Measurement(&self.measurement).escape(),
202201
tags = tags,
203202
fields = fields,
204-
time = match self.timestamp {
205-
Timestamp::Now => String::from(""),
206-
_ => format!(" {}", self.timestamp),
207-
}
203+
time = format!(" {}", self.timestamp)
208204
)))
209205
}
210206

influxdb/tests/derive_integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async fn test_derive_simple_write() {
5252
create_db(TEST_NAME).await.expect("could not setup db");
5353
let client = create_client(TEST_NAME);
5454
let weather_reading = WeatherReading {
55-
time: Timestamp::Now.into(),
55+
time: Timestamp::Nanoseconds(0).into(),
5656
humidity: 30,
5757
wind_strength: Some(5),
5858
};

0 commit comments

Comments
 (0)