pub struct Date { /* private fields */ }Expand description
A date as music21 keeps one: music21’s metadata.Date. Any part may be
missing, and any part may say how sure it is.
use music21::metadata::primitives::{Certainty, Date, DatePart};
let read = Date::from_written("1030?/12~/?4")?;
assert_eq!(read.value(DatePart::Year), Some(1030));
assert_eq!(read.certainty(DatePart::Year), Some(Certainty::Uncertain));
assert_eq!(read.to_string(), "1030?/12~/04?");Implementations§
Source§impl Date
impl Date
Sourcepub fn value(&self, part: DatePart) -> Option<IntegerType>
pub fn value(&self, part: DatePart) -> Option<IntegerType>
The value of one part, where it has one.
Sourcepub fn certainty(&self, part: DatePart) -> Option<Certainty>
pub fn certainty(&self, part: DatePart) -> Option<Certainty>
How sure one part is, where it says.
Sourcepub fn year(&self) -> Option<IntegerType>
pub fn year(&self) -> Option<IntegerType>
The year, where the date gives one.
Sourcepub fn month(&self) -> Option<IntegerType>
pub fn month(&self) -> Option<IntegerType>
The month, where the date gives one.
Sourcepub fn day(&self) -> Option<IntegerType>
pub fn day(&self) -> Option<IntegerType>
The day, where the date gives one.
Sourcepub fn set(
&mut self,
part: DatePart,
value: Option<IntegerType>,
certainty: Option<Certainty>,
) -> Result<()>
pub fn set( &mut self, part: DatePart, value: Option<IntegerType>, certainty: Option<Certainty>, ) -> Result<()>
Gives one part a value, with how sure it is.
§Errors
A value no date can have – a thirteenth month, the thirty-first of
April, the twenty-ninth of February in a year that is not a leap
year. music21 checks the same, and leaves the value it was given in
place when it raises, which is why Self::set_unchecked is here
beside this.
Sourcepub fn set_unchecked(
&mut self,
part: DatePart,
value: Option<IntegerType>,
certainty: Option<Certainty>,
)
pub fn set_unchecked( &mut self, part: DatePart, value: Option<IntegerType>, certainty: Option<Certainty>, )
Gives one part a value without asking whether a calendar has such a date: music21 writes its own attributes freely and only checks when a date is loaded, so a caller standing in for it writes this way and checks afterwards.
Sourcepub fn has_time(&self) -> bool
pub fn has_time(&self) -> bool
Whether any part of the time of day is given: music21’s hasTime.
Sourcepub fn has_certainty(&self) -> bool
pub fn has_certainty(&self) -> bool
Whether any part says how sure it is: music21’s hasError.
Sourcepub fn from_written(written: &str) -> Result<Self>
pub fn from_written(written: &str) -> Result<Self>
A date read from the way music21 writes one: music21’s loadStr.
A part written -- says nothing; a symbol anywhere in a part says
how sure it is. Colons are read as slashes, so
1834/12/4/4:50:32 and 1834/12/4:4:50:32 are one date.
§Errors
A part that is not a number, or a value no date can have.
Sourcepub fn from_written_unchecked(written: &str) -> Result<Self>
pub fn from_written_unchecked(written: &str) -> Result<Self>
A date read as Self::from_written reads one, without asking
whether a calendar has such a date. music21’s own load keeps the
values it read and then raises, so a caller standing in for it
reads this way and calls Self::check afterwards.
§Errors
A part that is not a number.
Sourcepub fn from_parts(
year: Option<IntegerType>,
month: Option<IntegerType>,
day: Option<IntegerType>,
) -> Result<Self>
pub fn from_parts( year: Option<IntegerType>, month: Option<IntegerType>, day: Option<IntegerType>, ) -> Result<Self>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Date
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Date
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Date
Auto Trait Implementations§
impl Forget for Date
impl Freeze for Date
impl RefUnwindSafe for Date
impl Send for Date
impl Sync for Date
impl Unpin for Date
impl UnsafeUnpin for Date
impl UnwindSafe for Date
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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 more