silk.time.plain_month_day.

Days of the year without a year: the PlainMonthDay type, such as November 19.

When to use#

Use PlainMonthDay for a day that comes back every year: a birthday, an anniversary, a fixed holiday. PlainMonthDay.atYear gives the date in one year.

Details#

The month and the day are in the ISO 8601 calendar. February 29 is a valid value. The text form is MM-DD.

Examples#

Find a birthday in two years#

silk
import silk.core.option { Option }
import silk.time.period { Overflow }
import silk.time.plain_date { PlainDate }
import silk.time.plain_month_day { PlainMonthDay }

pub fn main() -> i32 {
  let birthday = PlainMonthDay.make(2, 29)
  match birthday.atYear(2028, Overflow.Reject) {
    Option<PlainDate>.Some { value } => {
      if value.day() != 29 {
        return 1
      }
    }
    Option<PlainDate>.None => {
      return 2
    }
  }
  // 2027 has no February 29.
  match birthday.atYear(2027, Overflow.Constrain) {
    Option<PlainDate>.Some { value } => {
      if value.day() != 28 {
        return 3
      }
    }
    Option<PlainDate>.None => {
      return 4
    }
  }
  return 0
}

Import as PlainMonthDay with import silk.time.plain_month_day { PlainMonthDay }.

Public declarations: 1.

PlainMonthDay#

silk
pub struct PlainMonthDay

A month and a day of the month, without a year, in the ISO 8601 calendar.

Details#

== and != compare the month and the day. There is no order, because a day of the year is neither before nor after another without a year. Display writes MM-DD.

Implementation Copy for PlainMonthDay#

silk
impl Copy for PlainMonthDay

Implementation PlainMonthDay#

silk
impl PlainMonthDay

Associated function make#

silk
pub fn make(month: u8, day: u8) -> PlainMonthDay

Returns day day of month month, from 1 to 12.

Gotchas#

A day that no year has, such as February 30, traps. PlainMonthDay.checkedMake returns None instead.

Associated function checkedMake#

silk
pub fn checkedMake(month: u8, day: u8) -> Option<PlainMonthDay>

Returns day day of month month, from 1 to 12, or None when no year has that day. February 29 is valid.

Associated function fromDate#

silk
pub fn fromDate(date: PlainDate) -> PlainMonthDay

Returns the month and the day of date.

Method month#

silk
pub fn month(self: Self) -> u8

Returns the month, from 1 for January to 12 for December.

Method day#

silk
pub fn day(self: Self) -> u8

Returns the day of the month, from 1.

Method atYear#

silk
pub fn atYear(self: Self, year: i32, overflow: Overflow) -> Option<PlainDate>

Returns the date of this day in the year year, or None when the date is outside the range of PlainDate, or when the year has no such day and overflow is Reject.

Details#

Only February 29 can be absent from a year. Overflow.Constrain then gives February 28.

Associated function parse#

silk
pub fn parse(text: string) -> Result<PlainMonthDay, TimeParseError>

Reads a month and a day from ISO 8601 text such as 11-19.

Details#

The text is MM-DD or MMDD, optionally after --, as in --11-19. Bracketed annotations can follow. The text can also be a whole date, with or without a time, in the form that PlainDate.parse reads; the year is checked and then ignored.

Errors#

  • TimeParseReason.UnexpectedEnd or UnexpectedCharacter if the text does not have that form.

  • TimeParseReason.OutOfRange if no year has that month and day.

  • TimeParseReason.UtcNotAllowed if the text has the UTC designator Z.

  • TimeParseReason.UnsupportedCalendar if a calendar annotation is not [u-ca=iso8601].

  • TimeParseReason.UnknownCriticalAnnotation if an annotation with an unknown key starts with !.

Associated function parseBytes#

silk
pub fn parseBytes(bytes: &[u8]) -> Result<PlainMonthDay, TimeParseError>

Reads a month and a day from the bytes of ISO 8601 text such as 11-19.

Details#

The form is the one of PlainMonthDay.parse.

Errors#

Implementation Equal for PlainMonthDay#

silk
impl Equal for PlainMonthDay

Operation equals#

silk
equals: PlainMonthDay.same

Implementation Display for PlainMonthDay#

silk
impl Display for PlainMonthDay

Writes the month and the day as MM-DD, as in 11-19.

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> ()
    ! WriterError
    ? &mut Writer

Implementation Debug for PlainMonthDay#

silk
impl Debug for PlainMonthDay

Writes the same text as Display: the month and the day as MM-DD.

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> ()
    ! WriterError
    ? &mut Writer

Category: Time.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page