TemporalZ

toZonedDateTime

Returns a ZonedDateTime by combining this date-time with a time zone.

Parameters

#
self:PlainDateTime
PlainDateTime
options:ToZonedDateTimeOptions
ToZonedDateTimeOptions

Source

Implementation

#
pub fn toZonedDateTime(self: PlainDateTime, options: ToZonedDateTimeOptions) !ZonedDateTime {
    const tz_view = abi.toDiplomatStringView(options.timeZone);
    const tz_result = abi.c.temporal_rs_TimeZone_try_from_str(tz_view);
    const time_zone = try abi.extractResult(tz_result);

    // Convert to PlainDate and PlainTime
    const date = try self.toPlainDate();
    const time = try self.toPlainTime();

    // Use PlainDate's toZonedDateTime with the time component
    const ptr = (try abi.extractResult(abi.c.temporal_rs_PlainDate_to_zoned_date_time(date._inner, time_zone, time._inner))) orelse return abi.TemporalError.Generic;

    return .{ ._inner = ptr };
}