[][src]Struct datetime_string::common::Ymd8HyphenStr

#[repr(transparent)]pub struct Ymd8HyphenStr(_);

String slice for a date in YYYY-MM-DD format, such as 2001-12-31.

This is also an RFC 3339 full-date string.

Implementations

impl Ymd8HyphenStr[src]

pub fn from_str(s: &str) -> Result<&Self, Error>[src]

Creates a new &Ymd8HyphenStr from a string slice.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;
assert_eq!(date.as_str(), "2001-12-31");

assert!(Ymd8HyphenStr::from_str("0000-01-01").is_ok());
assert!(Ymd8HyphenStr::from_str("9999-12-31").is_ok());

assert!(Ymd8HyphenStr::from_str("2004-02-29").is_ok(), "2004 is a leap year");
assert!(Ymd8HyphenStr::from_str("2100-02-29").is_err(), "2100 is NOT a leap year");
assert!(Ymd8HyphenStr::from_str("2000-02-29").is_ok(), "2000 is a leap year");

pub fn from_mut_str(s: &mut str) -> Result<&mut Self, Error>[src]

Creates a new &mut Ymd8HyphenStr from a mutable string slice.

Examples

let mut buf = "2001-12-31".to_owned();
let date = Ymd8HyphenStr::from_mut_str(&mut buf)?;
assert_eq!(date.as_str(), "2001-12-31");

date.set_year(1999)?;
assert_eq!(date.as_str(), "1999-12-31");

assert_eq!(buf, "1999-12-31");

pub fn from_bytes(s: &[u8]) -> Result<&Self, Error>[src]

Creates a new &Ymd8HyphenStr from a byte slice.

Examples

let date = Ymd8HyphenStr::from_bytes(b"2001-12-31")?;
assert_eq!(date.as_str(), "2001-12-31");

assert!(Ymd8HyphenStr::from_bytes(b"0000-01-01").is_ok());
assert!(Ymd8HyphenStr::from_bytes(b"9999-12-31").is_ok());

assert!(Ymd8HyphenStr::from_bytes(b"2004-02-29").is_ok(), "2004 is a leap year");
assert!(Ymd8HyphenStr::from_bytes(b"2100-02-29").is_err(), "2100 is NOT a leap year");
assert!(Ymd8HyphenStr::from_bytes(b"2000-02-29").is_ok(), "2000 is a leap year");

pub fn from_bytes_mut(s: &mut [u8]) -> Result<&mut Self, Error>[src]

Creates a new &mut Ymd8HyphenStr from a mutable byte slice.

Examples

let mut buf: [u8; 10] = *b"2001-12-31";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "2001-12-31");

date.set_year(1999)?;
assert_eq!(date.as_str(), "1999-12-31");

assert_eq!(&buf[..], b"1999-12-31");

pub fn assign(&mut self, v: &Self)[src]

Assigns the given value.

Examples

let mut buf: [u8; 10] = *b"1999-12-31";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "1999-12-31");

let newdate = Ymd8HyphenStr::from_str("2000-01-01")?;

date.assign(newdate);
assert_eq!(date.as_str(), "2000-01-01");
assert_eq!(buf, *b"2000-01-01");

#[must_use]pub fn as_str(&self) -> &str[src]

Returns a string slice.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

assert_eq!(date.as_str(), "2001-12-31");

#[must_use]pub fn as_bytes(&self) -> &[u8][src]

Returns a byte slice.

If you want to use indexed access, prefer as_bytes_fixed_len.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

assert_eq!(date.as_bytes(), b"2001-12-31");

#[must_use]pub fn as_bytes_fixed_len(&self) -> &[u8; 10][src]

Returns a fixed length byte slice.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

let fixed_len: &[u8; 10] = date.as_bytes_fixed_len();
assert_eq!(fixed_len, b"2001-12-31");

#[must_use]pub fn year_str(&self) -> &str[src]

Returns the year as a string slice.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

assert_eq!(date.year_str(), "2001");

#[must_use]pub fn year_bytes_fixed_len(&self) -> &[u8; 4][src]

Returns the year as a fixed length byte slice.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

let year_fixed_len: &[u8; 4] = date.year_bytes_fixed_len();
assert_eq!(year_fixed_len, b"2001");

#[must_use]pub fn year(&self) -> u16[src]

Returns the year as an integer.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

assert_eq!(date.year(), 2001);

#[must_use]pub fn month_str(&self) -> &str[src]

Returns the month as a string slice.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

assert_eq!(date.month_str(), "12");

#[must_use]pub fn month_bytes_fixed_len(&self) -> &[u8; 2][src]

Returns the month as a fixed length byte slice.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

let month_fixed_len: &[u8; 2] = date.month_bytes_fixed_len();
assert_eq!(month_fixed_len, b"12");

#[must_use]pub fn month1(&self) -> u8[src]

Returns the 1-based month as an integer.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

assert_eq!(date.month1(), 12);

#[must_use]pub fn month0(&self) -> u8[src]

Returns the 0-based month as an integer.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

assert_eq!(date.month0(), 11);

#[must_use]pub fn mday_str(&self) -> &str[src]

Returns the day of month as a string slice.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

assert_eq!(date.mday_str(), "31");

#[must_use]pub fn mday_bytes_fixed_len(&self) -> &[u8; 2][src]

Returns the day of month as a fixed length byte slice.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

let mday_fixed_len: &[u8; 2] = date.mday_bytes_fixed_len();
assert_eq!(mday_fixed_len, b"31");

#[must_use]pub fn mday(&self) -> u8[src]

Returns the day of month as an integer.

Examples

let date = Ymd8HyphenStr::from_str("2001-12-31")?;

assert_eq!(date.mday(), 31);

pub fn set_year(&mut self, year: u16) -> Result<(), Error>[src]

Sets the given year to the string.

Failures

  • Fails if year is greater than 9999.
  • Fails if the datetime after modification is invalid.

Examples

let mut buf: [u8; 10] = *b"2000-02-29";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "2000-02-29");

date.set_year(2004)?;
assert_eq!(date.as_str(), "2004-02-29");

assert!(date.set_year(2001).is_err(), "2001-02-29 is invalid");

pub fn set_month0(&mut self, month0: u8) -> Result<(), Error>[src]

Sets the given 0-based month value to the string.

Failures

  • Fails if the datetime after modification is invalid.

Examples

let mut buf: [u8; 10] = *b"2001-12-31";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "2001-12-31");

date.set_month0(7)?;
assert_eq!(date.as_str(), "2001-08-31");

assert!(date.set_month0(8).is_err(), "2001-09-31 is invalid");

pub fn set_month1(&mut self, month1: u8) -> Result<(), Error>[src]

Sets the given 1-based month value to the string.

Failures

  • Fails if the datetime after modification is invalid.

Examples

let mut buf: [u8; 10] = *b"2001-12-31";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "2001-12-31");

date.set_month1(8)?;
assert_eq!(date.as_str(), "2001-08-31");

assert!(date.set_month1(9).is_err(), "2001-09-31 is invalid");

pub fn set_mday(&mut self, mday: u8) -> Result<(), Error>[src]

Sets the given day of month value to the string.

Failures

  • Fails if the datetime after modification is invalid.

Examples

let mut buf: [u8; 10] = *b"2001-02-28";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "2001-02-28");

date.set_mday(3)?;
assert_eq!(date.as_str(), "2001-02-03");

assert!(date.set_mday(29).is_err(), "2001-02-29 is invalid");

pub fn set_month0_mday(&mut self, month0: u8, mday: u8) -> Result<(), Error>[src]

Sets the given 0-based month and 1-based day of month values to the string.

Failures

  • Fails if the datetime after modification is invalid.

Examples

let mut buf: [u8; 10] = *b"2001-02-28";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "2001-02-28");

date.set_month0_mday(3, 23)?;
assert_eq!(date.as_str(), "2001-04-23");

assert!(date.set_month0_mday(1, 29).is_err(), "2001-02-29 is invalid");

pub fn set_month1_mday(&mut self, month1: u8, mday: u8) -> Result<(), Error>[src]

Sets the given 1-based month and day of month values to the string.

Failures

  • Fails if the datetime after modification is invalid.

Examples

let mut buf: [u8; 10] = *b"2001-02-28";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "2001-02-28");

date.set_month1_mday(4, 23)?;
assert_eq!(date.as_str(), "2001-04-23");

assert!(date.set_month1_mday(2, 29).is_err(), "2001-02-29 is invalid");

pub fn set_ym0d(&mut self, year: u16, month0: u8, mday: u8) -> Result<(), Error>[src]

Sets the given 1-based year, 0-based month, and 1-based day of month values to the string.

Failures

  • Fails if year is greater than 9999.
  • Fails if the datetime after modification is invalid.

Examples

let mut buf: [u8; 10] = *b"2001-02-28";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "2001-02-28");

date.set_ym0d(1999, 3, 23)?;
assert_eq!(date.as_str(), "1999-04-23");

assert!(date.set_ym0d(1999, 1, 29).is_err(), "1999-02-29 is invalid");

pub fn set_ym1d(&mut self, year: u16, month1: u8, mday: u8) -> Result<(), Error>[src]

Sets the given 1-based year, month, and day of month values to the string.

Failures

  • Fails if year is greater than 9999.
  • Fails if the datetime after modification is invalid.

Examples

let mut buf: [u8; 10] = *b"2001-02-28";
let date = Ymd8HyphenStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(date.as_str(), "2001-02-28");

date.set_ym1d(1999, 4, 23)?;
assert_eq!(date.as_str(), "1999-04-23");

assert!(date.set_ym1d(1999, 2, 29).is_err(), "1999-02-29 is invalid");

pub fn yday0(&self) -> u16[src]

Returns the 0-based day of the year, i.e. days since January 1 of the year.

Note that this value is 0-based. January 1 is 0 days since January 1 of the year.

Examples

let date = Ymd8HyphenStr::from_str("1970-01-01")?;
assert_eq!(date.yday0(), 0, "0 for the 1st day of the year, because this is 0-based value");

let date2 = Ymd8HyphenStr::from_str("1970-12-31")?;
assert_eq!(date2.yday0(), 364);

let leap_last = Ymd8HyphenStr::from_str("2000-12-31")?;
assert_eq!(leap_last.yday0(), 365, "2000-02-29 exists");

pub fn yday1(&self) -> u16[src]

Returns the 1-based day of the year.

Note that this value is 1-based. January 1 is 1st day of the year.

Examples

let date = Ymd8HyphenStr::from_str("1970-01-01")?;
assert_eq!(date.yday1(), 1, "1 for the 1st day of the year, because this is 1-based value");

let date2 = Ymd8HyphenStr::from_str("1970-12-31")?;
assert_eq!(date2.yday1(), 365);

let leap_last = Ymd8HyphenStr::from_str("2000-12-31")?;
assert_eq!(leap_last.yday1(), 366, "2000-02-29 exists");

pub fn days_since_epoch(&self) -> i32[src]

Returns the days from the epoch (1970-01-01).

Examples

let date = Ymd8HyphenStr::from_str("1971-01-01")?;
assert_eq!(date.days_since_epoch(), 365);

let date2 = Ymd8HyphenStr::from_str("1969-01-01")?;
assert_eq!(date2.days_since_epoch(), -365);

let epoch = Ymd8HyphenStr::from_str("1970-01-01")?;
assert_eq!(epoch.days_since_epoch(), 0);

Trait Implementations

impl AsMut<Ymd8HyphenStr> for Ymd8HyphenStr[src]

impl AsMut<Ymd8HyphenStr> for Ymd8HyphenString[src]

impl AsRef<[u8]> for Ymd8HyphenStr[src]

impl AsRef<Ymd8HyphenStr> for Ymd8HyphenStr[src]

impl AsRef<Ymd8HyphenStr> for Ymd8HyphenString[src]

impl AsRef<str> for Ymd8HyphenStr[src]

impl Borrow<Ymd8HyphenStr> for Ymd8HyphenString[src]

impl BorrowMut<Ymd8HyphenStr> for Ymd8HyphenString[src]

impl Debug for Ymd8HyphenStr[src]

impl Deref for Ymd8HyphenStr[src]

type Target = str

The resulting type after dereferencing.

impl<'de> Deserialize<'de> for &'de Ymd8HyphenStr[src]

impl Display for Ymd8HyphenStr[src]

impl Eq for Ymd8HyphenStr[src]

impl<'_> From<&'_ Ymd8HyphenStr> for NaiveDate[src]

impl<'_> From<&'_ Ymd8HyphenStr> for Ymd8HyphenString[src]

impl<'a> From<&'a Ymd8HyphenStr> for &'a str[src]

impl Hash for Ymd8HyphenStr[src]

impl Ord for Ymd8HyphenStr[src]

impl<'_> PartialEq<&'_ [u8]> for Ymd8HyphenStr[src]

impl<'_> PartialEq<&'_ Ymd8HyphenStr> for Ymd8HyphenStr[src]

impl<'_> PartialEq<&'_ Ymd8HyphenStr> for [u8][src]

impl<'_> PartialEq<&'_ Ymd8HyphenStr> for str[src]

impl<'_> PartialEq<&'_ Ymd8HyphenStr> for Ymd8HyphenString[src]

impl<'_> PartialEq<&'_ str> for Ymd8HyphenStr[src]

impl PartialEq<[u8]> for Ymd8HyphenStr[src]

impl<'_> PartialEq<[u8]> for &'_ Ymd8HyphenStr[src]

impl PartialEq<Ymd8HyphenStr> for Ymd8HyphenStr[src]

impl<'_> PartialEq<Ymd8HyphenStr> for &'_ Ymd8HyphenStr[src]

impl PartialEq<Ymd8HyphenStr> for [u8][src]

impl<'_> PartialEq<Ymd8HyphenStr> for &'_ [u8][src]

impl PartialEq<Ymd8HyphenStr> for str[src]

impl<'_> PartialEq<Ymd8HyphenStr> for &'_ str[src]

impl PartialEq<Ymd8HyphenStr> for Ymd8HyphenString[src]

impl PartialEq<Ymd8HyphenString> for Ymd8HyphenStr[src]

impl<'_> PartialEq<Ymd8HyphenString> for &'_ Ymd8HyphenStr[src]

impl PartialEq<str> for Ymd8HyphenStr[src]

impl<'_> PartialEq<str> for &'_ Ymd8HyphenStr[src]

impl<'_> PartialOrd<&'_ [u8]> for Ymd8HyphenStr[src]

impl<'_> PartialOrd<&'_ Ymd8HyphenStr> for Ymd8HyphenStr[src]

impl<'_> PartialOrd<&'_ Ymd8HyphenStr> for [u8][src]

impl<'_> PartialOrd<&'_ Ymd8HyphenStr> for str[src]

impl<'_> PartialOrd<&'_ Ymd8HyphenStr> for Ymd8HyphenString[src]

impl<'_> PartialOrd<&'_ str> for Ymd8HyphenStr[src]

impl PartialOrd<[u8]> for Ymd8HyphenStr[src]

impl<'_> PartialOrd<[u8]> for &'_ Ymd8HyphenStr[src]

impl PartialOrd<Ymd8HyphenStr> for Ymd8HyphenStr[src]

impl<'_> PartialOrd<Ymd8HyphenStr> for &'_ Ymd8HyphenStr[src]

impl PartialOrd<Ymd8HyphenStr> for [u8][src]

impl<'_> PartialOrd<Ymd8HyphenStr> for &'_ [u8][src]

impl PartialOrd<Ymd8HyphenStr> for str[src]

impl<'_> PartialOrd<Ymd8HyphenStr> for &'_ str[src]

impl PartialOrd<Ymd8HyphenStr> for Ymd8HyphenString[src]

impl PartialOrd<Ymd8HyphenString> for Ymd8HyphenStr[src]

impl<'_> PartialOrd<Ymd8HyphenString> for &'_ Ymd8HyphenStr[src]

impl PartialOrd<str> for Ymd8HyphenStr[src]

impl<'_> PartialOrd<str> for &'_ Ymd8HyphenStr[src]

impl Serialize for Ymd8HyphenStr[src]

impl StructuralEq for Ymd8HyphenStr[src]

impl StructuralPartialEq for Ymd8HyphenStr[src]

impl ToOwned for Ymd8HyphenStr[src]

type Owned = Ymd8HyphenString

The resulting type after obtaining ownership.

impl<'a> TryFrom<&'a [u8]> for &'a Ymd8HyphenStr[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a mut [u8]> for &'a mut Ymd8HyphenStr[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a mut str> for &'a mut Ymd8HyphenStr[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a str> for &'a Ymd8HyphenStr[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]