withPlainTime
Returns a new PlainDateTime with the time fields replaced by the given PlainTime (or zeroed if null).
Parameters
- self:PlainDateTime
- PlainDateTime
- time:?PlainTime
- ?PlainTime
Source
Implementation
pub fn withPlainTime(self: PlainDateTime, time: ?PlainTime) !PlainDateTime {
const new_hour: u8 = if (time) |tt| tt.hour() else 0;
const new_minute: u8 = if (time) |tt| tt.minute() else 0;
const new_second: u8 = if (time) |tt| tt.second() else 0;
const new_millisecond: u16 = if (time) |tt| tt.millisecond() else 0;
const new_microsecond: u16 = if (time) |tt| tt.microsecond() else 0;
const new_nanosecond: u16 = if (time) |tt| tt.nanosecond() else 0;
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(
self.year(),
self.month(),
self.day(),
new_hour,
new_minute,
new_second,
new_millisecond,
new_microsecond,
new_nanosecond,
cal_kind,
));
}