fix: plain-time and now fix on linux
This commit is contained in:
parent
6d5dca2ffd
commit
de05d1303d
2 changed files with 12 additions and 11 deletions
12
src/Now.zig
12
src/Now.zig
|
|
@ -77,15 +77,9 @@ pub fn plainDateTimeISO(allocator: std.mem.Allocator, io: std.Io, time_zone_like
|
||||||
///
|
///
|
||||||
/// See: [Temporal.Now.plainTimeISO](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Now/plainTimeISO)
|
/// See: [Temporal.Now.plainTimeISO](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Now/plainTimeISO)
|
||||||
pub fn plainTimeISO(allocator: std.mem.Allocator, io: std.Io, time_zone_like: ?[]const u8) !PlainTime {
|
pub fn plainTimeISO(allocator: std.mem.Allocator, io: std.Io, time_zone_like: ?[]const u8) !PlainTime {
|
||||||
const time_zone = try resolveTimeZone(allocator, io, time_zone_like);
|
const zdt = try zonedDateTimeISO(allocator, io, time_zone_like);
|
||||||
const now = try instant(io);
|
defer zdt.deinit();
|
||||||
defer now.deinit();
|
return zdt.toPlainTime();
|
||||||
|
|
||||||
const ptr = (try abi.extractResult(abi.c.temporal_rs_PlainTime_from_epoch_nanoseconds(
|
|
||||||
abi.toI128Nanoseconds(now.epochNanoseconds()),
|
|
||||||
abi.to.toTimeZone(time_zone),
|
|
||||||
))) orelse return abi.TemporalError.Generic;
|
|
||||||
return PlainTime{ ._inner = ptr };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a time zone identifier representing the system's current time zone.
|
/// Returns a time zone identifier representing the system's current time zone.
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,21 @@ pub fn init(
|
||||||
microsecond_val: u16,
|
microsecond_val: u16,
|
||||||
nanosecond_val: u16,
|
nanosecond_val: u16,
|
||||||
) !PlainTime {
|
) !PlainTime {
|
||||||
return wrapPlainTime(abi.c.temporal_rs_PlainTime_try_new(
|
if (hour_val > 23 or minute_val > 59 or second_val > 59 or
|
||||||
|
millisecond_val > 999 or microsecond_val > 999 or nanosecond_val > 999)
|
||||||
|
{
|
||||||
|
return abi.TemporalError.RangeError;
|
||||||
|
}
|
||||||
|
var buf: [18]u8 = undefined;
|
||||||
|
const s = std.fmt.bufPrint(&buf, "{d:0>2}:{d:0>2}:{d:0>2}.{d:0>3}{d:0>3}{d:0>3}", .{
|
||||||
hour_val,
|
hour_val,
|
||||||
minute_val,
|
minute_val,
|
||||||
second_val,
|
second_val,
|
||||||
millisecond_val,
|
millisecond_val,
|
||||||
microsecond_val,
|
microsecond_val,
|
||||||
nanosecond_val,
|
nanosecond_val,
|
||||||
));
|
}) catch unreachable;
|
||||||
|
return from(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a PlainTime from a string.
|
/// Parses a PlainTime from a string.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue