Skip to content

Commit

Permalink
Add example of date conversion after 9999 CE
Browse files Browse the repository at this point in the history
(cherry picked from commit 05b865d)
  • Loading branch information
c-git authored and djc committed Feb 16, 2023
1 parent 64c4c01 commit e63b729
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ impl NaiveDateTime {
/// assert!(parse_from_str("2001-09-09 01:46:39 = UNIX timestamp 999999999", fmt).is_ok());
/// assert!(parse_from_str("1970-01-01 00:00:00 = UNIX timestamp 1", fmt).is_err());
/// ```
///
/// Years before 1 BCE or after 9999 CE, require an initial sign
///
///```
/// # use chrono::{NaiveDate, NaiveDateTime};
/// # let parse_from_str = NaiveDateTime::parse_from_str;
/// let fmt = "%Y-%m-%d %H:%M:%S";
/// assert!(parse_from_str("10000-09-09 01:46:39", fmt).is_err());
/// assert!(parse_from_str("+10000-09-09 01:46:39", fmt).is_ok());
///```
pub fn parse_from_str(s: &str, fmt: &str) -> ParseResult<NaiveDateTime> {
let mut parsed = Parsed::new();
parse(&mut parsed, s, StrftimeItems::new(fmt))?;
Expand Down

0 comments on commit e63b729

Please sign in to comment.