Skip to main content

Date

Struct Date 

Source
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

Source

pub fn new() -> Self

A date saying nothing at all.

Source

pub fn value(&self, part: DatePart) -> Option<IntegerType>

The value of one part, where it has one.

Source

pub fn certainty(&self, part: DatePart) -> Option<Certainty>

How sure one part is, where it says.

Source

pub fn year(&self) -> Option<IntegerType>

The year, where the date gives one.

Source

pub fn month(&self) -> Option<IntegerType>

The month, where the date gives one.

Source

pub fn day(&self) -> Option<IntegerType>

The day, where the date gives one.

Source

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.

Source

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.

Source

pub fn has_time(&self) -> bool

Whether any part of the time of day is given: music21’s hasTime.

Source

pub fn has_certainty(&self) -> bool

Whether any part says how sure it is: music21’s hasError.

Source

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.

Source

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.

Source

pub fn from_parts( year: Option<IntegerType>, month: Option<IntegerType>, day: Option<IntegerType>, ) -> Result<Self>

A date of a year, and of a month and a day where they are given.

§Errors

A value no date can have.

Source

pub fn take_from(&mut self, other: &Self) -> Result<()>

The parts of another date that it gives, written over this one’s, with their certainties: music21’s loadOther.

§Errors

A value no date can have.

Source

pub fn check(&self) -> Result<()>

Whether a calendar has such a date: music21’s _sanityCheck. It does not check whether a Gregorian leap year really was one, “as it changes historically”, and neither does this.

§Errors

A value no date can have.

Trait Implementations§

Source§

impl Clone for Date

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Date

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Date

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Date

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Date

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Date

Source§

impl Hash for Date

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Date

Two dates are equal where they are written alike, which is music21’s own __eq__ – it compares the two as strings.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Date

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.