Skip to content

Commit ec500b9

Browse files
committed
remove chrono
closes #1232
1 parent ba3d22e commit ec500b9

File tree

14 files changed

+66
-59
lines changed

14 files changed

+66
-59
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quickwit-cli/src/index.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use std::time::{Duration, Instant};
2424
use std::{env, fmt, io};
2525

2626
use anyhow::{bail, Context};
27-
use chrono::Utc;
2827
use clap::{arg, ArgMatches, Command};
2928
use colored::Colorize;
3029
use humantime::format_duration;
@@ -48,6 +47,7 @@ use quickwit_search::{single_node_search, SearchResponseRest};
4847
use quickwit_storage::{load_file, quickwit_storage_uri_resolver};
4948
use quickwit_telemetry::payload::TelemetryEvent;
5049
use thousands::Separable;
50+
use time::OffsetDateTime;
5151
use tracing::{debug, info, Level};
5252

5353
use crate::stats::{mean, percentile, std_deviation};
@@ -748,8 +748,8 @@ pub async fn create_index_cli(args: CreateIndexArgs) -> anyhow::Result<()> {
748748
doc_mapping: index_config.doc_mapping,
749749
indexing_settings: index_config.indexing_settings,
750750
search_settings: index_config.search_settings,
751-
create_timestamp: Utc::now().timestamp(),
752-
update_timestamp: Utc::now().timestamp(),
751+
create_timestamp: OffsetDateTime::now_utc().unix_timestamp(),
752+
update_timestamp: OffsetDateTime::now_utc().unix_timestamp(),
753753
};
754754
create_index(&quickwit_config.metastore_uri(), index_metadata.clone()).await?;
755755
println!("Index `{}` successfully created.", index_config.index_id);
@@ -1066,12 +1066,12 @@ fn display_statistics(
10661066
throughput_calculator: &mut ThroughputCalculator,
10671067
statistics: &IndexingStatistics,
10681068
) -> anyhow::Result<()> {
1069-
let elapsed_duration = chrono::Duration::from_std(throughput_calculator.elapsed_time())?;
1069+
let elapsed_duration = time::Duration::try_from(throughput_calculator.elapsed_time())?;
10701070
let elapsed_time = format!(
10711071
"{:02}:{:02}:{:02}",
1072-
elapsed_duration.num_hours(),
1073-
elapsed_duration.num_minutes() % 60,
1074-
elapsed_duration.num_seconds() % 60
1072+
elapsed_duration.whole_hours(),
1073+
elapsed_duration.whole_minutes() % 60,
1074+
elapsed_duration.whole_seconds() % 60
10751075
);
10761076
let throughput_mb_s = throughput_calculator.calculate(statistics.total_bytes_processed);
10771077
let mut printer = Printer { stdout };

quickwit-cli/src/split.rs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::ops::{Range, RangeInclusive};
2222
use std::path::PathBuf;
2323

2424
use anyhow::{bail, Context};
25-
use chrono::{NaiveDate, NaiveDateTime};
2625
use clap::{arg, ArgMatches, Command};
2726
use humansize::{file_size_opts, FileSize};
2827
use itertools::Itertools;
@@ -33,6 +32,7 @@ use quickwit_directories::{
3332
use quickwit_metastore::{quickwit_metastore_uri_resolver, Split, SplitState};
3433
use quickwit_storage::{quickwit_storage_uri_resolver, BundleStorage, Storage};
3534
use tabled::{Table, Tabled};
35+
use time::{format_description, Date, OffsetDateTime, PrimitiveDateTime};
3636
use tracing::debug;
3737

3838
use crate::{load_quickwit_config, make_table};
@@ -159,28 +159,31 @@ impl SplitCliCommand {
159159
.into_iter()
160160
.collect::<Result<Vec<_>, _>>()
161161
.map_err(|err_str| anyhow::anyhow!(err_str))?;
162-
let start_date = if let Some(date_str) = matches.value_of("start-date") {
163-
let from_date_time = NaiveDate::parse_from_str(date_str, "%Y-%m-%d")
164-
.map(|date| date.and_hms(0, 0, 0))
165-
.or_else(|_err| NaiveDateTime::parse_from_str(date_str, "%Y-%m-%dT%H:%M:%S"))
162+
163+
let format1 = format_description::parse("[year]-[month]-[day]")?;
164+
let format2 = format_description::parse("[year]-[month]-[day]T[hour]:[minute]:[second]")?;
165+
166+
let parse_date = |date_str: &str| {
167+
Date::parse(date_str, &format1)
168+
.map(|date| date.with_hms(0, 0, 0).expect("could not create date time"))
169+
.or_else(|_err| PrimitiveDateTime::parse(date_str, &format2))
170+
.map(|date| date.assume_utc())
166171
.context(format!(
167-
"'start-date' `{}` should be of the format `2020-10-31` or \
172+
"'start/end-date' `{}` should be of the format `2020-10-31` or \
168173
`2020-10-31T02:00:00`",
169174
date_str
170-
))?;
171-
Some(from_date_time.timestamp())
175+
))
176+
};
177+
178+
let start_date = if let Some(date_str) = matches.value_of("start-date") {
179+
let from_date_time = parse_date(date_str)?;
180+
Some(from_date_time.unix_timestamp())
172181
} else {
173182
None
174183
};
175184
let end_date = if let Some(date_str) = matches.value_of("end-date") {
176-
let to_date_time = NaiveDate::parse_from_str(date_str, "%Y-%m-%d")
177-
.map(|date| date.and_hms(0, 0, 0))
178-
.or_else(|_err| NaiveDateTime::parse_from_str(date_str, "%Y-%m-%dT%H:%M:%S"))
179-
.context(format!(
180-
"'end-date' `{}` should be of the format `2020-10-31` or `2020-10-31T02:00:00`",
181-
date_str
182-
))?;
183-
Some(to_date_time.timestamp())
185+
let to_date_time = parse_date(date_str)?;
186+
Some(to_date_time.unix_timestamp())
184187
} else {
185188
None
186189
};
@@ -427,8 +430,12 @@ fn make_list_splits_table(splits: Vec<Split>) -> Table {
427430
id: split.split_metadata.split_id,
428431
num_docs: split.split_metadata.num_docs,
429432
size_mega_bytes: split.split_metadata.original_size_in_bytes / 1_000_000,
430-
create_at: NaiveDateTime::from_timestamp(split.split_metadata.create_timestamp, 0),
431-
updated_at: NaiveDateTime::from_timestamp(split.update_timestamp, 0),
433+
create_at: OffsetDateTime::from_unix_timestamp(
434+
split.split_metadata.create_timestamp,
435+
)
436+
.expect("could not create OffsetDateTime from timestamp"),
437+
updated_at: OffsetDateTime::from_unix_timestamp(split.update_timestamp)
438+
.expect("could not create OffsetDateTime from timestamp"),
432439
time_range,
433440
}
434441
})
@@ -457,9 +464,9 @@ struct SplitRow {
457464
#[header("Size (MB)")]
458465
size_mega_bytes: u64,
459466
#[header("Created At")]
460-
create_at: NaiveDateTime,
467+
create_at: OffsetDateTime,
461468
#[header("Updated At")]
462-
updated_at: NaiveDateTime,
469+
updated_at: OffsetDateTime,
463470
#[header("Time Range")]
464471
time_range: String,
465472
}
@@ -468,8 +475,8 @@ struct SplitRow {
468475
mod tests {
469476
use std::path::PathBuf;
470477

471-
use chrono::NaiveDateTime;
472478
use quickwit_metastore::SplitMetadata;
479+
use time::format_description;
473480

474481
use super::*;
475482
use crate::cli::{build_cli, CliCommand};
@@ -494,14 +501,17 @@ mod tests {
494501
"file:///config.yaml",
495502
])?;
496503
let command = CliCommand::parse_cli_args(&matches)?;
504+
let format =
505+
format_description::parse("[year]-[month]-[day]T[hour]:[minute]:[second]").unwrap();
506+
497507
assert!(matches!(
498508
command,
499509
CliCommand::Split(SplitCliCommand::List(ListSplitArgs {
500510
index_id, states, start_date, end_date, tags, ..
501511
})) if &index_id == "wikipedia"
502512
&& states == vec![SplitState::Published, SplitState::Staged]
503-
&& start_date == Some(NaiveDateTime::parse_from_str("2021-12-03T00:00:00", "%Y-%m-%dT%H:%M:%S").unwrap().timestamp())
504-
&& end_date == Some(NaiveDateTime::parse_from_str("2021-12-05T00:30:25", "%Y-%m-%dT%H:%M:%S").unwrap().timestamp())
513+
&& start_date == Some(PrimitiveDateTime::parse("2021-12-03T00:00:00", &format).unwrap().assume_utc().unix_timestamp())
514+
&& end_date == Some(PrimitiveDateTime::parse("2021-12-05T00:30:25", &format).unwrap().assume_utc().unix_timestamp())
505515
&& tags == BTreeSet::from(["foo:bar".to_string(), "bar:baz".to_string()])
506516
));
507517

quickwit-directories/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tracing = "0.1.29"
2525
thiserror = "1"
2626
anyhow = "1"
2727
async-trait = "0.1"
28-
time = { version = "0.3.7", features = ["std"] }
28+
time = { version = "0.3.9", features = ["std"] }
2929

3030
[dev-dependencies]
3131
tempfile = '3'

quickwit-doc-mapper/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ documentation = "https://quickwit.io/docs/"
1212
[dependencies]
1313
anyhow = "1"
1414
base64 = "0.13"
15-
chrono = "0.4"
1615
dyn-clone = "1.0.4"
1716
itertools = '0.10'
1817
once_cell = "1.10"

quickwit-doc-mapper/src/default_doc_mapper/default_mapper.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@ mod tests {
574574
value, expected_json_paths_and_values
575575
);
576576
}
577-
assert!(is_value_in_expected_values);
578577
}
579578
});
580579
Ok(())

quickwit-doc-mapper/src/default_doc_mapper/field_mapping_entry.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,9 +1362,8 @@ mod tests {
13621362
Date::from_calendar_date(2021, Month::December, 19).unwrap(),
13631363
Time::from_hms(17, 39, 57).unwrap(),
13641364
);
1365-
// let datetime = datetime!(2021-12-19 17:39:57);
13661365

1367-
let datetime_utc = DateTime::new_primitive(datetime); // Utc.from_utc_datetime(&datetime);
1366+
let datetime_utc = DateTime::new_primitive(datetime);
13681367
assert_eq!(parsed_value.len(), 1);
13691368
assert_eq!(parsed_value[0].1, Value::Date(datetime_utc));
13701369

quickwit-indexing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ tracing = "0.1.29"
4242
ulid = "0.5"
4343
tokio-stream = "0.1"
4444
arc-swap = "1.4"
45-
time = { version = "0.3.7", features = ["std"] }
45+
time = { version = "0.3.9", features = ["std"] }
4646

4747

4848
[features]

quickwit-metastore/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ documentation = "https://quickwit.io/docs/"
1414
anyhow = "1.0"
1515
async-trait = "0.1"
1616
byte-unit = { version = "4", default-features = false, features = ["serde"] }
17-
chrono = "0.4"
17+
time = { version = "0.3.9", features = ["std"] }
18+
chrono = { version = "0.4" }
1819
diesel = { version = "1.4", features = ["postgres", "chrono", "extras"], optional = true }
1920
diesel_migrations = { version = "1.4", optional = true }
2021
futures = "0.3.17"

quickwit-metastore/src/metastore/file_backed_metastore/file_backed_index.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
use std::collections::HashMap;
2525
use std::ops::{Range, RangeInclusive};
2626

27-
use chrono::Utc;
2827
use itertools::Itertools;
2928
use quickwit_config::SourceConfig;
3029
use quickwit_doc_mapper::tag_pruning::TagFilterAst;
3130
use serde::{Deserialize, Serialize};
31+
use time::OffsetDateTime;
3232

3333
use crate::checkpoint::CheckpointDelta;
3434
use crate::{IndexMetadata, MetastoreError, MetastoreResult, Split, SplitMetadata, SplitState};
@@ -161,7 +161,7 @@ impl FileBackedIndex {
161161
});
162162
}
163163

164-
let now_timestamp = Utc::now().timestamp();
164+
let now_timestamp = OffsetDateTime::now_utc().unix_timestamp();
165165
let metadata = Split {
166166
split_state: SplitState::Staged,
167167
update_timestamp: now_timestamp,
@@ -198,7 +198,8 @@ impl FileBackedIndex {
198198
) -> MetastoreResult<bool> {
199199
let mut is_modified = false;
200200
let mut split_not_found_ids = vec![];
201-
let now_timestamp = Utc::now().timestamp();
201+
let now_timestamp = OffsetDateTime::now_utc().unix_timestamp();
202+
202203
for &split_id in split_ids {
203204
// Check for the existence of split.
204205
let metadata = match self.splits.get_mut(split_id) {
@@ -239,7 +240,7 @@ impl FileBackedIndex {
239240
) -> MetastoreResult<()> {
240241
let mut split_not_found_ids = vec![];
241242
let mut split_not_staged_ids = vec![];
242-
let now_timestamp = Utc::now().timestamp();
243+
let now_timestamp = OffsetDateTime::now_utc().unix_timestamp();
243244
for &split_id in split_ids {
244245
// Check for the existence of split.
245246
let metadata = match self.splits.get_mut(split_id) {
@@ -380,7 +381,7 @@ impl FileBackedIndex {
380381
});
381382
}
382383

383-
self.metadata.update_timestamp = Utc::now().timestamp();
384+
self.metadata.update_timestamp = OffsetDateTime::now_utc().unix_timestamp();
384385
Ok(())
385386
}
386387

0 commit comments

Comments
 (0)