Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ pub fn main() void {
var env = try std.process.getEnvMap(allocator);
defer env.deinit();

// Get an instant in time. The default gets "now" in UTC
const now = try zeit.instant(.{});
var threaded: std.Io.Threaded = .init_single_threaded;
var io = threaded.io();
defer io.deinit();

// Get an instant in time. The default gets "now" in UTC,
// and requires io to read from the system clock
const now = try zeit.instant(.{ .io = io });

// Load our local timezone. This needs an allocator. Optionally pass in a
// *const std.process.EnvMap to support TZ and TZDIR environment variables
Expand Down Expand Up @@ -56,7 +61,7 @@ pub fn main() void {
const vienna = try zeit.loadTimeZone(alloc, .@"Europe/Vienna", &env);
defer vienna.deinit();

// Parse an Instant from an ISO8601 or RFC3339 string
// Parse an Instant from an ISO8601 or RFC3339 string. io is not needed
const iso = try zeit.instant(.{
.source = .{
.iso8601 = "2024-03-16T08:38:29.496-1200",
Expand Down
4 changes: 2 additions & 2 deletions src/timezone.zig
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ pub const TZInfo = struct {
},
};

pub fn parse(allocator: std.mem.Allocator, reader: *std.io.Reader) !TZInfo {
pub fn parse(allocator: std.mem.Allocator, reader: *std.Io.Reader) !TZInfo {
var legacy_header = try reader.takeStruct(Header, .big); // handles endianness for us
if (!std.mem.eql(u8, &legacy_header.magic, "TZif")) return error.BadHeader;
if (legacy_header.version != 0 and legacy_header.version != '2' and legacy_header.version != '3') return error.BadVersion;
Expand All @@ -545,7 +545,7 @@ pub const TZInfo = struct {
}
}

fn parseBlock(allocator: std.mem.Allocator, reader: *std.io.Reader, header: Header, legacy: bool) !TZInfo {
fn parseBlock(allocator: std.mem.Allocator, reader: *std.Io.Reader, header: Header, legacy: bool) !TZInfo {
if (header.counts.isstdcnt != 0 and header.counts.isstdcnt != header.counts.typecnt) return error.Malformed; // rfc8536: isstdcnt [...] MUST either be zero or equal to "typecnt"
if (header.counts.isutcnt != 0 and header.counts.isutcnt != header.counts.typecnt) return error.Malformed; // rfc8536: isutcnt [...] MUST either be zero or equal to "typecnt"
if (header.counts.typecnt == 0) return error.Malformed; // rfc8536: typecnt [...] MUST NOT be zero
Expand Down
Loading