Is there a way to get timezone information with stdlib or an external zig lib?

hi, I didn’t find anything in the standard library. There is gettimeofday but is POSIX it is obsolete and it also seems to be broken.

Its replacement is clock_gettime(), which is indeed available as std.os.clock_gettime():

var tp: std.os.timespec = undefined;
try std.os.clock_gettime(std.os.system.CLOCK.REALTIME, &tp);

Broken how? Do you have a reproducible test case? If it is truly and consistently broken, would you consider filing a bug report?

Unfortunately you can’t get timezone info with this one.

I’ll check, but I think it’s not zig fault but broken upstream.

I searched for the string localtime inside zig stdlib and found no results. I think that the file /etc/localtime is essential for this. I’d say that getting timezone info is currently not possible with the stdlib.

As far as I know, to get timezone info you need to parse tzif files, where the one corresponding to the user’s current timezone is symlinked to /etc/localtime.

Here’s a library that can do the parsing for you:

Here’s how I use it in bork:

In my case I also use another package called datetime, but that’s not strictly necessary.

Ah, bummer, that’s true.

FWIW I think date/time/calendar utilities an area where the stdlib is undercooked right now, but getting that stuff right is hard =)