Function get_date_time

Source
pub fn get_date_time(
    datetime: impl AsRef<str>,
) -> Result<DateTime<Local>, TimeAgoError>
Expand description

Converts datetime to Chrono DateTime<Local>

§Warning

This function is designed to only works for these date time formats :

  • %Y-%m-%d %H:%M:%S: Sortable format
  • %Y/%m/%d %H:%M:%S: Sortable format
  • %Y-%m-%dT%H:%M:%S%:z: ISO 8601 with timezone offset
  • %Y-%m-%dT%H:%M:%S%.3f%:z: ISO 8601 with milliseconds and timezone offset
  • %a, %d %b %Y %H:%M:%S %z: RFC 2822 Format

timezone is set with the current timezone of the OS.

§Examples

use rust_persian_tools::time_diff::get_date_time;

assert!(get_date_time("2019/03/18 12:22:14").is_ok());
assert!(get_date_time("20192/03/18 12:22:14").is_err());