TemporalZ

with

Returns a new PlainDateTime with some fields replaced.

Parameters

#
self:PlainDateTime
PlainDateTime
partial:WithOptions
WithOptions

Source

Implementation

#
pub fn with(self: PlainDateTime, partial: WithOptions) !PlainDateTime {
    // Extract fields from partial, or use current values as defaults
    const new_year = partial.year orelse self.year();
    const new_month = partial.month orelse self.month();
    const new_day = partial.day orelse self.day();
    const new_hour = partial.hour orelse self.hour();
    const new_minute = partial.minute orelse self.minute();
    const new_second = partial.second orelse self.second();
    const new_millisecond = partial.millisecond orelse self.millisecond();
    const new_microsecond = partial.microsecond orelse self.microsecond();
    const new_nanosecond = partial.nanosecond orelse self.nanosecond();

    // Preserve calendar
    const calendar_ptr = abi.c.temporal_rs_PlainDateTime_calendar(self._inner) orelse return error.TemporalError;
    const cal_id_view = abi.c.temporal_rs_Calendar_identifier(calendar_ptr);
    const cal_view = abi.c.DiplomatStringView{ .data = cal_id_view.data, .len = cal_id_view.len };
    const cal_result = abi.c.temporal_rs_AnyCalendarKind_parse_temporal_calendar_string(cal_view);
    const cal_kind = try abi.extractResult(cal_result);

    return wrapPlainDateTime(abi.c.temporal_rs_PlainDateTime_try_new(
        new_year,
        new_month,
        new_day,
        new_hour,
        new_minute,
        new_second,
        new_millisecond,
        new_microsecond,
        new_nanosecond,
        cal_kind,
    ));
}