Skip to content

Commit

Permalink
Drop chrono and use latest time
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Mackie authored and Jordan Mackie committed Feb 11, 2023
1 parent f7334c7 commit 98238cc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 161 deletions.
148 changes: 2 additions & 146 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/ditto-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ditto-cst = { path = "../ditto-cst" }
ditto-config = { path = "../ditto-config" }
ditto-fmt = { path = "../ditto-fmt" }
clap = "4.0"
chrono = "0.4"
time = { version = "0.3", features = ["serde-human-readable"] }
miette = { version = "5.5", features = ["fancy"] }
tracing = "0.1"
tracing-subscriber = "0.3"
Expand Down Expand Up @@ -59,4 +59,4 @@ assert_fs = "1.0"
similar-asserts = "1.4"

[build-dependencies]
chrono = "0.4"
time = "0.3"
7 changes: 5 additions & 2 deletions crates/ditto-cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ fn main() {
});
println!("cargo:rustc-env=GIT_DIRTY={}", git_dirty);

let build_time =
env::var("DITTO_BUILD_TIME").unwrap_or_else(|_| chrono::offset::Utc::now().to_rfc3339());
let build_time = env::var("DITTO_BUILD_TIME").unwrap_or_else(|_| {
time::OffsetDateTime::now_utc()
.format(&time::format_description::well_known::Rfc3339)
.unwrap()
});

println!("cargo:rustc-env=BUILD_TIME={}", build_time);

Expand Down
6 changes: 5 additions & 1 deletion crates/ditto-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ async fn try_main() -> Result<()> {
.map_or(String::from("ditto"), |subcmd| format!("ditto_{}", subcmd));

log_file.push(subcommand);
log_file.set_extension(chrono::offset::Utc::now().to_rfc3339());
log_file.set_extension(
time::OffsetDateTime::now_utc()
.format(&time::format_description::well_known::Rfc3339)
.unwrap(),
);

let log_file = std::fs::File::create(log_file).into_diagnostic()?;
let (non_blocking, guard) = tracing_appender::non_blocking(log_file);
Expand Down
20 changes: 11 additions & 9 deletions crates/ditto-cli/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Version {
pub semversion: semver::Version,
pub git_rev: String,
pub git_is_dirty: bool,
pub build_time: chrono::DateTime<chrono::FixedOffset>,
pub build_time: time::OffsetDateTime,
pub build_profile: String,
}

Expand All @@ -26,8 +26,11 @@ impl Version {
.unwrap_or_else(|_| panic!("invalid GIT_DESCRIBE: \"{GIT_DESCRIBE}\"")),
git_rev: GIT_REV.to_owned(),
git_is_dirty: GIT_DIRTY == "yes", // see build.rs
build_time: chrono::DateTime::parse_from_rfc3339(BUILD_TIME)
.unwrap_or_else(|_| panic!("invalid BUILD_TIME: \"{BUILD_TIME}\"")),
build_time: time::OffsetDateTime::parse(
BUILD_TIME,
&time::format_description::well_known::Rfc3339,
)
.unwrap_or_else(|_| panic!("invalid BUILD_TIME: \"{BUILD_TIME}\"")),
build_profile: PROFILE.to_owned(),
}
}
Expand All @@ -44,19 +47,18 @@ impl Version {
version = self.semversion,
dirty = if self.git_is_dirty { "*" } else { "" },
profile = self.build_profile,
build_time = self.build_time.to_rfc3339()
build_time = self
.build_time
.format(&time::format_description::well_known::Rfc3339)
.unwrap(),
)
}
fn new_test() -> Self {
use chrono::TimeZone;
Self {
semversion: semver::Version::new(0, 0, 0),
git_rev: String::from("test"),
git_is_dirty: false,
build_time: chrono::Utc
.with_ymd_and_hms(1970, 1, 1, 0, 0, 0)
.unwrap()
.into(),
build_time: time::OffsetDateTime::UNIX_EPOCH,
build_profile: String::from("test"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ditto-cli/tests/cmd/version/test.stdout
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ditto 0.0.0 test
built at: 1970-01-01T00:00:00+00:00
built at: 1970-01-01T00:00:00Z

0 comments on commit 98238cc

Please sign in to comment.