Skip to content

Commit 7f6cf5e

Browse files
committed
Switch to 2024 style
1 parent 11d227a commit 7f6cf5e

33 files changed

+135
-154
lines changed

bench/benches/chrono.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! Benchmarks for chrono that just depend on std
22
3-
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
3+
use criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main};
44

5-
use chrono::format::StrftimeItems;
6-
use chrono::prelude::*;
75
#[cfg(feature = "unstable-locales")]
86
use chrono::Locale;
9-
use chrono::{DateTime, FixedOffset, Local, TimeDelta, Utc, __BenchYearFlags};
7+
use chrono::format::StrftimeItems;
8+
use chrono::prelude::*;
9+
use chrono::{__BenchYearFlags, DateTime, FixedOffset, Local, TimeDelta, Utc};
1010

1111
fn bench_date_from_ymd(c: &mut Criterion) {
1212
c.bench_function("bench_date_from_ymd", |b| {

bench/benches/serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
1+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
22

33
use chrono::NaiveDateTime;
44

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
style_edition = "2024"
12
use_small_heuristics = "Max"

src/datetime/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ use core::{fmt, hash, str};
1414
#[cfg(feature = "std")]
1515
use std::time::{SystemTime, UNIX_EPOCH};
1616

17+
#[allow(deprecated)]
18+
use crate::Date;
1719
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
1820
use crate::format::Locale;
21+
#[cfg(feature = "alloc")]
22+
use crate::format::{DelayedFormat, SecondsFormat, write_rfc2822, write_rfc3339};
1923
use crate::format::{
20-
parse, parse_and_remainder, parse_rfc3339, Fixed, Item, ParseError, ParseResult, Parsed,
21-
StrftimeItems, TOO_LONG,
24+
Fixed, Item, ParseError, ParseResult, Parsed, StrftimeItems, TOO_LONG, parse,
25+
parse_and_remainder, parse_rfc3339,
2226
};
23-
#[cfg(feature = "alloc")]
24-
use crate::format::{write_rfc2822, write_rfc3339, DelayedFormat, SecondsFormat};
2527
use crate::naive::{Days, IsoWeek, NaiveDate, NaiveDateTime, NaiveTime};
2628
#[cfg(feature = "clock")]
2729
use crate::offset::Local;
2830
use crate::offset::{FixedOffset, LocalResult, Offset, TimeZone, Utc};
29-
#[allow(deprecated)]
30-
use crate::Date;
31-
use crate::{expect, try_opt};
3231
use crate::{Datelike, Months, TimeDelta, Timelike, Weekday};
32+
use crate::{expect, try_opt};
3333

3434
#[cfg(any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"))]
3535
use rkyv::{Archive, Deserialize, Serialize};
@@ -1849,11 +1849,7 @@ impl From<SystemTime> for DateTime<Utc> {
18491849
// unlikely but should be handled
18501850
let dur = e.duration();
18511851
let (sec, nsec) = (dur.as_secs() as i64, dur.subsec_nanos());
1852-
if nsec == 0 {
1853-
(-sec, 0)
1854-
} else {
1855-
(-sec - 1, 1_000_000_000 - nsec)
1856-
}
1852+
if nsec == 0 { (-sec, 0) } else { (-sec - 1, 1_000_000_000 - nsec) }
18571853
}
18581854
};
18591855
Utc.timestamp_opt(sec, nsec).unwrap()

src/datetime/serde.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::fmt;
22
use serde::{de, ser};
33

44
use super::DateTime;
5-
use crate::format::{write_rfc3339, SecondsFormat};
5+
use crate::format::{SecondsFormat, write_rfc3339};
66
#[cfg(feature = "clock")]
77
use crate::offset::Local;
88
use crate::offset::{FixedOffset, Offset, TimeZone, Utc};
@@ -1289,7 +1289,9 @@ mod tests {
12891289
}
12901290

12911291
assert!(serde_json::from_str::<DateTime<Utc>>(r#""2014-07-32T12:34:06Z""#).is_err());
1292-
assert!(serde_json::from_str::<DateTime<FixedOffset>>(r#""2014-07-32T12:34:06Z""#).is_err());
1292+
assert!(
1293+
serde_json::from_str::<DateTime<FixedOffset>>(r#""2014-07-32T12:34:06Z""#).is_err()
1294+
);
12931295
}
12941296

12951297
#[test]

src/datetime/tests.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,7 @@ fn test_datetime_rfc2822() {
734734
"Thu,\n\t13\n Feb\n 1969\n 23:32\n -0330 (Newfoundland Time)"
735735
),
736736
Ok(
737-
ymdhms(
738-
&FixedOffset::east_opt(-3 * 60 * 60 - 30 * 60).unwrap(),
739-
1969, 2, 13, 23, 32, 0,
740-
)
737+
ymdhms(&FixedOffset::east_opt(-3 * 60 * 60 - 30 * 60).unwrap(), 1969, 2, 13, 23, 32, 0,)
741738
)
742739
);
743740
// example from RFC 2822 Appendix A.5. without trailing " (Newfoundland Time)"
@@ -1099,8 +1096,10 @@ fn test_parse_from_str() {
10991096
Ok(ymdhms(&edt, 2014, 5, 7, 12, 34, 56))
11001097
); // ignore offset
11011098
assert!(DateTime::parse_from_str("20140507000000", "%Y%m%d%H%M%S").is_err()); // no offset
1102-
assert!(DateTime::parse_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT")
1103-
.is_err());
1099+
assert!(
1100+
DateTime::parse_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT")
1101+
.is_err()
1102+
);
11041103
assert_eq!(
11051104
DateTime::parse_from_str("0", "%s").unwrap(),
11061105
DateTime::from_timestamp(0, 0).unwrap().fixed_offset()

src/format/formatting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ mod tests {
638638
#[cfg(all(feature = "std", feature = "unstable-locales", feature = "alloc"))]
639639
#[test]
640640
fn test_with_locale_delayed_write_to() {
641-
use crate::format::locales::Locale;
642641
use crate::DateTime;
642+
use crate::format::locales::Locale;
643643

644644
let dt = DateTime::from_timestamp(1643723400, 123456789).unwrap();
645645
let df = dt.format_localized("%A, %B %d, %Y", Locale::ja_JP);

src/format/locales.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(feature = "unstable-locales")]
22
mod localized {
3-
use pure_rust_locales::{locale_match, Locale};
3+
use pure_rust_locales::{Locale, locale_match};
44

55
pub(crate) const fn default_locale() -> Locale {
66
Locale::POSIX

src/format/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ pub mod strftime;
5454
// not require `alloc`.
5555
pub(crate) mod locales;
5656

57+
pub use formatting::SecondsFormat;
5758
pub(crate) use formatting::write_hundreds;
5859
#[cfg(feature = "alloc")]
5960
pub(crate) use formatting::write_rfc2822;
6061
#[cfg(any(feature = "alloc", feature = "serde"))]
6162
pub(crate) use formatting::write_rfc3339;
62-
pub use formatting::SecondsFormat;
6363
#[cfg(feature = "alloc")]
6464
#[allow(deprecated)]
65-
pub use formatting::{format, format_item, DelayedFormat};
65+
pub use formatting::{DelayedFormat, format, format_item};
6666
#[cfg(feature = "unstable-locales")]
6767
pub use locales::Locale;
6868
pub(crate) use parse::parse_rfc3339;

src/format/parse.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use core::borrow::Borrow;
88
use core::str;
99

1010
use super::scan;
11+
use super::{BAD_FORMAT, INVALID, OUT_OF_RANGE, TOO_LONG, TOO_SHORT};
1112
use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric, Pad, Parsed};
1213
use super::{ParseError, ParseResult};
13-
use super::{BAD_FORMAT, INVALID, OUT_OF_RANGE, TOO_LONG, TOO_SHORT};
1414
use crate::{DateTime, FixedOffset, Weekday};
1515

1616
fn set_weekday_with_num_days_from_sunday(p: &mut Parsed, v: i64) -> ParseResult<()> {
@@ -640,15 +640,17 @@ mod tests {
640640
// most unicode whitespace characters
641641
parses(
642642
"\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{3000}",
643-
&[Space("\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{3000}")]
643+
&[Space(
644+
"\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{3000}",
645+
)],
644646
);
645647
// most unicode whitespace characters
646648
parses(
647649
"\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{3000}",
648650
&[
649651
Space("\u{00A0}\u{1680}\u{2000}\u{2001}\u{2002}\u{2003}\u{2004}"),
650-
Space("\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{3000}")
651-
]
652+
Space("\u{2005}\u{2006}\u{2007}\u{2008}\u{2009}\u{3000}"),
653+
],
652654
);
653655
check("a", &[Space("")], Err(TOO_LONG));
654656
check("a", &[Space(" ")], Err(TOO_LONG));
@@ -1835,8 +1837,10 @@ mod tests {
18351837

18361838
#[test]
18371839
fn test_issue_1010() {
1838-
let dt = crate::NaiveDateTime::parse_from_str("\u{c}SUN\u{e}\u{3000}\0m@J\u{3000}\0\u{3000}\0m\u{c}!\u{c}\u{b}\u{c}\u{c}\u{c}\u{c}%A\u{c}\u{b}\0SU\u{c}\u{c}",
1839-
"\u{c}\u{c}%A\u{c}\u{b}\0SUN\u{c}\u{c}\u{c}SUNN\u{c}\u{c}\u{c}SUN\u{c}\u{c}!\u{c}\u{b}\u{c}\u{c}\u{c}\u{c}%A\u{c}\u{b}%a");
1840+
let dt = crate::NaiveDateTime::parse_from_str(
1841+
"\u{c}SUN\u{e}\u{3000}\0m@J\u{3000}\0\u{3000}\0m\u{c}!\u{c}\u{b}\u{c}\u{c}\u{c}\u{c}%A\u{c}\u{b}\0SU\u{c}\u{c}",
1842+
"\u{c}\u{c}%A\u{c}\u{b}\0SUN\u{c}\u{c}\u{c}SUNN\u{c}\u{c}\u{c}SUN\u{c}\u{c}!\u{c}\u{b}\u{c}\u{c}\u{c}\u{c}%A\u{c}\u{b}%a",
1843+
);
18401844
assert_eq!(dt, Err(ParseError(ParseErrorKind::Invalid)));
18411845
}
18421846
}

0 commit comments

Comments
 (0)