hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 02e09a92ac424ae9d16bab0a5248372cc66f856b
parent 655b285db25226fa483323e0a4fa50fc1e603e7a
Author: Willow Barraco <contact@willowbarraco.fr>
Date:   Tue, 26 Nov 2024 19:06:21 +0100

time::chrono: fix loading TZ filepaths

The doc says:

> If [name] is a full filepath (begins with '/'), it is used directly instead.

But the function was still prefixing with TZDB_PATH when using an
absolute path.

This cause a huge problem on Alpine linux, when the user uses the
setup-timezone without the -i. The setup would copy the timezone file
from /usr/share/zoneinfo/** to /etc/zoneinfo/**. Meaning date::localnow
would just fallback to UTC.

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
Signed-off-by: Byron Torres <b@torresjrjr.com>
Co-authored-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mtime/chrono/timezone.ha | 8+++++++-
Mtime/chrono/tzdb.ha | 6+++---
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha @@ -191,7 +191,13 @@ export const LOCAL: locality = &TZ_UTC; case void => yield match (os::realpath(LOCALTIME_PATH)) { case let path: str => - yield path; + yield if (strings::hasprefix(path, TZDB_PATH)) { + yield strings::sub( + path, len(TZDB_PATH), strings::end, + ); + } else { + yield path; + }; case => return; }; diff --git a/time/chrono/tzdb.ha b/time/chrono/tzdb.ha @@ -30,10 +30,10 @@ export type invalidtzif = !void; // All localities returned default to the [[utc]] [[timescale]] and // [[EARTH_DAY]] day-length. export fn tz(name: str) (locality | tzdberror) = { - const filepath = if (!strings::hasprefix(name, TZDB_PATH)) { - yield path::init(TZDB_PATH, name); - } else { + const filepath = if (strings::hasprefix(name, "/")) { yield path::init(name); + } else { + yield path::init(TZDB_PATH, name); }; const filepath = match (filepath) { case let buf: path::buffer =>