chore: add todo for timezone()
This commit is contained in:
parent
a4c2e4cd7a
commit
b03d42e72d
3 changed files with 23 additions and 8 deletions
|
|
@ -523,8 +523,10 @@ pub fn run(allocator: std.mem.Allocator, io_optional: ?std.Io) !void {
|
|||
});
|
||||
|
||||
if (io_optional) |io| {
|
||||
const now_zdt = try Temporal.Now.zonedDateTimeISO(io);
|
||||
const now_zdt = try Temporal.Now.zonedDateTimeISO(allocator, io);
|
||||
defer now_zdt.deinit();
|
||||
const now_tz_id = try Temporal.Now.timeZoneId(allocator);
|
||||
defer allocator.free(now_tz_id);
|
||||
std.log.info(
|
||||
\\Now Coverage
|
||||
\\ - timeZoneId(): {s}
|
||||
|
|
@ -532,7 +534,7 @@ pub fn run(allocator: std.mem.Allocator, io_optional: ?std.Io) !void {
|
|||
\\
|
||||
\\
|
||||
, .{
|
||||
Temporal.Now.timeZoneId(),
|
||||
now_tz_id,
|
||||
try now_zdt.toString(allocator, .{}),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ pub fn fromEpochMilliseconds(epoch_ms: i64) !Instant {
|
|||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/fromEpochNanoseconds
|
||||
pub fn fromEpochNanoseconds(epoch_ns: i128) !Instant {
|
||||
const parts = abi.toI128Nanoseconds(epoch_ns);
|
||||
|
||||
return wrapInstant(abi.c.temporal_rs_Instant_try_new(parts));
|
||||
}
|
||||
|
||||
|
|
|
|||
24
src/Now.zig
24
src/Now.zig
|
|
@ -79,17 +79,28 @@ pub fn plainTimeISO(io: std.Io) !PlainTime {
|
|||
|
||||
/// Returns a time zone identifier representing the system's current time zone.
|
||||
///
|
||||
/// The caller owns the returned slice and must free it with `allocator`.
|
||||
///
|
||||
/// TODO: Detect the system's actual IANA time zone instead of always returning
|
||||
/// "UTC". This requires platform-specific logic:
|
||||
/// - Linux/macOS: resolve the `/etc/localtime` symlink to `.../zoneinfo/<Area>/<City>`.
|
||||
/// - Windows: read the time zone from the registry and map the Windows zone
|
||||
/// name to an IANA identifier via the CLDR `windowsZones` table.
|
||||
/// - WASI: no host time zone is available; "UTC" is the only honest answer.
|
||||
///
|
||||
/// See: [MDN Temporal.Now.timeZoneId](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Now/timeZoneId)
|
||||
pub fn timeZoneId() []const u8 {
|
||||
return "UTC";
|
||||
pub fn timeZoneId(allocator: std.mem.Allocator) ![]const u8 {
|
||||
return allocator.dupe(u8, "UTC");
|
||||
}
|
||||
|
||||
/// Returns the current date and time as a [`Temporal.ZonedDateTime`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime) object, in the ISO 8601 calendar and the specified time zone.
|
||||
///
|
||||
/// See: [MDN Temporal.Now.zonedDateTimeISO](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Now/zonedDateTimeISO)
|
||||
pub fn zonedDateTimeISO(io: std.Io) !ZonedDateTime {
|
||||
pub fn zonedDateTimeISO(allocator: std.mem.Allocator, io: std.Io) !ZonedDateTime {
|
||||
const now = try instant(io);
|
||||
const time_zone = try ZonedDateTime.TimeZone.init(timeZoneId());
|
||||
const tz_id = try timeZoneId(allocator);
|
||||
defer allocator.free(tz_id);
|
||||
const time_zone = try ZonedDateTime.TimeZone.init(tz_id);
|
||||
return ZonedDateTime.fromEpochNanoseconds(now.epochNanoseconds(), time_zone);
|
||||
}
|
||||
|
||||
|
|
@ -167,12 +178,13 @@ test plainTimeISO {
|
|||
try std.testing.expect(t.second() < 60);
|
||||
}
|
||||
test timeZoneId {
|
||||
const tz = timeZoneId();
|
||||
const tz = try timeZoneId(std.testing.allocator);
|
||||
defer std.testing.allocator.free(tz);
|
||||
try std.testing.expectEqualStrings("UTC", tz);
|
||||
}
|
||||
test zonedDateTimeISO {
|
||||
const io = std.testing.io;
|
||||
const zdt = try zonedDateTimeISO(io);
|
||||
const zdt = try zonedDateTimeISO(std.testing.allocator, io);
|
||||
defer zdt.deinit();
|
||||
|
||||
std.log.info("{d}", .{zdt.epochNanoseconds()});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue