Skip to content
Snippets Groups Projects
Ada's avatar
Ada authored
5030179c
History

A go lib for parsing human readable time duration

This library parses 1d1h1m1s format similarly to gostd time.Duration().

Why write a library instead of using time.Duration() ?

Because the standard library does not support the day unit.

Known limitations

  • Units have to be in a specific order (Greater to lower : d→h→m→s).

  • No support for units smaller than seconds.

Example :

package main

import (
    "gitlab.gnous.eu/ada/atp"
    "fmt"
)

func main() {
    t, err := atp.ParseDuration("1d2h")
    if err != nil {
        panic(err)
    }

    fmt.Println(t)
}