~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH hare v5] time::chrono: use TZDIR environment variable

Antero Mejr <antero@mailbox.org>
Details
Message ID
<20220707170545.7619-1-antero@mailbox.org>
DKIM signature
pass
Download raw message
Patch: +15 -7
Sets TZ_LOCAL.name correctly when TZDIR does not end in a slash.

Reference:
tzset(3)
https://man.archlinux.org/man/tzset.3.en

tzselect(8)
https://man.archlinux.org/man/tzselect.8.en

Signed-off-by: Antero Mejr <antero@mailbox.org>
---
 time/chrono/leapsec.ha  | 10 ++++++----
 time/chrono/timezone.ha |  9 +++++++--
 time/chrono/tzdb.ha     |  3 ++-
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/time/chrono/leapsec.ha b/time/chrono/leapsec.ha
index 7706475f..505fb5e7 100644
--- a/time/chrono/leapsec.ha
+++ b/time/chrono/leapsec.ha
@@ -5,6 +5,7 @@ use encoding::utf8;
use fs;
use io;
use os;
use path;
use strconv;
use strings;

@@ -32,16 +33,17 @@ use strings;
// accurate enough to account for small changes in time.
export def SECS_1900_1970: i64 = 2208988800;

// The filepath of the system's leap-seconds.list file.
export def UTC_LEAPSECS_FILE: str = "/usr/share/zoneinfo/leap-seconds.list";

// UTC timestamps and their offsets from TAI, sourced from the system's
// leap-seconds.list file.
let utc_leapsecs: [](i64, i64) = [];

@init fn init_utc_leapsecs() void = {
	os::init_cwd();
	const file = match (os::open(UTC_LEAPSECS_FILE)) {
	const tzdir = os::tryenv("TZDIR", ZONEINFO_PREFIX);
	let leap_seconds_path = path::init();
	path::add(&leap_seconds_path, tzdir, "leap-seconds.list")!;
	const utc_leapsecs_file = path::string(&leap_seconds_path);
	const file = match (os::open(utc_leapsecs_file)) {
	case let file: io::file =>
		yield file;
	case fs::error =>
diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha
index 52615b35..c459b136 100644
--- a/time/chrono/timezone.ha
+++ b/time/chrono/timezone.ha
@@ -240,9 +240,14 @@ let TZ_LOCAL: timezone = timezone {
		};
		defer io::close(file)!;

		if (strings::hasprefix(filepath, ZONEINFO_PREFIX)) {
		const tzdir = os::tryenv("TZDIR", ZONEINFO_PREFIX);
		let tzdir_path = path::init();
		path::add(&tzdir_path, tzdir, "/")!;
		const tzdir_str = path::string(&tzdir_path);

		if (strings::hasprefix(filepath, tzdir_str)) {
			TZ_LOCAL.name = strings::trimprefix(
				filepath, ZONEINFO_PREFIX,
				filepath, tzdir_str,
			);
		};

diff --git a/time/chrono/tzdb.ha b/time/chrono/tzdb.ha
index 876d85d9..c9a63bbb 100644
--- a/time/chrono/tzdb.ha
+++ b/time/chrono/tzdb.ha
@@ -37,7 +37,8 @@ export fn strerror(err: error) const str = {
export fn tz(name: str) (timezone | fs::error | io::error | invalidtzif) = {
// TODO: Consolidate errors (use chrono::error?).
	const filepath = path::init();
	path::add(&filepath, ZONEINFO_PREFIX, name)!;
	const tzdir = os::tryenv("TZDIR", ZONEINFO_PREFIX);
	path::add(&filepath, tzdir, name)!;
	const fpath = path::string(&filepath);
	const file = os::open(fpath)?;

-- 
2.36.1

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CL9L7OQJAPS6.12ZSULH1PTR6E@cirno>
In-Reply-To
<20220707170545.7619-1-antero@mailbox.org> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 1m36s

[time::chrono: use TZDIR environment variable][0] v5 from [Antero Mejr][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/33636
[1]: antero@mailbox.org

✓ #796831 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/796831
✓ #796832 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/796832
Details
Message ID
<CLPJW8QNVNEW.2V8IZQE4V3RHO@megumin>
In-Reply-To
<20220707170545.7619-1-antero@mailbox.org> (view parent)
DKIM signature
pass
Download raw message
On Thu Jul 7, 2022 at 7:05 PM CEST, Antero Mejr wrote:
>  @init fn init_utc_leapsecs() void = {
>  	os::init_cwd();
> -	const file = match (os::open(UTC_LEAPSECS_FILE)) {
> +	const tzdir = os::tryenv("TZDIR", ZONEINFO_PREFIX);
> +	let leap_seconds_path = path::init();
> +	path::add(&leap_seconds_path, tzdir, "leap-seconds.list")!;

Should use path::set here. We can also just call the leap_seconds_path
variable "path" or "buf" or something, no need to get verbose.
Reply to thread Export thread (mbox)