Skip to content

Commit

Permalink
buck2_server_commands: remove deprecated chrono::DateTime::from_utc
Browse files Browse the repository at this point in the history
Summary:
Chrono deprecated this method in 0.4.27 which was released recently:
* https://github.com/chronotope/chrono/releases/tag/v0.4.27
* chronotope/chrono#1175

And our Cargo builds started to fail with:
```
use of deprecated associated function "chrono::DateTime::<Tz>::from_utc"
```

Reviewed By: wendy728

Differential Revision: D48785434

fbshipit-source-id: d3911b72d533fb7b1d9fd5995edf764cd828b447
  • Loading branch information
KapJI authored and facebook-github-bot committed Aug 31, 2023
1 parent f6389d5 commit 98e3cf2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bumpalo = "3.11.1"
byteorder = "1.4.3"
bytes = "1.0"
bytesize = "1.1.0"
chrono = "0.4.19"
chrono = "0.4.28"
clap = { version = "3.2.24", features = ["derive", "env"] }
common-path = "1.0.0"
compact_str = "0.6.1"
Expand Down
7 changes: 1 addition & 6 deletions app/buck2_server_commands/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ use buck2_server_ctx::pattern::target_platform_from_client_context;
use buck2_server_ctx::template::run_server_command;
use buck2_server_ctx::template::ServerCommandTemplate;
use buck2_util::process::background_command;
use chrono::DateTime;
use chrono::NaiveDateTime;
use chrono::Utc;
use dice::DiceComputations;
Expand Down Expand Up @@ -302,14 +301,10 @@ fn get_random_tcp_port() -> anyhow::Result<u16> {
Ok(tcp_port)
}

// `DateTime::from_utc` is deprecated in the latest version, it suggests
// use `TimeZone::from_utc_datetime()` or `DateTime::from_naive_utc_and_offset`
// but these are not yet available in fbsource third-parties.
#[allow(deprecated)]
fn get_timestamp_as_string() -> anyhow::Result<String> {
let nt = NaiveDateTime::from_timestamp_opt(Utc::now().timestamp(), 0)
.context(InstallError::NativeDateTime)?;
let dt: DateTime<Utc> = DateTime::from_utc(nt, Utc);
let dt = nt.and_utc();
Ok(dt.format("%Y%m%d-%H%M%S").to_string())
}

Expand Down
2 changes: 1 addition & 1 deletion shim/third-party/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bumpalo = "=3.11.1"
byteorder = "1.4.3"
bytes = "1.0"
bytesize = "1.1.0"
chrono = "=0.4.19" # Avoid a dependency iana-time-zone, which requires a fixup
chrono = "0.4.28"
clap = { package = "clap", version = "4.0.7", features = ["derive", "env"] }
clap-3 = { package = "clap", version = "3.2.24", features = ["derive", "env"] }
common-path = "1.0.0"
Expand Down

0 comments on commit 98e3cf2

Please sign in to comment.