Skip to content

Commit

Permalink
Remove unnecessary type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 26, 2023
1 parent 680cf07 commit d9c3772
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 91 deletions.
4 changes: 2 additions & 2 deletions bench/benches/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn bench_datetime_parse_from_rfc2822(c: &mut Criterion) {
c.bench_function("bench_datetime_parse_from_rfc2822", |b| {
b.iter(|| {
let str = black_box("Wed, 18 Feb 2015 23:16:09 +0000");
DateTime::<FixedOffset>::parse_from_rfc2822(str).unwrap()
DateTime::parse_from_rfc2822(str).unwrap()
})
});
}
Expand All @@ -21,7 +21,7 @@ fn bench_datetime_parse_from_rfc3339(c: &mut Criterion) {
c.bench_function("bench_datetime_parse_from_rfc3339", |b| {
b.iter(|| {
let str = black_box("2015-02-18T23:59:60.234567+05:00");
DateTime::<FixedOffset>::parse_from_rfc3339(str).unwrap()
DateTime::parse_from_rfc3339(str).unwrap()
})
});
}
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/fuzz_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use libfuzzer_sys::fuzz_target;
fuzz_target!(|data: &[u8]| {
use chrono::prelude::*;
if let Ok(data) = std::str::from_utf8(data) {
let _ = DateTime::<FixedOffset>::parse_from_rfc2822(data);
let _ = DateTime::<FixedOffset>::parse_from_rfc3339(data);
let _ = DateTime::parse_from_rfc2822(data);
let _ = DateTime::parse_from_rfc3339(data);
}
});
4 changes: 2 additions & 2 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ impl DateTime<FixedOffset> {
/// ```
/// # use chrono::{DateTime, FixedOffset, TimeZone};
/// assert_eq!(
/// DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 GMT").unwrap(),
/// DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 GMT").unwrap(),
/// FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
/// );
/// ```
Expand Down Expand Up @@ -727,7 +727,7 @@ impl DateTime<FixedOffset> {
/// ```rust
/// use chrono::{DateTime, FixedOffset, TimeZone, NaiveDate};
///
/// let dt = DateTime::<FixedOffset>::parse_from_str(
/// let dt = DateTime::parse_from_str(
/// "1983 Apr 13 12:09:14.274 +0000", "%Y %b %d %H:%M:%S%.3f %z");
/// assert_eq!(dt, Ok(FixedOffset::east_opt(0).unwrap().from_local_datetime(&NaiveDate::from_ymd_opt(1983, 4, 13).unwrap().and_hms_milli_opt(12, 9, 14, 274).unwrap()).unwrap()));
/// ```
Expand Down
111 changes: 42 additions & 69 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ fn test_datetime_rfc2822() {
"Wed, 18 Feb 2015 23:16:09 +0500"
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:59:60 +0500"),
DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:59:60 +0500"),
Ok(edt
.from_local_datetime(
&NaiveDate::from_ymd_opt(2015, 2, 18)
Expand All @@ -482,9 +482,9 @@ fn test_datetime_rfc2822() {
)
.unwrap())
);
assert!(DateTime::<FixedOffset>::parse_from_rfc2822("31 DEC 262143 23:59 -2359").is_err());
assert!(DateTime::parse_from_rfc2822("31 DEC 262143 23:59 -2359").is_err());
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00"),
DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00"),
Ok(edt
.from_local_datetime(
&NaiveDate::from_ymd_opt(2015, 2, 18)
Expand All @@ -508,36 +508,36 @@ fn test_datetime_rfc2822() {
);

assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000"),
DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000"),
Ok(FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap())
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 -0000"),
DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 -0000"),
Ok(FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap())
);
assert_eq!(
ymdhms_micro(&edt, 2015, 2, 18, 23, 59, 59, 1_234_567).to_rfc2822(),
"Wed, 18 Feb 2015 23:59:60 +0500"
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:59:58 +0500"),
DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:59:58 +0500"),
Ok(ymdhms(&edt, 2015, 2, 18, 23, 59, 58))
);
assert_ne!(
DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:59:58 +0500"),
DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:59:58 +0500"),
Ok(ymdhms_milli(&edt, 2015, 2, 18, 23, 59, 58, 500))
);

// many varying whitespace intermixed
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc2822(
DateTime::parse_from_rfc2822(
"\t\t\tWed,\n\t\t18 \r\n\t\tFeb \u{3000} 2015\r\n\t\t\t23:59:58 \t+0500"
),
Ok(ymdhms(&edt, 2015, 2, 18, 23, 59, 58))
);
// example from RFC 2822 Appendix A.5.
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc2822(
DateTime::parse_from_rfc2822(
"Thu,\n\t13\n Feb\n 1969\n 23:32\n -0330 (Newfoundland Time)"
),
Ok(
Expand All @@ -549,7 +549,7 @@ fn test_datetime_rfc2822() {
);
// example from RFC 2822 Appendix A.5. without trailing " (Newfoundland Time)"
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc2822(
DateTime::parse_from_rfc2822(
"Thu,\n\t13\n Feb\n 1969\n 23:32\n -0330"
),
Ok(
Expand All @@ -558,23 +558,17 @@ fn test_datetime_rfc2822() {
);

// bad year
assert!(DateTime::<FixedOffset>::parse_from_rfc2822("31 DEC 262143 23:59 -2359").is_err());
assert!(DateTime::parse_from_rfc2822("31 DEC 262143 23:59 -2359").is_err());
// wrong format
assert!(
DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +00:00").is_err()
);
assert!(DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +00:00").is_err());
// full name day of week
assert!(DateTime::<FixedOffset>::parse_from_rfc2822("Wednesday, 18 Feb 2015 23:16:09 +0000")
.is_err());
assert!(DateTime::parse_from_rfc2822("Wednesday, 18 Feb 2015 23:16:09 +0000").is_err());
// full name day of week
assert!(DateTime::<FixedOffset>::parse_from_rfc2822("Wednesday 18 Feb 2015 23:16:09 +0000")
.is_err());
assert!(DateTime::parse_from_rfc2822("Wednesday 18 Feb 2015 23:16:09 +0000").is_err());
// wrong day of week separator '.'
assert!(DateTime::<FixedOffset>::parse_from_rfc2822("Wed. 18 Feb 2015 23:16:09 +0000").is_err());
assert!(DateTime::parse_from_rfc2822("Wed. 18 Feb 2015 23:16:09 +0000").is_err());
// *trailing* space causes failure
assert!(
DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000 ").is_err()
);
assert!(DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000 ").is_err());
}

#[test]
Expand Down Expand Up @@ -611,19 +605,19 @@ fn test_datetime_rfc3339() {
"2015-02-18T23:59:60.234567+05:00"
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:59.123+05:00"),
DateTime::parse_from_rfc3339("2015-02-18T23:59:59.123+05:00"),
Ok(ymdhms_micro(&edt5, 2015, 2, 18, 23, 59, 59, 123_000))
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:59.123456+05:00"),
DateTime::parse_from_rfc3339("2015-02-18T23:59:59.123456+05:00"),
Ok(ymdhms_micro(&edt5, 2015, 2, 18, 23, 59, 59, 123_456))
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:59.123456789+05:00"),
DateTime::parse_from_rfc3339("2015-02-18T23:59:59.123456789+05:00"),
Ok(ymdhms_nano(&edt5, 2015, 2, 18, 23, 59, 59, 123_456_789))
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:16:09Z"),
DateTime::parse_from_rfc3339("2015-02-18T23:16:09Z"),
Ok(ymdhms(&edt0, 2015, 2, 18, 23, 16, 9))
);

Expand All @@ -636,49 +630,31 @@ fn test_datetime_rfc3339() {
"2015-02-18T23:16:09.150+05:00"
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T00:00:00.234567+05:00"),
DateTime::parse_from_rfc3339("2015-02-18T00:00:00.234567+05:00"),
Ok(ymdhms_micro(&edt5, 2015, 2, 18, 0, 0, 0, 234_567))
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:16:09Z"),
DateTime::parse_from_rfc3339("2015-02-18T23:16:09Z"),
Ok(ymdhms(&edt0, 2015, 2, 18, 23, 16, 9))
);
assert_eq!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18 23:59:60.234567+05:00"),
DateTime::parse_from_rfc3339("2015-02-18 23:59:60.234567+05:00"),
Ok(ymdhms_micro(&edt5, 2015, 2, 18, 23, 59, 59, 1_234_567))
);
assert_eq!(ymdhms_utc(2015, 2, 18, 23, 16, 9).to_rfc3339(), "2015-02-18T23:16:09+00:00");

assert!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567 +05:00").is_err()
);
assert!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:059:60.234567+05:00").is_err()
);
assert!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00PST").is_err()
);
assert!(DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567+PST").is_err());
assert!(DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567PST").is_err());
assert!(DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567+0500").is_err());
assert!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00:00").is_err()
);
assert!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567:+05:00").is_err()
);
assert!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00 ").is_err()
);
assert!(
DateTime::<FixedOffset>::parse_from_rfc3339(" 2015-02-18T23:59:60.234567+05:00").is_err()
);
assert!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015- 02-18T23:59:60.234567+05:00").is_err()
);
assert!(
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567A+05:00").is_err()
);
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567 +05:00").is_err());
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:059:60.234567+05:00").is_err());
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00PST").is_err());
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567+PST").is_err());
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567PST").is_err());
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567+0500").is_err());
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00:00").is_err());
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567:+05:00").is_err());
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00 ").is_err());
assert!(DateTime::parse_from_rfc3339(" 2015-02-18T23:59:60.234567+05:00").is_err());
assert!(DateTime::parse_from_rfc3339("2015- 02-18T23:59:60.234567+05:00").is_err());
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567A+05:00").is_err());
}

#[test]
Expand Down Expand Up @@ -922,18 +898,15 @@ fn test_parse_from_str() {
let edt0 = FixedOffset::east_opt(0).unwrap();
let wdt = FixedOffset::west_opt(10 * 3600).unwrap();
assert_eq!(
DateTime::<FixedOffset>::parse_from_str("2014-5-7T12:34:56+09:30", "%Y-%m-%dT%H:%M:%S%z"),
DateTime::parse_from_str("2014-5-7T12:34:56+09:30", "%Y-%m-%dT%H:%M:%S%z"),
Ok(ymdhms(&edt, 2014, 5, 7, 12, 34, 56))
); // ignore offset
assert!(DateTime::<FixedOffset>::parse_from_str("20140507000000", "%Y%m%d%H%M%S").is_err()); // no offset
assert!(DateTime::<FixedOffset>::parse_from_str(
"Fri, 09 Aug 2013 23:54:35 GMT",
"%a, %d %b %Y %H:%M:%S GMT"
)
.is_err());
assert!(DateTime::parse_from_str("20140507000000", "%Y%m%d%H%M%S").is_err()); // no offset
assert!(DateTime::parse_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT")
.is_err());
assert_eq!(
DateTime::<Utc>::parse_from_str("0", "%s").unwrap(),
NaiveDateTime::from_timestamp_opt(0, 0).unwrap().and_utc().fixed_offset()
DateTime::parse_from_str("0", "%s").unwrap(),
NaiveDateTime::from_timestamp_opt(0, 0).unwrap().and_utc()
);

assert_eq!(
Expand Down Expand Up @@ -979,7 +952,7 @@ fn test_parse_from_str() {
#[test]
fn test_datetime_parse_from_str() {
let dt = ymdhms(&FixedOffset::east_opt(-9 * 60 * 60).unwrap(), 2013, 8, 9, 23, 54, 35);
let parse = DateTime::<FixedOffset>::parse_from_str;
let parse = DateTime::parse_from_str;

// timezone variations

Expand Down
2 changes: 1 addition & 1 deletion src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ mod tests {

// Test against test data above
for &(date, checkdate) in testdates.iter() {
let dt = DateTime::<FixedOffset>::parse_from_rfc3339(date);
let dt = DateTime::parse_from_rfc3339(date);
if dt != checkdate {
// check for expected result
panic!(
Expand Down
9 changes: 3 additions & 6 deletions src/format/strftime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,18 +743,15 @@ mod tests {
);
assert_eq!(
dt.with_timezone(&Utc),
DateTime::<FixedOffset>::parse_from_str("2001-07-07T15:04:60.026490708Z", "%+")
.unwrap()
DateTime::parse_from_str("2001-07-07T15:04:60.026490708Z", "%+").unwrap()
);
assert_eq!(
dt.with_timezone(&Utc),
DateTime::<FixedOffset>::parse_from_str("2001-07-07T15:04:60.026490708UTC", "%+")
.unwrap()
DateTime::parse_from_str("2001-07-07T15:04:60.026490708UTC", "%+").unwrap()
);
assert_eq!(
dt.with_timezone(&Utc),
DateTime::<FixedOffset>::parse_from_str("2001-07-07t15:04:60.026490708utc", "%+")
.unwrap()
DateTime::parse_from_str("2001-07-07t15:04:60.026490708utc", "%+").unwrap()
);

assert_eq!(
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,18 @@
//! assert_eq!("2014-11-28T21:00:09+09:00".parse::<DateTime<FixedOffset>>(), Ok(fixed_dt.clone()));
//!
//! // method 2
//! assert_eq!(DateTime::<FixedOffset>::parse_from_str("2014-11-28 21:00:09 +09:00", "%Y-%m-%d %H:%M:%S %z"),
//! assert_eq!(DateTime::parse_from_str("2014-11-28 21:00:09 +09:00", "%Y-%m-%d %H:%M:%S %z"),
//! Ok(fixed_dt.clone()));
//! assert_eq!(DateTime::<FixedOffset>::parse_from_rfc2822("Fri, 28 Nov 2014 21:00:09 +0900"),
//! assert_eq!(DateTime::parse_from_rfc2822("Fri, 28 Nov 2014 21:00:09 +0900"),
//! Ok(fixed_dt.clone()));
//! assert_eq!(DateTime::<FixedOffset>::parse_from_rfc3339("2014-11-28T21:00:09+09:00"), Ok(fixed_dt.clone()));
//! assert_eq!(DateTime::parse_from_rfc3339("2014-11-28T21:00:09+09:00"), Ok(fixed_dt.clone()));
//!
//! // oops, the year is missing!
//! assert!(DateTime::<FixedOffset>::parse_from_str("Fri Nov 28 12:00:09", "%a %b %e %T %Y").is_err());
//! assert!(DateTime::parse_from_str("Fri Nov 28 12:00:09", "%a %b %e %T %Y").is_err());
//! // oops, the format string does not include the year at all!
//! assert!(DateTime::<FixedOffset>::parse_from_str("Fri Nov 28 12:00:09", "%a %b %e %T").is_err());
//! assert!(DateTime::parse_from_str("Fri Nov 28 12:00:09", "%a %b %e %T").is_err());
//! // oops, the weekday is incorrect!
//! assert!(DateTime::<FixedOffset>::parse_from_str("Sat Nov 28 12:00:09 2014", "%a %b %e %T %Y").is_err());
//! assert!(DateTime::parse_from_str("Sat Nov 28 12:00:09 2014", "%a %b %e %T %Y").is_err());
//! ```
//!
//! Again : See [`format::strftime`](./format/strftime/index.html#specifiers)
Expand All @@ -313,14 +313,14 @@
#![cfg_attr(not(feature = "std"), doc = "```ignore")]
#![cfg_attr(feature = "std", doc = "```rust")]
//! // We need the trait in scope to use Utc::timestamp().
//! use chrono::{DateTime, FixedOffset, TimeZone, Utc};
//! use chrono::{DateTime, TimeZone, Utc};
//!
//! // Construct a datetime from epoch:
//! let dt = Utc.timestamp_opt(1_500_000_000, 0).unwrap();
//! assert_eq!(dt.to_rfc2822(), "Fri, 14 Jul 2017 02:40:00 +0000");
//!
//! // Get epoch value from a datetime:
//! let dt = DateTime::<FixedOffset>::parse_from_rfc2822("Fri, 14 Jul 2017 02:40:00 +0000").unwrap();
//! let dt = DateTime::parse_from_rfc2822("Fri, 14 Jul 2017 02:40:00 +0000").unwrap();
//! assert_eq!(dt.timestamp(), 1_500_000_000);
//! ```
//!
Expand Down
2 changes: 1 addition & 1 deletion src/naive/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ mod tests;
///
/// let dt = Utc.with_ymd_and_hms(2015, 6, 30, 23, 56, 5).unwrap();
/// assert_eq!(format!("{:?}", dt), "2015-06-30T23:56:05Z");
/// assert_eq!(DateTime::<Utc>::parse_from_rfc3339("2015-06-30T23:56:05Z").unwrap(), dt);
/// assert_eq!(DateTime::parse_from_rfc3339("2015-06-30T23:56:05Z").unwrap(), dt);
/// ```
///
/// Since Chrono alone cannot determine any existence of leap seconds,
Expand Down

0 comments on commit d9c3772

Please sign in to comment.