Use the following grammar to parse `s` into: - `NaiveDate` - `NaiveTime` - Timezone string `NaiveDate` and `NaiveTime` are appropriate to compute a `NaiveDateTime`, which can be used in conjunction with a timezone string to generate a `DateTime `. ```text ::= [ ] ::= <m
(s: &str)
| 374 | /// <sign> <hours value> <colon> <minutes value> |
| 375 | /// ``` |
| 376 | fn parse_timestamp_string(s: &str) -> Result<(NaiveDate, NaiveTime, Timezone), String> { |
| 377 | if s.is_empty() { |
| 378 | return Err("timestamp string is empty".into()); |
| 379 | } |
| 380 | |
| 381 | // PostgreSQL special date-time inputs |
| 382 | // https://www.postgresql.org/docs/12/datatype-datetime.html#id-1.5.7.13.18.8 |
| 383 | // We should add support for other values here, e.g. infinity |
| 384 | // which @quodlibetor is willing to add to the chrono package. |
| 385 | if s == "epoch" { |
| 386 | return Ok(( |
| 387 | NaiveDate::from_ymd_opt(1970, 1, 1).unwrap(), |
| 388 | NaiveTime::from_hms_opt(0, 0, 0).unwrap(), |
| 389 | Default::default(), |
| 390 | )); |
| 391 | } |
| 392 | |
| 393 | let (ts_string, tz_string, era) = datetime::split_timestamp_string(s); |
| 394 | |
| 395 | let pdt = ParsedDateTime::build_parsed_datetime_timestamp(ts_string, era)?; |
| 396 | let d: NaiveDate = pdt.compute_date()?; |
| 397 | let t: NaiveTime = pdt.compute_time()?; |
| 398 | |
| 399 | let offset = if tz_string.is_empty() { |
| 400 | Default::default() |
| 401 | } else { |
| 402 | Timezone::parse(tz_string, TimezoneSpec::Iso)? |
| 403 | }; |
| 404 | |
| 405 | Ok((d, t, offset)) |
| 406 | } |
| 407 | |
| 408 | /// Parses a [`Date`] from `s`. |
| 409 | pub fn parse_date(s: &str) -> Result<Date, ParseError> { |
no test coverage detected