Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Neved4 committed Dec 11, 2023
0 parents commit f0dffa6
Show file tree
Hide file tree
Showing 8 changed files with 811 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.go]
indent_style = tab
indent_size = 4
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tools/** linguist-vendored
Dockerfile linguist-vendored
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang:latest
WORKDIR /app
COPY twc.go /app
ENV CFLAGS=-O2
RUN go build -o twc .
CMD ["./twc"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (C) 2023 Neveda

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
![Go](https://img.shields.io/badge/Go-00ADD8?logo=go&logoColor=fff)
[![CodeQL](https://github.com/github/docs/actions/workflows/codeql.yml/badge.svg)](https://github.com/Neved4/twc/actions/workflows/codeql.yml)

# `twc.go` - simple world clock in Go 🦦

Fast, CLI world clock that displays time zone information using
[tz database] to read valid [tz entries].

```console
$ twc -h -f tools/samples/tz-small.conf
America/New_York 2023-12-11 12:37:13
America/Los_Angeles 2023-12-11 09:37:13
UTC 2023-12-11 17:37:13
Europe/London 2023-12-11 17:37:13
Europe/Paris 2023-12-11 18:37:13
Asia/Tokyo 2023-12-12 02:37:13
Australia/Sydney 2023-12-12 04:37:13
```

### Highlights

- 🚀 _**Fast**_ - **10X times faster than [twc.c], 65X times faster than
`date`**.[^1] Only ≈ `7 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,
lighweight (`1555 bytes`, `67 lines`).

## Getting Started

### Setup

Clone the repository:

```sh
git clone https://github.com/Neved4/twc
```

Build:

```console
$ go build twc.go
```

### Usage

```
flag provided but not defined: -z
Usage of ./twc:
-f string
Specify file path (default "tz-small.conf")
-h Print human-readable format
-s string
Specify time format
-t string
Specify timezone directly
Examples:
$ twc -h -s %Y-%m-%d -t Asia/Tokyo
2006-01-02
$ TZ=America/Los_Angeles twz
2006-01-02T15:04:05-0800
Environment:
TZ Timezone to use when displaying dates.
See also:
environ(7)
```

## Compatibility

Runs on _**Linux**_, _**macOS**_ and _**\*BSD**_ systems on [`x86_64`] and
[`arm64`], and compiles with and any other.

## License
`twc` is licensed under the terms of the [MIT License].

See the [LICENSE](LICENSE) file for details.

[`hyperfine`]: https://github.com/sharkdp/hyperfine
[`twc.c`]: https://github.com/Neved4/twc
[`arm64`]: https://en.wikipedia.org/wiki/AArch64
[`x86_64`]: https://en.wikipedia.org/wiki/X86-64
[MIT License]: https://opensource.org/license/mit/
[tz database]: https://en.wikipedia.org/wiki/Tz_database
[tz entries]: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

[^1]: _cfr._ `date` command that takes ≈ `931 ms` for ≈ `600` entries.
Measured with [`hyperfine`].
[^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/
[^3]: _ISO/IEC 9899:2023: Standard for Information Technology
— Programming languages — C_, ISO/IEC 9899:2023. \
URL: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf
7 changes: 7 additions & 0 deletions tools/samples/tz-small.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
America/New_York
America/Los_Angeles
UTC
Europe/London
Europe/Paris
Asia/Tokyo
Australia/Sydney
Loading

0 comments on commit f0dffa6

Please sign in to comment.