From 2cf99d1e354a678fa24b9045e06a167bf5c809a1 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 14 Nov 2022 09:37:48 -0800 Subject: [PATCH] cargo: upgrade chrono to version 0.4.23 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- lib/Cargo.toml | 2 +- src/commands.rs | 26 ++++++++++++++++++-------- src/template_parser.rs | 24 ++++++++++++++++-------- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa1e014bd..9107b4822 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,9 +179,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", "num-integer", diff --git a/Cargo.toml b/Cargo.toml index 206fb3c31..8435cb726 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ members = ["lib"] [dependencies] atty = "0.2.14" -chrono = { version = "0.4.22", default-features = false, features = ["std", "clock"] } +chrono = { version = "0.4.23", default-features = false, features = ["std", "clock"] } clap = { version = "4.0.23", features = ["derive", "deprecated"] } clap_complete = "4.0.5" clap_mangen = "0.2.4" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index fbe72c9bd..a5ad49f92 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -22,7 +22,7 @@ backoff = "0.4.0" blake2 = "0.10.5" bytes = "1.2.1" byteorder = "1.4.3" -chrono = { version = "0.4.22", default-features = false, features = ["std", "clock"] } +chrono = { version = "0.4.23", default-features = false, features = ["std", "clock"] } config = { version = "0.13.2", default-features = false, features = ["toml"] } digest = "0.10.5" git2 = "0.15.0" diff --git a/src/commands.rs b/src/commands.rs index 702e77f38..f64c66c9a 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -23,7 +23,7 @@ use std::sync::{Arc, Mutex}; use std::time::Instant; use std::{fs, io}; -use chrono::{FixedOffset, TimeZone, Utc}; +use chrono::{FixedOffset, LocalResult, TimeZone, Utc}; use clap::{ArgGroup, ArgMatches, CommandFactory, FromArgMatches, Subcommand}; use itertools::Itertools; use jujutsu_lib::backend::{BackendError, CommitId, Timestamp, TreeValue}; @@ -3537,14 +3537,24 @@ fn cmd_debug( Ok(()) } +// TODO: Move this somewhere where it can be reused by +// `template_parser::SignatureTimestamp`. fn format_timestamp(timestamp: &Timestamp) -> String { - let utc = Utc - .timestamp( - timestamp.timestamp.0.div_euclid(1000), - (timestamp.timestamp.0.rem_euclid(1000)) as u32 * 1000000, - ) - .with_timezone(&FixedOffset::east(timestamp.tz_offset * 60)); - utc.format("%Y-%m-%d %H:%M:%S.%3f %:z").to_string() + let utc = match Utc.timestamp_opt( + timestamp.timestamp.0.div_euclid(1000), + (timestamp.timestamp.0.rem_euclid(1000)) as u32 * 1000000, + ) { + LocalResult::None => { + return "".to_string(); + } + LocalResult::Single(x) => x, + LocalResult::Ambiguous(y, _z) => y, + }; + let datetime = utc.with_timezone( + &FixedOffset::east_opt(timestamp.tz_offset * 60) + .unwrap_or_else(|| FixedOffset::east_opt(0).unwrap()), + ); + datetime.format("%Y-%m-%d %H:%M:%S.%3f %:z").to_string() } fn cmd_op_log( diff --git a/src/template_parser.rs b/src/template_parser.rs index d6049b6d7..f7126ce42 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use chrono::{FixedOffset, TimeZone, Utc}; +use chrono::{FixedOffset, LocalResult, TimeZone, Utc}; use jujutsu_lib::backend::{CommitId, Signature}; use jujutsu_lib::commit::Commit; use jujutsu_lib::op_store::WorkspaceId; @@ -98,13 +98,21 @@ struct SignatureTimestamp; impl TemplateProperty for SignatureTimestamp { fn extract(&self, context: &Signature) -> String { - let utc = Utc - .timestamp( - context.timestamp.timestamp.0.div_euclid(1000), - context.timestamp.timestamp.0.rem_euclid(1000) as u32 * 1000000, - ) - .with_timezone(&FixedOffset::east(context.timestamp.tz_offset * 60)); - utc.format("%Y-%m-%d %H:%M:%S.%3f %:z").to_string() + let utc = match Utc.timestamp_opt( + context.timestamp.timestamp.0.div_euclid(1000), + (context.timestamp.timestamp.0.rem_euclid(1000)) as u32 * 1000000, + ) { + LocalResult::None => { + return "".to_string(); + } + LocalResult::Single(x) => x, + LocalResult::Ambiguous(y, _z) => y, + }; + let datetime = utc.with_timezone( + &FixedOffset::east_opt(context.timestamp.tz_offset * 60) + .unwrap_or_else(|| FixedOffset::east_opt(0).unwrap()), + ); + datetime.format("%Y-%m-%d %H:%M:%S.%3f %:z").to_string() } }