pub struct DateParser {}
Expand description
Container for parsing dates from string slices.
Implementations§
Source§impl DateParser
impl DateParser
Sourcepub fn parse(text: &str) -> Option<NaiveDate>
pub fn parse(text: &str) -> Option<NaiveDate>
Parses a string slice of natural language text with respect to the current date. Returns a NaiveDate
if a match is found, None
otherwise.
§Arguments
text
- A string slice that holds the the text to be parsed
§Example
use chrono::{prelude::*, Duration, Local, NaiveDate, NaiveDateTime, Weekday};
use date_time_parser::{DateParser, Recognizable};
let year = Local::now().year();
let date = DateParser::parse("July 4 2020");
assert_eq!(date, Some(NaiveDate::from_ymd(year, 7, 4)));
Sourcepub fn parse_relative(text: &str, now: NaiveDate) -> Option<NaiveDate>
pub fn parse_relative(text: &str, now: NaiveDate) -> Option<NaiveDate>
Parses a string slice of natural language text with respect to a given date. Returns a NaiveDate
if a match is found, None
otherwise.
§Arguments
text
- A string slice that holds the the text to be parsednow
- ANaiveDate
to interpret the natural language date around
§Example
use chrono::{prelude::*, Duration, Local, NaiveDate, NaiveDateTime, Weekday};
use date_time_parser::{DateParser, Recognizable};
let year = Local::now().year();
let date = DateParser::parse_relative("July 4", Utc::now().date().naive_utc());
assert_eq!(date, Some(NaiveDate::from_ymd(year, 7, 4)));
Auto Trait Implementations§
impl Freeze for DateParser
impl RefUnwindSafe for DateParser
impl Send for DateParser
impl Sync for DateParser
impl Unpin for DateParser
impl UnwindSafe for DateParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more