from
Creates a PlainDateTime from another PlainDateTime, PlainDate, PlainTime, or from a string (ISO 8601) or UTF-16 array.
Parameters
- info:anytype
- anytype
- opts:FromOptions
- FromOptions
Source
Implementation
pub fn from(info: anytype, opts: FromOptions) !PlainDateTime {
const T = @TypeOf(info);
const overflow = if (opts.overflow) |f| abi.to.toArithmeticOverflow(f) else null;
if (T == PlainDateTime) return info.clone();
if (T == PlainTime) return abi.c.temporal_rs_PlainDateTime_from_partial(.{ .time = info._inner }, abi.toArithmeticOverflowOption(overflow));
if (T == PlainDate) return abi.c.temporal_rs_PlainDateTime_from_partial(.{ .date = info._inner }, abi.toArithmeticOverflowOption(overflow));
// Handle string types (both literals and slices)
const type_info = @typeInfo(T);
switch (type_info) {
.pointer => |ptr_info| {
const ChildType = switch (@typeInfo(ptr_info.child)) {
.array => |arr| arr.child,
else => ptr_info.child,
};
if (ChildType == u8) return fromUtf8(info);
if (ChildType == u16) return fromUtf16(info);
return abi.TemporalError.Generic;
},
else => return abi.TemporalError.Generic,
}
}