Skip to content

Commit 754ad18

Browse files
committed
Remove remaining uses of TimeZone::datetime_from_str() from tests and docs
1 parent 935e7b5 commit 754ad18

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

src/datetime/tests.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ fn test_parse_datetime_utc() {
898898
}
899899

900900
#[test]
901-
fn test_utc_datetime_from_str() {
901+
fn test_parse_from_str() {
902902
let edt = FixedOffset::east_opt(570 * 60).unwrap();
903903
let edt0 = FixedOffset::east_opt(0).unwrap();
904904
let wdt = FixedOffset::west_opt(10 * 3600).unwrap();
@@ -909,10 +909,6 @@ fn test_utc_datetime_from_str() {
909909
assert!(DateTime::parse_from_str("20140507000000", "%Y%m%d%H%M%S").is_err()); // no offset
910910
assert!(DateTime::parse_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT")
911911
.is_err());
912-
assert_eq!(
913-
Utc.datetime_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT"),
914-
Ok(Utc.with_ymd_and_hms(2013, 8, 9, 23, 54, 35).unwrap())
915-
);
916912
assert_eq!(
917913
DateTime::parse_from_str("0", "%s").unwrap(),
918914
NaiveDateTime::from_timestamp_opt(0, 0).unwrap().and_utc().fixed_offset()

src/format/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
//! # Example
1919
#![cfg_attr(not(feature = "std"), doc = "```ignore")]
2020
#![cfg_attr(feature = "std", doc = "```rust")]
21-
//! use chrono::{TimeZone, Utc};
21+
//! use chrono::{NaiveDateTime, TimeZone, Utc};
2222
//!
2323
//! let date_time = Utc.with_ymd_and_hms(2020, 11, 10, 0, 1, 32).unwrap();
2424
//!
2525
//! let formatted = format!("{}", date_time.format("%Y-%m-%d %H:%M:%S"));
2626
//! assert_eq!(formatted, "2020-11-10 00:01:32");
2727
//!
28-
//! let parsed = Utc.datetime_from_str(&formatted, "%Y-%m-%d %H:%M:%S")?;
28+
//! let parsed = NaiveDateTime::parse_from_str(&formatted, "%Y-%m-%d %H:%M:%S")?.and_utc();
2929
//! assert_eq!(parsed, date_time);
3030
//! # Ok::<(), chrono::ParseError>(())
3131
//! ```

src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,12 @@
298298
//! Ok(fixed_dt.clone()));
299299
//! assert_eq!(DateTime::parse_from_rfc3339("2014-11-28T21:00:09+09:00"), Ok(fixed_dt.clone()));
300300
//!
301-
//! // method 3
302-
//! assert_eq!(Utc.datetime_from_str("2014-11-28 12:00:09", "%Y-%m-%d %H:%M:%S"), Ok(dt.clone()));
303-
//! assert_eq!(Utc.datetime_from_str("Fri Nov 28 12:00:09 2014", "%a %b %e %T %Y"), Ok(dt.clone()));
304-
//!
305301
//! // oops, the year is missing!
306-
//! assert!(Utc.datetime_from_str("Fri Nov 28 12:00:09", "%a %b %e %T %Y").is_err());
302+
//! assert!(DateTime::parse_from_str("Fri Nov 28 12:00:09", "%a %b %e %T %Y").is_err());
307303
//! // oops, the format string does not include the year at all!
308-
//! assert!(Utc.datetime_from_str("Fri Nov 28 12:00:09", "%a %b %e %T").is_err());
304+
//! assert!(DateTime::parse_from_str("Fri Nov 28 12:00:09", "%a %b %e %T").is_err());
309305
//! // oops, the weekday is incorrect!
310-
//! assert!(Utc.datetime_from_str("Sat Nov 28 12:00:09 2014", "%a %b %e %T %Y").is_err());
306+
//! assert!(DateTime::parse_from_str("Sat Nov 28 12:00:09 2014", "%a %b %e %T %Y").is_err());
311307
//! ```
312308
//!
313309
//! Again : See [`format::strftime`](./format/strftime/index.html#specifiers)

0 commit comments

Comments
 (0)