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#
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#
pub struct PlainMonthDayA 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#
impl Copy for PlainMonthDayImplementation PlainMonthDay#
impl PlainMonthDayAssociated function make#
pub fn make(month: u8, day: u8) -> PlainMonthDayReturns 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#
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#
pub fn fromDate(date: PlainDate) -> PlainMonthDayReturns the month and the day of date.
Method month#
pub fn month(self: Self) -> u8Returns the month, from 1 for January to 12 for December.
Method day#
pub fn day(self: Self) -> u8Returns the day of the month, from 1.
Method atYear#
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#
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.UnexpectedEndorUnexpectedCharacterif the text does not have that form.TimeParseReason.OutOfRangeif no year has that month and day.TimeParseReason.UtcNotAllowedif the text has the UTC designatorZ.TimeParseReason.UnsupportedCalendarif a calendar annotation is not[u-ca=iso8601].TimeParseReason.UnknownCriticalAnnotationif an annotation with an unknown key starts with!.
Associated function parseBytes#
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#
The errors of
PlainMonthDay.parse.
Implementation Equal for PlainMonthDay#
impl Equal for PlainMonthDayOperation equals#
equals: PlainMonthDay.sameImplementation Display for PlainMonthDay#
impl Display for PlainMonthDayWrites the month and the day as MM-DD, as in 11-19.
Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> ()
! WriterError
? &mut WriterImplementation Debug for PlainMonthDay#
impl Debug for PlainMonthDayWrites the same text as Display: the month and the day as MM-DD.
Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> ()
! WriterError
? &mut WriterCategory: 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.