Skip to content

axkit/hms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hms package

Build Status Go Report Card GoDoc Coverage Status

The hms package provides a simple time handling within a day.

Installation

To install the package, run:

go get github.com/axkit/hms

Usage

Creating a new HMS instance

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
}

Adding durations

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

Parsing from string

h, err := hms.Parse("01:02:03")
if err != nil {
	fmt.Println("Error:", err)
} else {
	fmt.Println(h) // Output: 01:02:03
}

Converting to duration

h := hms.New(3661 * time.Second)
d := h.ToDuration()
fmt.Println(d) // Output: 1h1m1s

Errors

ErrParseFailed

Returned by parsing functions when an invalid format/character is encountered.

Running Tests

To run the tests, use:

go test ./...

License

This package is open-source and distributed under the MIT License. Contributions and feedback are welcome!

About

Go package to handle time within a day

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages