| 1 | commit 957d704139d6430fcce7e5b0d7058572f220ab09
|
| 2 | Author: Jonas Meeuws <[email protected]>
|
| 3 | Date: Thu Mar 12 01:27:34 2026 +0100
|
| 4 |
|
| 5 | std.datetime.timezone: Support the TZDIR environment variable on POSIX.
|
| 6 |
|
| 7 | diff --git a/std/datetime/timezone.d b/std/datetime/timezone.d
|
| 8 | index 6a1898b0e..4e7b1f95b 100644
|
| 9 | |
| 10 | |
| 11 | @@ -2033,7 +2033,15 @@ public:
|
| 12 | }
|
| 13 | else version (Posix)
|
| 14 | {
|
| 15 | - enum defaultTZDatabaseDir = "/usr/share/zoneinfo/";
|
| 16 | + static nothrow
|
| 17 | + string defaultTZDatabaseDir()
|
| 18 | + {
|
| 19 | + import std.exception : assumeWontThrow;
|
| 20 | + import std.process : environment;
|
| 21 | + return environment
|
| 22 | + .get("TZDIR", "/usr/share/zoneinfo/")
|
| 23 | + .assumeWontThrow; // nothrow on POSIX
|
| 24 | + }
|
| 25 | }
|
| 26 | else version (Windows)
|
| 27 | {
|
| 28 | @@ -2455,11 +2463,13 @@ public:
|
| 29 | // RefCounted variable, but here, no references to the payload is
|
| 30 | // escaped to the outside, so this should be @trusted
|
| 31 | () @trusted {
|
| 32 | - foreach (DirEntry de; dirEntries(tzDatabaseDir, SpanMode.depth))
|
| 33 | + foreach (DirEntry de; dirEntries(tzDatabaseDir, SpanMode.depth, false))
|
| 34 | {
|
| 35 | if (de.isFile)
|
| 36 | {
|
| 37 | auto tzName = de.name[tzDatabaseDir.length .. $];
|
| 38 | + if (tzName.startsWith("/"))
|
| 39 | + tzName = tzName[1 .. $];
|
| 40 |
|
| 41 | if (!tzName.extension().empty ||
|
| 42 | !tzName.startsWith(subName) ||
|