Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mazeyqian/asiatz
A Go library for converting timezones and other utilities, with a focus on Asia Time Zone.
https://github.com/mazeyqian/asiatz
asia go golang library timezone utc utility
Last synced: 16 days ago
JSON representation
A Go library for converting timezones and other utilities, with a focus on Asia Time Zone.
- Host: GitHub
- URL: https://github.com/mazeyqian/asiatz
- Owner: mazeyqian
- License: mit
- Created: 2017-10-09T08:41:38.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2023-12-17T09:41:38.000Z (11 months ago)
- Last Synced: 2023-12-17T10:33:13.449Z (11 months ago)
- Topics: asia, go, golang, library, timezone, utc, utility
- Language: Go
- Homepage:
- Size: 11 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# asiatz
Asiatz is a Go library for converting timezones and other utilities, with a focus on Asia Time Zone. It provides functions to convert various time zones to UTC time.
## Installation
To use Asiatz in your Go project, you can import it using the following command:
```shell
go get github.com/mazeyqian/asiatz
```## Usage
To use the timezone conversion functions, first import this package:
```go
import "github.com/mazeyqian/asiatz"
```Then, call the appropriate function with a time string in the format "HH:mm":
```go
utcTime, err := asiatz.ShanghaiToUTC("08:00")
if err != nil {
// handle error
}
fmt.Println(utcTime) // Output: 00:00
```Here is a list of supported time zones and their corresponding functions:
| Time Zone | Function Name |
|-------------|----------------|
| Shanghai | ShanghaiToUTC |
| Tokyo | TokyoToUTC |
| Hong Kong | HongKongToUTC |
| Singapore | SingaporeToUTC |
| Taipei | TaipeiToUTC |
| Seoul | SeoulToUTC |
| Beijing | BeijingToUTC |
| Dubai | DubaiToUTC |
| Delhi | DelhiToUTC |
| Jakarta | JakartaToUTC |
| Bangkok | BangkokToUTC |
| Pyongyang | PyongyangToUTC |The `ToUTC` function is a helper function used by the timezone conversion functions in the `time_utils.go` file. It takes two arguments: `offset` and `timeString`.
The `offset` argument specifies the UTC offset for the given time zone. For example, the UTC offset for Shanghai is +8, so you would pass 8 as the `offset` argument when converting a Shanghai time string to UTC.
The `timeString` argument is a string in the format "HH:mm" that represents the time in the given time zone.
The `ToUTC` function returns a string in the same format ("HH:mm") that represents the equivalent time in UTC.
Here's an example usage of the `ToUTC` function:
```go
utcTime, err := ToUTC(8, "08:00")
if err != nil {
// handle error
}
fmt.Println(utcTime) // Output: 00:00
```In this example, we're converting a Shanghai time string ("08:00") to its equivalent UTC time string ("00:00"). We pass 8 as the `offset` argument since Shanghai's UTC offset is +8.
## Contributing
If you find a bug or have an idea for a new feature, please open an issue on the GitHub repository. Pull requests are also welcome!
## License
This library is licensed under the MIT license. See the LICENSE file for more details.