(timestamp: &str)
| 533 | } |
| 534 | |
| 535 | fn codex_timestamp_date(timestamp: &str) -> Option<&str> { |
| 536 | let date = timestamp.get(..10)?; |
| 537 | let bytes = date.as_bytes(); |
| 538 | if !(bytes.len() == 10 |
| 539 | && bytes[0..4].iter().all(u8::is_ascii_digit) |
| 540 | && bytes[4] == b'-' |
| 541 | && bytes[5..7].iter().all(u8::is_ascii_digit) |
| 542 | && bytes[7] == b'-' |
| 543 | && bytes[8..10].iter().all(u8::is_ascii_digit)) |
| 544 | { |
| 545 | return None; |
| 546 | } |
| 547 | let year = codex_date_part(&bytes[0..4])?; |
| 548 | let month = codex_date_part(&bytes[5..7])?; |
| 549 | let day = codex_date_part(&bytes[8..10])?; |
| 550 | let max_day = codex_days_in_month(year, month)?; |
| 551 | (day >= 1 && day <= max_day).then_some(date) |
| 552 | } |
| 553 | |
| 554 | fn codex_date_part(bytes: &[u8]) -> Option<u16> { |
| 555 | bytes.iter().try_fold(0u16, |value, byte| { |
no test coverage detected