// Peek Annotation presence // Throw error if annotation does not exist and zoned is true, else return. if !cursor.check_or(false, is_annotation_open)? {
cursor.close()?;
/// Parses a `DateTime` record. fn parse_date_time<T: EncodingType>(cursor: &mut Cursor<T>) -> ParserResult<DateTimeRecord> { let date = parse_date(cursor)?;
// If there is no `DateTimeSeparator`, return date early. if !cursor.check_or(false, is_date_time_separator)? { return Ok(DateTimeRecord {
date: Some(date),
time: None,
time_zone: None,
});
}
cursor.advance();
let time = parse_time_record(cursor)?;
let time_zone = if cursor.check_or(false, |ch| is_ascii_sign(ch) || is_utc_designator(ch))? {
Some(timezone::parse_date_time_utc_offset(cursor)?)
} else {
None
};
if !is_valid_month_day(month, day) { return Err(ParseError::InvalidMonthDay);
}
Ok(DateRecord {
year: 0,
month,
day,
})
}
fn is_valid_month_day(month: u8, day: u8) -> bool { match month { 2 | 4 | 6 | 9 | 11if day >= 31 => false, 2if day == 30 => false,
_ => day <= 31,
}
}
// ==== Unit Parsers ====
#[inline] fn parse_date_year<T: EncodingType>(cursor: &mut Cursor<T>) -> ParserResult<i32> { if cursor.check_or(false, is_ascii_sign)? { let sign = if cursor.next_or(ParseError::ImplAssert)? == b'+' { 1
} else {
-1
};
let first = cursor.next_digit()?.ok_or(ParseError::DateExtendedYear)? as i32 * 100_000; let second = cursor.next_digit()?.ok_or(ParseError::DateExtendedYear)? as i32 * 10_000; let third = cursor.next_digit()?.ok_or(ParseError::DateExtendedYear)? as i32 * 1000; let fourth = cursor.next_digit()?.ok_or(ParseError::DateExtendedYear)? as i32 * 100; let fifth = cursor.next_digit()?.ok_or(ParseError::DateExtendedYear)? as i32 * 10;
let year_value = first
+ second
+ third
+ fourth
+ fifth
+ cursor.next_digit()?.ok_or(ParseError::DateExtendedYear)? as i32;
// 13.30.1 Static Semantics: Early Errors // // It is a Syntax Error if DateYear is "-000000" or "−000000" (U+2212 MINUS SIGN followed by 000000). if sign == -1 && year_value == 0 { return Err(ParseError::DateExtendedYear);
}
let year = sign * year_value;
return Ok(year);
}
let first = cursor.next_digit()?.ok_or(ParseError::DateYear)? as i32 * 1000; let second = cursor.next_digit()?.ok_or(ParseError::DateYear)? as i32 * 100; let third = cursor.next_digit()?.ok_or(ParseError::DateYear)? as i32 * 10; let year_value =
first + second + third + cursor.next_digit()?.ok_or(ParseError::DateYear)? as i32;
Ok(year_value)
}
#[inline] fn parse_date_month<T: EncodingType>(cursor: &mut Cursor<T>) -> ParserResult<u8> { let first = cursor.next_digit()?.ok_or(ParseError::DateMonth)?; let month_value = first * 10 + cursor.next_digit()?.ok_or(ParseError::DateMonth)?; if !(1..=12).contains(&month_value) { return Err(ParseError::InvalidMonthRange);
}
Ok(month_value)
}
#[inline] fn parse_date_day<T: EncodingType>(cursor: &mut Cursor<T>) -> ParserResult<u8> { let first = cursor.next_digit()?.ok_or(ParseError::DateDay)?; let day_value = first * 10 + cursor.next_digit()?.ok_or(ParseError::DateDay)?;
Ok(day_value)
}
#[inline] fn check_date_validity(year: i32, month: u8, day: u8) -> ParserResult<()> { let Some(days_in_month) = days_in_month(year, month) else { // NOTE: This should never through due to check in `parse_date_month` return Err(ParseError::InvalidMonthRange);
}; if !(1..=days_in_month).contains(&day) { return Err(ParseError::InvalidDayRange);
}
Ok(())
}
/// Utilty to return the days in month, returns None if month is invalid #[inline] fn days_in_month(year: i32, month: u8) -> Option<u8> { match month { 1 | 3 | 5 | 7 | 8 | 10 | 12 => Some(31), 4 | 6 | 9 | 11 => Some(30), 2 => Some(28 + u8::from(in_leap_year(year))),
_ => None,
}
}
/// Utility that returns whether a year is a leap year. #[inline] fn in_leap_year(year: i32) -> bool { if year % 4 != 0 { false
} elseif year % 4 == 0 && year % 100 != 0 { true
} elseif year % 100 == 0 && year % 400 != 0 { false
} else {
assert_eq!(year % 400, 0); true
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.33 Sekunden
(vorverarbeitet am 2026-10-03)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.