Merge pull request #7712 from influxdata/cn/bye-chrono-time
fix: Use only humantime; get rid of chrono-englishpull/24376/head
commit
78ad824705
|
@ -37,10 +37,6 @@ workspace-members = [
|
|||
"influxdb-line-protocol",
|
||||
"influxdb2_client",
|
||||
"iox_data_generator",
|
||||
# The garbage collector uses chrono-english which needlessly
|
||||
# brings in chrono with the default features. This exclusion can
|
||||
# likely be removed if they publish a version without that.
|
||||
"garbage_collector",
|
||||
"mutable_batch_tests",
|
||||
]
|
||||
third-party = [
|
||||
|
|
|
@ -799,15 +799,6 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chrono-english"
|
||||
version = "0.1.6"
|
||||
source = "git+https://github.com/stevedonovan/chrono-english.git?rev=def5941ebee24b55e1174eb18ab33d91603f907a#def5941ebee24b55e1174eb18ab33d91603f907a"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"scanlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chrono-tz"
|
||||
version = "0.8.2"
|
||||
|
@ -2055,6 +2046,7 @@ dependencies = [
|
|||
"tokio-stream",
|
||||
"tokio-util",
|
||||
"uuid",
|
||||
"workspace-hack",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2864,7 +2856,6 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bytes",
|
||||
"chrono",
|
||||
"chrono-english",
|
||||
"clap 4.2.5",
|
||||
"criterion",
|
||||
"datafusion_util",
|
||||
|
@ -4911,12 +4902,6 @@ dependencies = [
|
|||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scanlex"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "088c5d71572124929ea7549a8ce98e1a6fd33d0a38367b09027b382e67c033db"
|
||||
|
||||
[[package]]
|
||||
name = "schema"
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -115,7 +115,6 @@ license = "MIT OR Apache-2.0"
|
|||
[workspace.dependencies]
|
||||
arrow = { version = "38.0.0" }
|
||||
arrow-flight = { version = "38.0.0" }
|
||||
chrono-english = { git = "https://github.com/stevedonovan/chrono-english.git", rev = "def5941ebee24b55e1174eb18ab33d91603f907a" }
|
||||
datafusion = { git = "https://github.com/apache/arrow-datafusion.git", rev="451e81eafe5e404de50f6ede1bebf25ed90f5eb0", default-features = false }
|
||||
datafusion-proto = { git = "https://github.com/apache/arrow-datafusion.git", rev="451e81eafe5e404de50f6ede1bebf25ed90f5eb0" }
|
||||
hashbrown = { version = "0.13.2" }
|
||||
|
@ -125,8 +124,6 @@ tonic-build = { version = "0.9.2" }
|
|||
tonic-health = { version = "0.9.2" }
|
||||
tonic-reflection = { version = "0.9.2" }
|
||||
|
||||
|
||||
|
||||
# This profile optimizes for runtime performance and small binary size at the expense of longer
|
||||
# build times. It's most suitable for final release builds.
|
||||
[profile.release]
|
||||
|
|
|
@ -56,5 +56,8 @@ deny = [
|
|||
# If you're hitting this, you might want to take a look at what new
|
||||
# dependencies you have introduced and check if there's a way to depend on
|
||||
# rustls instead of OpenSSL (tip: check the crate's feature flags).
|
||||
{ name = "openssl-sys" }
|
||||
{ name = "openssl-sys" },
|
||||
# We've decided to use the `humantime` crate to parse and generate friendly time formats; use
|
||||
# that rather than chrono-english.
|
||||
{ name = "chrono-english" },
|
||||
]
|
||||
|
|
|
@ -21,6 +21,7 @@ tokio = { version = "1", features = ["macros", "rt", "sync"] }
|
|||
tokio-stream = "0.1"
|
||||
tokio-util = { version = "0.7.8" }
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
workspace-hack = { version = "0.1", path = "../workspace-hack" }
|
||||
|
||||
[dev-dependencies]
|
||||
bytes = "1.4"
|
||||
|
|
|
@ -9,7 +9,6 @@ license.workspace = true
|
|||
[dependencies]
|
||||
bytes = "1.4"
|
||||
chrono = { version = "0.4", default-features = false }
|
||||
chrono-english = { workspace = true }
|
||||
clap = { version = "4", features = ["derive", "env", "cargo"] }
|
||||
datafusion_util = { path = "../datafusion_util" }
|
||||
futures = "0.3"
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
)]
|
||||
|
||||
use chrono::prelude::*;
|
||||
use chrono_english::{parse_date_string, Dialect};
|
||||
use iox_data_generator::{specification::DataSpec, write::PointsWriterBuilder};
|
||||
use std::{
|
||||
fs::File,
|
||||
|
@ -38,7 +37,7 @@ Examples:
|
|||
|
||||
# Generate data points starting from an hour ago until now, generating the historical data as
|
||||
# fast as possible. Then generate data according to the sampling interval until terminated.
|
||||
iox_data_generator -s spec.toml -o lp --start "1 hr ago" --continue
|
||||
iox_data_generator -s spec.toml -o lp --start "1 hr" --continue
|
||||
|
||||
Logging:
|
||||
Use the RUST_LOG environment variable to configure the desired logging level.
|
||||
|
@ -103,14 +102,14 @@ struct Config {
|
|||
/// The date and time at which to start the timestamps of the generated data.
|
||||
///
|
||||
/// Can be an exact datetime like `2020-01-01T01:23:45-05:00` or a fuzzy
|
||||
/// specification like `1 hour ago`. If not specified, defaults to no.
|
||||
/// specification like `1 hour`. If not specified, defaults to no.
|
||||
#[clap(long, action)]
|
||||
start: Option<String>,
|
||||
|
||||
/// The date and time at which to stop the timestamps of the generated data.
|
||||
///
|
||||
/// Can be an exact datetime like `2020-01-01T01:23:45-05:00` or a fuzzy
|
||||
/// specification like `1 hour ago`. If not specified, defaults to now.
|
||||
/// specification like `1 hour`. If not specified, defaults to now.
|
||||
#[clap(long, action)]
|
||||
end: Option<String>,
|
||||
|
||||
|
@ -222,7 +221,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
fn datetime_nanoseconds(arg: Option<&str>, now: DateTime<Local>) -> Option<i64> {
|
||||
arg.map(|s| {
|
||||
let datetime = parse_date_string(s, now, Dialect::Us).expect("Could not parse time");
|
||||
let datetime = humantime::parse_rfc3339(s)
|
||||
.map(Into::into)
|
||||
.unwrap_or_else(|_| {
|
||||
let std_duration = humantime::parse_duration(s).expect("Could not parse time");
|
||||
let chrono_duration = chrono::Duration::from_std(std_duration)
|
||||
.expect("Could not convert std::time::Duration to chrono::Duration");
|
||||
now - chrono_duration
|
||||
});
|
||||
|
||||
datetime.timestamp_nanos()
|
||||
})
|
||||
}
|
||||
|
@ -238,16 +245,15 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore] // TODO: I think chrono-english isn't handling timezones the way I'd expect
|
||||
fn rfc3339() {
|
||||
let ns = datetime_nanoseconds(Some("2020-01-01T01:23:45-05:00"), Local::now());
|
||||
assert_eq!(ns, Some(1577859825000000000));
|
||||
let ns = datetime_nanoseconds(Some("2020-01-01T01:23:45Z"), Local::now());
|
||||
assert_eq!(ns, Some(1_577_841_825_000_000_000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relative() {
|
||||
let fixed_now = Local::now();
|
||||
let ns = datetime_nanoseconds(Some("1hr ago"), fixed_now);
|
||||
let ns = datetime_nanoseconds(Some("1hr"), fixed_now);
|
||||
let expected = (fixed_now - chrono::Duration::hours(1)).timestamp_nanos();
|
||||
assert_eq!(ns, Some(expected));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue