The hms
package provides a simple time handling within a day.
To install the package, run:
go get github.com/axkit/hms
package main
import (
"fmt"
"time"
"github.com/axkit/hms"
)
func main() {
h := hms.New(60*60 * time.Second)
fmt.Println(h) // Output: 01:00:00
}
h := hms.New(23 * time.Hour)
newH, overMidnight := h.Add(time.Hour + time.Minute)
fmt.Println(newH) // Output: 00:01:00
fmt.Println(overMidnight) // Output: true
h, err := hms.Parse("01:02:03")
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println(h) // Output: 01:02:03
}
h := hms.New(3661 * time.Second)
d := h.ToDuration()
fmt.Println(d) // Output: 1h1m1s
ErrParseFailed
Returned by parsing functions when an invalid format/character is encountered.
To run the tests, use:
go test ./...
This package is open-source and distributed under the MIT License. Contributions and feedback are welcome!