Skip to content

Commit 184db11

Browse files
Replace deprecated chrono with jiff (RustPython#8436)
See: chronotope/chrono#1768
1 parent 331c3b1 commit 184db11

7 files changed

Lines changed: 91 additions & 181 deletions

File tree

Cargo.lock

Lines changed: 21 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ bitflags = "2.11.0"
200200
bitflagset = "0.0.3"
201201
bstr = { version = "1", default-features = false, features = ["unicode"] }
202202
bzip2 = "0.6"
203-
chrono = { version = "0.4.44", default-features = false, features = ["clock", "std"] }
204203
console_error_panic_hook = "0.1"
205204
constant_time_eq = "0.5"
206205
cranelift = "0.132.0"
@@ -231,6 +230,7 @@ insta = "1.47"
231230
itertools = { version = "0.15.0", default-features = false, features = ["use_alloc"] }
232231
itoa = "1"
233232
is-macro = "0.3.7"
233+
jiff = "0.2"
234234
js-sys = "0.3"
235235
junction = "2.0.0"
236236
lexical-parse-float = "1.0.6"

crates/stdlib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ libz-rs-sys = { workspace = true }
8686
bzip2 = { workspace = true }
8787

8888
# tkinter
89+
jiff = { workspace = true }
8990
tk-sys = { workspace = true, optional = true }
9091
tcl-sys = { workspace = true, optional = true }
9192
widestring = { workspace = true, optional = true }
92-
chrono.workspace = true
9393

9494
# uuid
9595
[target.'cfg(not(any(target_os = "ios", target_os = "android", target_os = "windows", target_arch = "wasm32", target_os = "redox")))'.dependencies]

crates/stdlib/src/ssl/cert.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! - Loading certificates from files, directories, and bytes
1111
1212
use alloc::sync::Arc;
13-
use chrono::{DateTime, Utc};
13+
use jiff::{Timestamp, Zoned, tz::TimeZone};
1414
use parking_lot::RwLock as ParkingRwLock;
1515
use rustls::{
1616
DigitallySignedStruct, RootCertStore, SignatureScheme,
@@ -201,10 +201,10 @@ fn format_ip_address(ip: &[u8]) -> String {
201201
/// Formats certificate validity dates in the format:
202202
/// "Mon DD HH:MM:SS YYYY GMT"
203203
fn format_asn1_time(time: &x509_parser::time::ASN1Time) -> String {
204-
let timestamp = time.timestamp();
205-
DateTime::<Utc>::from_timestamp(timestamp, 0)
206-
.expect("ASN1Time must be valid timestamp")
207-
.format("%b %e %H:%M:%S %Y GMT")
204+
let timestamp =
205+
Timestamp::from_second(time.timestamp()).expect("ASN1Time must be valid timestamp");
206+
Zoned::new(timestamp, TimeZone::UTC)
207+
.strftime("%b %e %H:%M:%S %Y GMT")
208208
.to_string()
209209
}
210210

@@ -341,7 +341,7 @@ pub(super) fn cert_to_dict(
341341
let serial = format_serial_number(&cert.serial);
342342
dict.set_item("serialNumber", vm.ctx.new_str(serial).into(), vm)?;
343343

344-
// Validity dates - format with GMT using chrono
344+
// Validity dates - format with GMT using jiff
345345
dict.set_item(
346346
"notBefore",
347347
vm.ctx
@@ -414,7 +414,7 @@ pub(super) fn cert_der_to_dict_helper(
414414
// CPython ordering: issuer, notAfter, notBefore, serialNumber, subject, version
415415
dict.set_item("issuer", name_to_tuple(cert.issuer())?, vm)?;
416416

417-
// Validity - format with GMT using chrono
417+
// Validity - format with GMT using jiff
418418
dict.set_item(
419419
"notAfter",
420420
vm.ctx

crates/vm/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ast = ["ruff_python_ast", "ruff_text_size"]
2626
codegen = ["rustpython-codegen", "ast"]
2727
parser = ["ast"]
2828
serde = ["dep:serde"]
29-
wasmbind = ["rustpython-common/wasm_js", "chrono/wasmbind", "wasm-bindgen"]
29+
wasmbind = ["rustpython-common/wasm_js", "jiff/js", "wasm-bindgen"]
3030

3131
[dependencies]
3232
rustpython-compiler = { workspace = true, optional = true }
@@ -48,14 +48,14 @@ ascii = { workspace = true }
4848
bitflags = { workspace = true }
4949
bstr = { workspace = true }
5050
crossbeam-utils = { workspace = true }
51-
chrono = { workspace = true }
5251
constant_time_eq = { workspace = true }
5352
flame = { workspace = true, optional = true }
5453
hex = { workspace = true }
5554
indexmap = { workspace = true }
5655
itertools = { workspace = true }
5756
itoa = { workspace = true }
5857
is-macro = { workspace = true }
58+
jiff = { workspace = true }
5959
libc = { workspace = true }
6060
log = { workspace = true }
6161
malachite-bigint = { workspace = true }
@@ -91,9 +91,9 @@ widestring = { workspace = true }
9191
wasm-bindgen = { workspace = true, optional = true }
9292

9393
[build-dependencies]
94-
chrono = { workspace = true }
9594
glob = { workspace = true }
9695
itertools = { workspace = true }
96+
jiff = { workspace = true }
9797

9898
[lints]
9999
workspace = true

crates/vm/build.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
reason = "build scripts cannot use rustpython-host_env"
44
)]
55

6-
use chrono::{Local, prelude::DateTime};
7-
use core::time::Duration;
86
use itertools::Itertools;
7+
use jiff::{Timestamp, Zoned, tz::TimeZone};
98
use std::{
109
env,
1110
io::{self, prelude::*},
@@ -123,24 +122,27 @@ fn git_identifier() -> String {
123122
}
124123
}
125124

126-
fn get_git_timestamp_datetime() -> DateTime<Local> {
127-
let timestamp = git_timestamp().parse::<u64>().unwrap_or_default();
128-
let datetime = UNIX_EPOCH + Duration::from_secs(timestamp);
129-
datetime.into()
125+
fn get_git_timestamp_raw() -> Option<Timestamp> {
126+
let git_timestamp = git_timestamp().parse::<i64>().ok()?;
127+
Timestamp::from_second(git_timestamp).ok()
128+
}
129+
130+
fn get_git_timestamp_datetime() -> Zoned {
131+
get_git_timestamp_raw().map_or_else(Zoned::now, |timestamp| {
132+
Zoned::new(timestamp, TimeZone::system())
133+
})
130134
}
131135

132136
#[must_use]
133137
fn get_git_date() -> String {
134138
let datetime = get_git_timestamp_datetime();
135-
136-
datetime.format("%b %e %Y").to_string()
139+
datetime.strftime("%b %e %Y").to_string()
137140
}
138141

139142
#[must_use]
140143
fn get_git_time() -> String {
141144
let datetime = get_git_timestamp_datetime();
142-
143-
datetime.format("%H:%M:%S").to_string()
145+
datetime.strftime("%H:%M:%S").to_string()
144146
}
145147

146148
fn rustc_version() -> String {

0 commit comments

Comments
 (0)