mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-27 13:01:37 +00:00
Remove unnecessary type annotations
This commit is contained in:
parent
9e8e036378
commit
ce4644f5df
@ -12,7 +12,7 @@ fn bench_datetime_parse_from_rfc2822(c: &mut Criterion) {
|
|||||||
c.bench_function("bench_datetime_parse_from_rfc2822", |b| {
|
c.bench_function("bench_datetime_parse_from_rfc2822", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let str = black_box("Wed, 18 Feb 2015 23:16:09 +0000");
|
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()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ fn bench_datetime_parse_from_rfc3339(c: &mut Criterion) {
|
|||||||
c.bench_function("bench_datetime_parse_from_rfc3339", |b| {
|
c.bench_function("bench_datetime_parse_from_rfc3339", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let str = black_box("2015-02-18T23:59:60.234567+05:00");
|
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()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use libfuzzer_sys::fuzz_target;
|
|||||||
fuzz_target!(|data: &[u8]| {
|
fuzz_target!(|data: &[u8]| {
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
if let Ok(data) = std::str::from_utf8(data) {
|
if let Ok(data) = std::str::from_utf8(data) {
|
||||||
let _ = DateTime::<FixedOffset>::parse_from_rfc2822(data);
|
let _ = DateTime::parse_from_rfc2822(data);
|
||||||
let _ = DateTime::<FixedOffset>::parse_from_rfc3339(data);
|
let _ = DateTime::parse_from_rfc3339(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -677,7 +677,7 @@ impl DateTime<FixedOffset> {
|
|||||||
/// ```
|
/// ```
|
||||||
/// # use chrono::{DateTime, FixedOffset, TimeZone};
|
/// # use chrono::{DateTime, FixedOffset, TimeZone};
|
||||||
/// assert_eq!(
|
/// 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()
|
/// FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
@ -727,7 +727,7 @@ impl DateTime<FixedOffset> {
|
|||||||
/// ```rust
|
/// ```rust
|
||||||
/// use chrono::{DateTime, FixedOffset, TimeZone, NaiveDate};
|
/// 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");
|
/// "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()));
|
/// 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()));
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -472,7 +472,7 @@ fn test_datetime_rfc2822() {
|
|||||||
"Wed, 18 Feb 2015 23:16:09 +0500"
|
"Wed, 18 Feb 2015 23:16:09 +0500"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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
|
Ok(edt
|
||||||
.from_local_datetime(
|
.from_local_datetime(
|
||||||
&NaiveDate::from_ymd_opt(2015, 2, 18)
|
&NaiveDate::from_ymd_opt(2015, 2, 18)
|
||||||
@ -482,9 +482,9 @@ fn test_datetime_rfc2822() {
|
|||||||
)
|
)
|
||||||
.unwrap())
|
.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!(
|
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
|
Ok(edt
|
||||||
.from_local_datetime(
|
.from_local_datetime(
|
||||||
&NaiveDate::from_ymd_opt(2015, 2, 18)
|
&NaiveDate::from_ymd_opt(2015, 2, 18)
|
||||||
@ -508,11 +508,11 @@ fn test_datetime_rfc2822() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
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())
|
Ok(FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap())
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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())
|
Ok(FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap())
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -520,24 +520,24 @@ fn test_datetime_rfc2822() {
|
|||||||
"Wed, 18 Feb 2015 23:59:60 +0500"
|
"Wed, 18 Feb 2015 23:59:60 +0500"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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))
|
Ok(ymdhms(&edt, 2015, 2, 18, 23, 59, 58))
|
||||||
);
|
);
|
||||||
assert_ne!(
|
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))
|
Ok(ymdhms_milli(&edt, 2015, 2, 18, 23, 59, 58, 500))
|
||||||
);
|
);
|
||||||
|
|
||||||
// many varying whitespace intermixed
|
// many varying whitespace intermixed
|
||||||
assert_eq!(
|
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"
|
"\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))
|
Ok(ymdhms(&edt, 2015, 2, 18, 23, 59, 58))
|
||||||
);
|
);
|
||||||
// example from RFC 2822 Appendix A.5.
|
// example from RFC 2822 Appendix A.5.
|
||||||
assert_eq!(
|
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)"
|
"Thu,\n\t13\n Feb\n 1969\n 23:32\n -0330 (Newfoundland Time)"
|
||||||
),
|
),
|
||||||
Ok(
|
Ok(
|
||||||
@ -549,7 +549,7 @@ fn test_datetime_rfc2822() {
|
|||||||
);
|
);
|
||||||
// example from RFC 2822 Appendix A.5. without trailing " (Newfoundland Time)"
|
// example from RFC 2822 Appendix A.5. without trailing " (Newfoundland Time)"
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
DateTime::<FixedOffset>::parse_from_rfc2822(
|
DateTime::parse_from_rfc2822(
|
||||||
"Thu,\n\t13\n Feb\n 1969\n 23:32\n -0330"
|
"Thu,\n\t13\n Feb\n 1969\n 23:32\n -0330"
|
||||||
),
|
),
|
||||||
Ok(
|
Ok(
|
||||||
@ -558,23 +558,17 @@ fn test_datetime_rfc2822() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// bad year
|
// 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
|
// wrong format
|
||||||
assert!(
|
assert!(DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +00:00").is_err());
|
||||||
DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +00:00").is_err()
|
|
||||||
);
|
|
||||||
// full name day of week
|
// full name day of week
|
||||||
assert!(DateTime::<FixedOffset>::parse_from_rfc2822("Wednesday, 18 Feb 2015 23:16:09 +0000")
|
assert!(DateTime::parse_from_rfc2822("Wednesday, 18 Feb 2015 23:16:09 +0000").is_err());
|
||||||
.is_err());
|
|
||||||
// full name day of week
|
// full name day of week
|
||||||
assert!(DateTime::<FixedOffset>::parse_from_rfc2822("Wednesday 18 Feb 2015 23:16:09 +0000")
|
assert!(DateTime::parse_from_rfc2822("Wednesday 18 Feb 2015 23:16:09 +0000").is_err());
|
||||||
.is_err());
|
|
||||||
// wrong day of week separator '.'
|
// 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
|
// *trailing* space causes failure
|
||||||
assert!(
|
assert!(DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000 ").is_err());
|
||||||
DateTime::<FixedOffset>::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000 ").is_err()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -611,19 +605,19 @@ fn test_datetime_rfc3339() {
|
|||||||
"2015-02-18T23:59:60.234567+05:00"
|
"2015-02-18T23:59:60.234567+05:00"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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))
|
Ok(ymdhms_micro(&edt5, 2015, 2, 18, 23, 59, 59, 123_000))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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))
|
Ok(ymdhms_micro(&edt5, 2015, 2, 18, 23, 59, 59, 123_456))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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))
|
Ok(ymdhms_nano(&edt5, 2015, 2, 18, 23, 59, 59, 123_456_789))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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))
|
Ok(ymdhms(&edt0, 2015, 2, 18, 23, 16, 9))
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -636,49 +630,31 @@ fn test_datetime_rfc3339() {
|
|||||||
"2015-02-18T23:16:09.150+05:00"
|
"2015-02-18T23:16:09.150+05:00"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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))
|
Ok(ymdhms_micro(&edt5, 2015, 2, 18, 0, 0, 0, 234_567))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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))
|
Ok(ymdhms(&edt0, 2015, 2, 18, 23, 16, 9))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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))
|
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_eq!(ymdhms_utc(2015, 2, 18, 23, 16, 9).to_rfc3339(), "2015-02-18T23:16:09+00:00");
|
||||||
|
|
||||||
assert!(
|
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567 +05:00").is_err());
|
||||||
DateTime::<FixedOffset>::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!(
|
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567+PST").is_err());
|
||||||
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:059:60.234567+05:00").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!(
|
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00:00").is_err());
|
||||||
DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567+05:00PST").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::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567+PST").is_err());
|
assert!(DateTime::parse_from_rfc3339(" 2015-02-18T23:59:60.234567+05:00").is_err());
|
||||||
assert!(DateTime::<FixedOffset>::parse_from_rfc3339("2015-02-18T23:59:60.234567PST").is_err());
|
assert!(DateTime::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+0500").is_err());
|
assert!(DateTime::parse_from_rfc3339("2015-02-18T23:59:60.234567A+05:00").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()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -922,18 +898,15 @@ fn test_parse_from_str() {
|
|||||||
let edt0 = FixedOffset::east_opt(0).unwrap();
|
let edt0 = FixedOffset::east_opt(0).unwrap();
|
||||||
let wdt = FixedOffset::west_opt(10 * 3600).unwrap();
|
let wdt = FixedOffset::west_opt(10 * 3600).unwrap();
|
||||||
assert_eq!(
|
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))
|
Ok(ymdhms(&edt, 2014, 5, 7, 12, 34, 56))
|
||||||
); // ignore offset
|
); // ignore offset
|
||||||
assert!(DateTime::<FixedOffset>::parse_from_str("20140507000000", "%Y%m%d%H%M%S").is_err()); // no offset
|
assert!(DateTime::parse_from_str("20140507000000", "%Y%m%d%H%M%S").is_err()); // no offset
|
||||||
assert!(DateTime::<FixedOffset>::parse_from_str(
|
assert!(DateTime::parse_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT")
|
||||||
"Fri, 09 Aug 2013 23:54:35 GMT",
|
.is_err());
|
||||||
"%a, %d %b %Y %H:%M:%S GMT"
|
|
||||||
)
|
|
||||||
.is_err());
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
DateTime::<Utc>::parse_from_str("0", "%s").unwrap(),
|
DateTime::parse_from_str("0", "%s").unwrap(),
|
||||||
NaiveDateTime::from_timestamp_opt(0, 0).unwrap().and_utc().fixed_offset()
|
NaiveDateTime::from_timestamp_opt(0, 0).unwrap().and_utc()
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -979,7 +952,7 @@ fn test_parse_from_str() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_datetime_parse_from_str() {
|
fn test_datetime_parse_from_str() {
|
||||||
let dt = ymdhms(&FixedOffset::east_opt(-9 * 60 * 60).unwrap(), 2013, 8, 9, 23, 54, 35);
|
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
|
// timezone variations
|
||||||
|
|
||||||
|
@ -1865,7 +1865,7 @@ mod tests {
|
|||||||
|
|
||||||
// Test against test data above
|
// Test against test data above
|
||||||
for &(date, checkdate) in testdates.iter() {
|
for &(date, checkdate) in testdates.iter() {
|
||||||
let dt = DateTime::<FixedOffset>::parse_from_rfc3339(date);
|
let dt = DateTime::parse_from_rfc3339(date);
|
||||||
if dt != checkdate {
|
if dt != checkdate {
|
||||||
// check for expected result
|
// check for expected result
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -743,18 +743,15 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
dt.with_timezone(&Utc),
|
dt.with_timezone(&Utc),
|
||||||
DateTime::<FixedOffset>::parse_from_str("2001-07-07T15:04:60.026490708Z", "%+")
|
DateTime::parse_from_str("2001-07-07T15:04:60.026490708Z", "%+").unwrap()
|
||||||
.unwrap()
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
dt.with_timezone(&Utc),
|
dt.with_timezone(&Utc),
|
||||||
DateTime::<FixedOffset>::parse_from_str("2001-07-07T15:04:60.026490708UTC", "%+")
|
DateTime::parse_from_str("2001-07-07T15:04:60.026490708UTC", "%+").unwrap()
|
||||||
.unwrap()
|
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
dt.with_timezone(&Utc),
|
dt.with_timezone(&Utc),
|
||||||
DateTime::<FixedOffset>::parse_from_str("2001-07-07t15:04:60.026490708utc", "%+")
|
DateTime::parse_from_str("2001-07-07t15:04:60.026490708utc", "%+").unwrap()
|
||||||
.unwrap()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
16
src/lib.rs
16
src/lib.rs
@ -282,18 +282,18 @@
|
|||||||
//! assert_eq!("2014-11-28T21:00:09+09:00".parse::<DateTime<FixedOffset>>(), Ok(fixed_dt.clone()));
|
//! assert_eq!("2014-11-28T21:00:09+09:00".parse::<DateTime<FixedOffset>>(), Ok(fixed_dt.clone()));
|
||||||
//!
|
//!
|
||||||
//! // method 2
|
//! // 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()));
|
//! 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()));
|
//! 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!
|
//! // 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!
|
//! // 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!
|
//! // 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)
|
//! Again : See [`format::strftime`](./format/strftime/index.html#specifiers)
|
||||||
@ -313,14 +313,14 @@
|
|||||||
#![cfg_attr(not(feature = "std"), doc = "```ignore")]
|
#![cfg_attr(not(feature = "std"), doc = "```ignore")]
|
||||||
#![cfg_attr(feature = "std", doc = "```rust")]
|
#![cfg_attr(feature = "std", doc = "```rust")]
|
||||||
//! // We need the trait in scope to use Utc::timestamp().
|
//! // 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:
|
//! // Construct a datetime from epoch:
|
||||||
//! let dt = Utc.timestamp_opt(1_500_000_000, 0).unwrap();
|
//! let dt = Utc.timestamp_opt(1_500_000_000, 0).unwrap();
|
||||||
//! assert_eq!(dt.to_rfc2822(), "Fri, 14 Jul 2017 02:40:00 +0000");
|
//! assert_eq!(dt.to_rfc2822(), "Fri, 14 Jul 2017 02:40:00 +0000");
|
||||||
//!
|
//!
|
||||||
//! // Get epoch value from a datetime:
|
//! // 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);
|
//! assert_eq!(dt.timestamp(), 1_500_000_000);
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
@ -182,7 +182,7 @@ mod tests;
|
|||||||
///
|
///
|
||||||
/// let dt = Utc.with_ymd_and_hms(2015, 6, 30, 23, 56, 5).unwrap();
|
/// 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!(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,
|
/// Since Chrono alone cannot determine any existence of leap seconds,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user