Skip to content

Commit b2f13fc

Browse files
committed
Add support for the TZ environment variable in twc.c
1 parent 6a814eb commit b2f13fc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Australia/Sydney 2023-12-11 08:39:43 +1100
2424
for ≈ `600` entries.
2525
- 🔒 _**Robust**_ - tested to work with all [tz database] entries,
2626
`version 2023c`.
27-
- 📦 **Self-contained** - zero dependencies, lighweight, ISO C99,
28-
(`2676 bytes`, `140 lines`).
27+
- 📦 **Self-contained** - zero dependencies, ISO C99, lighweight (`2676
28+
bytes`, `140 lines`).
2929

3030
## Getting Started
3131

@@ -65,10 +65,17 @@ Files:
6565
Stores valid tz database identifiers to be displayed by twc.
6666
6767
Examples:
68+
$ twc -h -s %Y-%m-%d -t Japan/Tokyo
69+
2023-12-11
6870
71+
$ TZ=America/Los_Angeles twz
72+
2023-12-11T04:25:37-0800
73+
74+
Environment:
75+
TZ Timezone to use when displaying dates. See environ(7).
6976
7077
See also:
71-
time(3), strftime(3)
78+
time(3), strftime(3), environ(7)
7279
```
7380

7481
## Compatibility

twc.c

+5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ int main(int argc, char **argv) {
114114

115115
timefmt = time_fmts[TIMEFMT_ISO];
116116

117+
const char *tz_env = getenv("TZ");
118+
if (tz_env) {
119+
fmt = tz_env;
120+
}
121+
117122
while ((opt = getopt(argc, argv, "hf:s:t:")) != -1) {
118123
switch (opt) {
119124
case 'h':

0 commit comments

Comments
 (0)