with
Returns a new PlainYearMonth with some fields replaced by new values.
Parameters
- self:PlainYearMonth
- PlainYearMonth
- options:WithOptions
- WithOptions
Source
Implementation
pub fn with(self: PlainYearMonth, options: WithOptions) !PlainYearMonth {
// Build month_code view
const month_code_view = if (options.month_code) |mc|
abi.toDiplomatStringView(mc)
else
abi.c.DiplomatStringView{ .data = null, .len = 0 };
// Build partial date with only the fields we want to modify
const partial_date = abi.c.PartialDate{
.year = if (options.year) |y| abi.toOption(abi.c.OptionI32, y) else .{ .is_ok = false },
.month = if (options.month) |m| abi.toOption(abi.c.OptionU8, m) else .{ .is_ok = false },
.day = .{ .is_ok = false },
.month_code = month_code_view,
.era = .{ .data = null, .len = 0 },
.era_year = .{ .is_ok = false },
.calendar = abi.c.AnyCalendarKind_Iso,
};
const overflow = abi.c.ArithmeticOverflow_option{
.is_ok = true,
.unnamed_0 = .{ .ok = abi.c.ArithmeticOverflow_Constrain },
};
return wrapPlainYearMonth(abi.c.temporal_rs_PlainYearMonth_with(
self._inner,
partial_date,
overflow,
));
}