Fast, CLI world clock that displays time zone information using tz database to read valid tz entries.
$ twc -h -f tz-small.conf
America/New York 2023-12-10 16:39:43 -0500
America/Los Angeles 2023-12-10 13:39:43 -0800
UTC 2023-12-10 21:39:43 +0000
Europe/London 2023-12-10 21:39:43 +0000
Europe/Paris 2023-12-10 22:39:43 +0100
Asia/Tokyo 2023-12-11 06:39:43 +0900
Australia/Sydney 2023-12-11 08:39:43 +1100
- 🚀 Fast - 6X times faster than
date
1.twc
executes in only ≈8 ms
for one entry, and ≈177 ms
for ≈600
entries. - 🔒 Robust - tested to work with all tz database entries,
version 2023c
. - 📦 Self-contained - zero dependencies, ISO C99, lighweight (
2676 bytes
,140 lines
).
Clone the repository:
git clone https://github.com/Neved4/twc
Build the sources:
$ make twc
cc twc.c -o twc
Alternatively, if you have zig
installed:
$ zig cc twc.c
twc [-h] [-s FORMAT] [-f FILE | -t ENTRY] ...
Options:
-h Prints time in “human-readable” output instead of ISO 8601.
-f Specify a file to read entries from.
-s Use a different date format to print the time.
-t Manually specify a tz database entry.
Files:
~/.config/twc/tz.conf
Stores valid tz database identifiers to be displayed by twc.
Examples:
$ twc -h -s %Y-%m-%d -t Japan/Tokyo
2023-12-11
$ TZ=America/Los_Angeles twz
2023-12-11T04:25:37-0800
Environment:
TZ Timezone to use when displaying dates. See environ(7).
See also:
time(3), strftime(3), environ(7)
Runs on Linux, macOS and *BSD systems on x86_64
and
arm64
, and compiles with zig
, clang
, gcc
and any other
compiler that supports C99 or later.
twc
is compatible with ISO 9945:2009, also known as
POSIX.1-2017 as well as ISO/IEC 9899 known as C23.1 2
Special thanks to everybody who helped me with pointers and measuring optimal, safe memory allocation at every step of the program, @K4rakara for her code review, and @finnoleary, for getting me started.
twc
is licensed under the terms of the MIT License.
See the LICENSE file for details.
Footnotes
-
cfr.
date
command that takes ≈931 ms
for ≈600
entries. ↩ ↩2 -
IEEE Std 1003.1-2017: Standard for Information Technology — Portable Operating System Interface (POSIX®), ISO/IEC/IEEE 9945:2009/COR 2:2017. URL: https://pubs.opengroup.org/onlinepubs/9699919799/ ↩