Skip to content

Commit f0dffa6

Browse files
committed
Initial commit
0 parents  commit f0dffa6

File tree

8 files changed

+811
-0
lines changed

8 files changed

+811
-0
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
[*.go]
9+
indent_style = tab
10+
indent_size = 4

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tools/** linguist-vendored
2+
Dockerfile linguist-vendored

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM golang:latest
2+
WORKDIR /app
3+
COPY twc.go /app
4+
ENV CFLAGS=-O2
5+
RUN go build -o twc .
6+
CMD ["./twc"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (C) 2023 Neveda
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
![Go](https://img.shields.io/badge/Go-00ADD8?logo=go&logoColor=fff)
2+
[![CodeQL](https://github.com/github/docs/actions/workflows/codeql.yml/badge.svg)](https://github.com/Neved4/twc/actions/workflows/codeql.yml)
3+
4+
# `twc.go` - simple world clock in Go 🦦
5+
6+
Fast, CLI world clock that displays time zone information using
7+
[tz database] to read valid [tz entries].
8+
9+
```console
10+
$ twc -h -f tools/samples/tz-small.conf
11+
America/New_York 2023-12-11 12:37:13
12+
America/Los_Angeles 2023-12-11 09:37:13
13+
UTC 2023-12-11 17:37:13
14+
Europe/London 2023-12-11 17:37:13
15+
Europe/Paris 2023-12-11 18:37:13
16+
Asia/Tokyo 2023-12-12 02:37:13
17+
Australia/Sydney 2023-12-12 04:37:13
18+
```
19+
20+
### Highlights
21+
22+
- 🚀 _**Fast**_ - **10X times faster than [twc.c], 65X times faster than
23+
`date`**.[^1] Only ≈ `7 ms` for one entry, and ≈ `177 ms` for ≈ 600
24+
entries.
25+
- 🔒 _**Robust**_ - tested to work with all [tz database] entries,
26+
`version 2023c`.
27+
- 📦 **Self-contained** - zero dependencies,
28+
lighweight (`1555 bytes`, `67 lines`).
29+
30+
## Getting Started
31+
32+
### Setup
33+
34+
Clone the repository:
35+
36+
```sh
37+
git clone https://github.com/Neved4/twc
38+
```
39+
40+
Build:
41+
42+
```console
43+
$ go build twc.go
44+
```
45+
46+
### Usage
47+
48+
```
49+
flag provided but not defined: -z
50+
Usage of ./twc:
51+
-f string
52+
Specify file path (default "tz-small.conf")
53+
-h Print human-readable format
54+
-s string
55+
Specify time format
56+
-t string
57+
Specify timezone directly
58+
59+
Examples:
60+
$ twc -h -s %Y-%m-%d -t Asia/Tokyo
61+
2006-01-02
62+
63+
$ TZ=America/Los_Angeles twz
64+
2006-01-02T15:04:05-0800
65+
66+
Environment:
67+
TZ Timezone to use when displaying dates.
68+
69+
See also:
70+
environ(7)
71+
```
72+
73+
## Compatibility
74+
75+
Runs on _**Linux**_, _**macOS**_ and _**\*BSD**_ systems on [`x86_64`] and
76+
[`arm64`], and compiles with and any other.
77+
78+
## License
79+
80+
`twc` is licensed under the terms of the [MIT License].
81+
82+
See the [LICENSE](LICENSE) file for details.
83+
84+
[`hyperfine`]: https://github.com/sharkdp/hyperfine
85+
[`twc.c`]: https://github.com/Neved4/twc
86+
[`arm64`]: https://en.wikipedia.org/wiki/AArch64
87+
[`x86_64`]: https://en.wikipedia.org/wiki/X86-64
88+
[MIT License]: https://opensource.org/license/mit/
89+
[tz database]: https://en.wikipedia.org/wiki/Tz_database
90+
[tz entries]: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
91+
92+
[^1]: _cfr._ `date` command that takes ≈ `931 ms` for ≈ `600` entries.
93+
Measured with [`hyperfine`].
94+
[^2]: _IEEE Std 1003.1-2017: Standard for Information Technology
95+
— Portable Operating System Interface (POSIX®)_, \
96+
ISO/IEC/IEEE 9945:2009/COR 2:2017. URL: https://pubs.opengroup.org/onlinepubs/9699919799/
97+
[^3]: _ISO/IEC 9899:2023: Standard for Information Technology
98+
— Programming languages — C_, ISO/IEC 9899:2023. \
99+
URL: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf

tools/samples/tz-small.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
America/New_York
2+
America/Los_Angeles
3+
UTC
4+
Europe/London
5+
Europe/Paris
6+
Asia/Tokyo
7+
Australia/Sydney

0 commit comments

Comments
 (0)