MCPcopy Create free account
hub / github.com/ccusage/ccusage / codex_timestamp_date

Function codex_timestamp_date

rust/crates/ccusage/src/adapter/codex/parser.rs:535–552  ·  view source on GitHub ↗
(timestamp: &str)

Source from the content-addressed store, hash-verified

533}
534
535fn 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
554fn codex_date_part(bytes: &[u8]) -> Option<u16> {
555 bytes.iter().try_fold(0u16, |value, byte| {

Calls 4

codex_date_partFunction · 0.85
codex_days_in_monthFunction · 0.85
lenMethod · 0.80
allMethod · 0.80

Tested by

no test coverage detected