pub struct HistoricalDate {
pub year: i32,
pub month: Option<u8>,
pub day: Option<u8>,
pub precision: DatePrecision,
}Expand description
A historical date that can represent BCE dates and partial precision.
Unlike chrono’s types, this can represent:
- BCE dates (negative years like -44 for 44 BCE)
- Partial dates (year only, year-month)
- Far-past dates beyond chrono’s range
§ISO 8601 Representation
Follows ISO 8601 extended format:
- CE dates: “2024-03-15”, “2024-03”, “2024”
- BCE dates: “-0044-03-15” (44 BCE March 15)
§Examples
ⓘ
use anno_core::types::HistoricalDate;
// Julius Caesar's death
let caesar_death = HistoricalDate::bce(44, 3, 15);
assert_eq!(caesar_death.to_iso8601(), "-0044-03-15");
// Modern date
let modern = HistoricalDate::ce(2024, 6, 15);
assert_eq!(modern.to_iso8601(), "2024-06-15");
// Year only
let year_only = HistoricalDate::year_only(1990);
assert_eq!(year_only.to_iso8601(), "1990");Fields§
§year: i32Year (negative for BCE, positive for CE) Year 0 does not exist in historical dating; -1 = 1 BCE, 1 = 1 CE
month: Option<u8>Month (1-12), None if unknown
day: Option<u8>Day (1-31), None if unknown
precision: DatePrecisionPrecision of this date
Implementations§
Source§impl HistoricalDate
impl HistoricalDate
Sourcepub fn year_only(year: i32) -> HistoricalDate
pub fn year_only(year: i32) -> HistoricalDate
Create a year-only date.
Sourcepub fn year_month(year: i32, month: u8) -> HistoricalDate
pub fn year_month(year: i32, month: u8) -> HistoricalDate
Create a year-month date.
Sourcepub fn format_year(&self) -> String
pub fn format_year(&self) -> String
Sourcepub fn to_iso8601(&self) -> String
pub fn to_iso8601(&self) -> String
Sourcepub fn parse(s: &str) -> Result<HistoricalDate, String>
pub fn parse(s: &str) -> Result<HistoricalDate, String>
Parse from ISO 8601 string.
Handles:
- “2024-06-15” (full CE date)
- “-0044-03-15” (full BCE date)
- “2024-06” (year-month)
- “2024” or “-0044” (year only)
§Errors
Returns error if the string cannot be parsed.
Sourcepub fn parse_year(s: &str) -> Option<i32>
pub fn parse_year(s: &str) -> Option<i32>
Extract just the year from an ISO 8601 string.
Useful for quick temporal comparisons without full parsing.
Trait Implementations§
Source§impl Clone for HistoricalDate
impl Clone for HistoricalDate
Source§fn clone(&self) -> HistoricalDate
fn clone(&self) -> HistoricalDate
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HistoricalDate
impl Debug for HistoricalDate
Source§impl<'de> Deserialize<'de> for HistoricalDate
impl<'de> Deserialize<'de> for HistoricalDate
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<HistoricalDate, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<HistoricalDate, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for HistoricalDate
impl Display for HistoricalDate
Source§impl FromStr for HistoricalDate
impl FromStr for HistoricalDate
Source§impl Hash for HistoricalDate
impl Hash for HistoricalDate
Source§impl Ord for HistoricalDate
impl Ord for HistoricalDate
Source§fn cmp(&self, other: &HistoricalDate) -> Ordering
fn cmp(&self, other: &HistoricalDate) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for HistoricalDate
impl PartialEq for HistoricalDate
Source§impl PartialOrd for HistoricalDate
impl PartialOrd for HistoricalDate
Source§impl Serialize for HistoricalDate
impl Serialize for HistoricalDate
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for HistoricalDate
impl Eq for HistoricalDate
impl StructuralPartialEq for HistoricalDate
Auto Trait Implementations§
impl Freeze for HistoricalDate
impl RefUnwindSafe for HistoricalDate
impl Send for HistoricalDate
impl Sync for HistoricalDate
impl Unpin for HistoricalDate
impl UnsafeUnpin for HistoricalDate
impl UnwindSafe for HistoricalDate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.