Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matriphe/go-format
A helper to format and convert many things in Go.
https://github.com/matriphe/go-format
converter date datetime direction formatter time wind
Last synced: about 2 months ago
JSON representation
A helper to format and convert many things in Go.
- Host: GitHub
- URL: https://github.com/matriphe/go-format
- Owner: matriphe
- License: mit
- Created: 2023-03-05T18:20:07.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-26T22:04:56.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T11:44:54.481Z (3 months ago)
- Topics: converter, date, datetime, direction, formatter, time, wind
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Format
A helper to format and convert many things in Go.
I'm fed up with the repetitive formatting of many things, especially the weird Go date format 🙄, so I decided to create a package to not repeat myself.
## Install
As usual, run: `go get github.com/matriphe/go-format`.
## Usage
### Date and Time
```go
package mainimport (
"fmt"
"time"
"github.com/matriphe/go-format/datetime"
)func main() {
theTime := time.Date(2023, 3, 5, 18, 45, 21, 0, time.UTC)
fmt.Println(theTime.Format(datetime.ISODate)) // print '2023-03-05'
fmt.Println(datetime.ToISODate(theTime)) // print '2023-03-05'
_, _ = datetime.FromISODate("2023-03-05") // parse to time.Timefmt.Println(theTime.Format(datetime.ISOTime)) // print '18:45:21'
fmt.Println(datetime.ToISOTime(theTime)) // print '18:45:21'
_, _ = datetime.FromISOTime("18:45:21") // parse to time.Timefmt.Println(theTime.Format(datetime.ISOHourMin)) // print '18:45'
fmt.Println(datetime.ToISOHourMin(theTime)) // print '18:45'
_, _ = datetime.FromISOHourMin("18:45") // parse to time.Timefmt.Println(theTime.Format(datetime.ISODateTime)) // print '2023-03-05 18:45:21'
fmt.Println(datetime.ToISODateTime(theTime)) // print '2023-03-05 18:45:21'
_, _ = datetime.FromISODateTime("2023-03-05 18:45:21") // parse to time.Time
}
```### Wind
This package converts wind [direction in degree to cardinal directional](http://snowfence.umn.edu/Components/winddirectionanddegrees.htm).
The reference of this function is from [Stackoverflow](https://stackoverflow.com/a/7490772/3460840).
```go
package mainimport (
"fmt"
"github.com/matriphe/go-format/wind"
)func main() {
fmt.Println(wind.Direction(90)) // print 'E'
fmt.Println(wind.Direction(13)) // print 'NNE'
}
```# License
This package is released under [MIT license](LICENSE).