cargo: upgrade chrono to version 0.4.23

This commit is contained in:
Martin von Zweigbergk 2022-11-14 09:37:48 -08:00 committed by Martin von Zweigbergk
parent 13d7594e85
commit 2cf99d1e35
5 changed files with 38 additions and 20 deletions

4
Cargo.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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"

View file

@ -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 "<out-of-range date>".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(

View file

@ -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<Signature, String> 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 "<out-of-range date>".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()
}
}