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

+4-4
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

+1-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
style_edition = "2024"
12
use_small_heuristics = "Max"

src/datetime/mod.rs

+8-12
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

+4-2
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

+5-6
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

+1-1
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

+1-1
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

+2-2
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

+10-6
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
}

src/format/parsed.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! A collection of parsed date and time items.
55
//! They can be constructed incrementally while being checked for consistency.
66
7-
use super::{ParseResult, IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE};
7+
use super::{IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE, ParseResult};
88
use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
99
use crate::offset::{FixedOffset, MappedLocalTime, Offset, TimeZone};
1010
use crate::{DateTime, Datelike, TimeDelta, Timelike, Weekday};
@@ -176,11 +176,7 @@ pub struct Parsed {
176176
#[inline]
177177
fn set_if_consistent<T: PartialEq>(old: &mut Option<T>, new: T) -> ParseResult<()> {
178178
if let Some(ref old) = *old {
179-
if *old == new {
180-
Ok(())
181-
} else {
182-
Err(IMPOSSIBLE)
183-
}
179+
if *old == new { Ok(()) } else { Err(IMPOSSIBLE) }
184180
} else {
185181
*old = Some(new);
186182
Ok(())
@@ -701,11 +697,7 @@ impl Parsed {
701697
(_, _, _) => return Err(NOT_ENOUGH),
702698
};
703699

704-
if verified {
705-
Ok(parsed_date)
706-
} else {
707-
Err(IMPOSSIBLE)
708-
}
700+
if verified { Ok(parsed_date) } else { Err(IMPOSSIBLE) }
709701
}
710702

711703
/// Returns a parsed naive time out of given fields.
@@ -1166,10 +1158,10 @@ fn resolve_week_date(
11661158
mod tests {
11671159
use super::super::{IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE};
11681160
use super::Parsed;
1169-
use crate::naive::{NaiveDate, NaiveTime};
1170-
use crate::offset::{FixedOffset, TimeZone, Utc};
11711161
use crate::Datelike;
11721162
use crate::Weekday::*;
1163+
use crate::naive::{NaiveDate, NaiveTime};
1164+
use crate::offset::{FixedOffset, TimeZone, Utc};
11731165

11741166
#[test]
11751167
fn test_parsed_set_fields() {

src/format/scan.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Various scanning routines for the parser.
66
*/
77

8-
use super::{ParseResult, INVALID, OUT_OF_RANGE, TOO_SHORT};
8+
use super::{INVALID, OUT_OF_RANGE, ParseResult, TOO_SHORT};
99
use crate::Weekday;
1010

1111
/// Tries to parse the non-negative number from `min` to `max` digits.
@@ -217,11 +217,7 @@ where
217217

218218
const fn digits(s: &str) -> ParseResult<(u8, u8)> {
219219
let b = s.as_bytes();
220-
if b.len() < 2 {
221-
Err(TOO_SHORT)
222-
} else {
223-
Ok((b[0], b[1]))
224-
}
220+
if b.len() < 2 { Err(TOO_SHORT) } else { Ok((b[0], b[1])) }
225221
}
226222
let negative = match s.chars().next() {
227223
Some('+') => {
@@ -359,8 +355,8 @@ mod tests {
359355
comment_2822, nanosecond, nanosecond_fixed, short_or_long_month0, short_or_long_weekday,
360356
timezone_offset_2822,
361357
};
362-
use crate::format::{INVALID, TOO_SHORT};
363358
use crate::Weekday;
359+
use crate::format::{INVALID, TOO_SHORT};
364360

365361
#[test]
366362
fn test_rfc2822_comments() {

src/format/strftime.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ Notes:
161161
#[cfg(feature = "alloc")]
162162
extern crate alloc;
163163

164-
use super::{fixed, internal_fixed, num, num0, nums};
165-
#[cfg(feature = "unstable-locales")]
166-
use super::{locales, Locale};
167-
use super::{Fixed, InternalInternal, Item, Numeric, Pad};
168164
#[cfg(any(feature = "alloc", feature = "std"))]
169-
use super::{ParseError, BAD_FORMAT};
165+
use super::{BAD_FORMAT, ParseError};
166+
use super::{Fixed, InternalInternal, Item, Numeric, Pad};
167+
#[cfg(feature = "unstable-locales")]
168+
use super::{Locale, locales};
169+
use super::{fixed, internal_fixed, num, num0, nums};
170170
#[cfg(all(feature = "alloc", not(feature = "std"), not(test)))]
171171
use alloc::vec::Vec;
172172

@@ -686,8 +686,8 @@ mod tests {
686686
use crate::format::Item::{self, Literal, Space};
687687
#[cfg(feature = "unstable-locales")]
688688
use crate::format::Locale;
689-
use crate::format::{fixed, internal_fixed, num, num0, nums};
690689
use crate::format::{Fixed, InternalInternal, Numeric::*};
690+
use crate::format::{fixed, internal_fixed, num, num0, nums};
691691
#[cfg(feature = "alloc")]
692692
use crate::{DateTime, FixedOffset, NaiveDate, TimeZone, Timelike, Utc};
693693

src/month.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use core::fmt;
33
#[cfg(any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"))]
44
use rkyv::{Archive, Deserialize, Serialize};
55

6-
use crate::naive::NaiveDate;
76
use crate::OutOfRange;
7+
use crate::naive::NaiveDate;
88

99
/// The month of the year.
1010
///
@@ -395,8 +395,8 @@ mod tests {
395395
#[test]
396396
#[cfg(feature = "serde")]
397397
fn test_serde_serialize() {
398-
use serde_json::to_string;
399398
use Month::*;
399+
use serde_json::to_string;
400400

401401
let cases: Vec<(Month, &str)> = vec![
402402
(January, "\"January\""),
@@ -422,8 +422,8 @@ mod tests {
422422
#[test]
423423
#[cfg(feature = "serde")]
424424
fn test_serde_deserialize() {
425-
use serde_json::from_str;
426425
use Month::*;
426+
use serde_json::from_str;
427427

428428
let cases: Vec<(&str, Month)> = vec![
429429
("\"january\"", January),

src/naive/date/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ use pure_rust_locales::Locale;
3030
#[cfg(feature = "alloc")]
3131
use crate::format::DelayedFormat;
3232
use crate::format::{
33-
parse, parse_and_remainder, write_hundreds, Item, Numeric, Pad, ParseError, ParseResult,
34-
Parsed, StrftimeItems,
33+
Item, Numeric, Pad, ParseError, ParseResult, Parsed, StrftimeItems, parse, parse_and_remainder,
34+
write_hundreds,
3535
};
3636
use crate::month::Months;
3737
use crate::naive::{Days, IsoWeek, NaiveDateTime, NaiveTime, NaiveWeek};
38-
use crate::{expect, try_opt};
3938
use crate::{Datelike, TimeDelta, Weekday};
39+
use crate::{expect, try_opt};
4040

4141
use super::internals::{Mdf, YearFlags};
4242

src/naive/date/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use super::{Days, Months, NaiveDate, MAX_YEAR, MIN_YEAR};
2-
use crate::naive::internals::{YearFlags, A, AG, B, BA, C, CB, D, DC, E, ED, F, FE, G, GF};
1+
use super::{Days, MAX_YEAR, MIN_YEAR, Months, NaiveDate};
2+
use crate::naive::internals::{A, AG, B, BA, C, CB, D, DC, E, ED, F, FE, G, GF, YearFlags};
33
use crate::{Datelike, TimeDelta, Weekday};
44

55
// as it is hard to verify year flags in `NaiveDate::MIN` and `NaiveDate::MAX`,

src/naive/datetime/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ use rkyv::{Archive, Deserialize, Serialize};
1515

1616
#[cfg(feature = "alloc")]
1717
use crate::format::DelayedFormat;
18-
use crate::format::{parse, parse_and_remainder, ParseError, ParseResult, Parsed, StrftimeItems};
1918
use crate::format::{Fixed, Item, Numeric, Pad};
19+
use crate::format::{ParseError, ParseResult, Parsed, StrftimeItems, parse, parse_and_remainder};
2020
use crate::naive::{Days, IsoWeek, NaiveDate, NaiveTime};
2121
use crate::offset::Utc;
2222
use crate::time_delta::NANOS_PER_SEC;
2323
use crate::{
24-
expect, try_opt, DateTime, Datelike, FixedOffset, MappedLocalTime, Months, TimeDelta, TimeZone,
25-
Timelike, Weekday,
24+
DateTime, Datelike, FixedOffset, MappedLocalTime, Months, TimeDelta, TimeZone, Timelike,
25+
Weekday, expect, try_opt,
2626
};
2727

2828
/// Tools to help serializing/deserializing `NaiveDateTime`s

src/naive/datetime/tests.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,10 @@ fn test_datetime_parse_from_str() {
199199
NaiveDateTime::parse_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT"),
200200
Ok(ymdhms(2013, 8, 9, 23, 54, 35))
201201
);
202-
assert!(NaiveDateTime::parse_from_str(
203-
"Sat, 09 Aug 2013 23:54:35 GMT",
204-
"%a, %d %b %Y %H:%M:%S GMT"
205-
)
206-
.is_err());
202+
assert!(
203+
NaiveDateTime::parse_from_str("Sat, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT")
204+
.is_err()
205+
);
207206
assert!(NaiveDateTime::parse_from_str("2014-5-7 12:3456", "%Y-%m-%d %H:%M:%S").is_err());
208207
assert!(NaiveDateTime::parse_from_str("12:34:56", "%H:%M:%S").is_err()); // insufficient
209208
assert_eq!(

0 commit comments

Comments
 (0)