duration

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 4 Imported by: 21

README

duration Test GoDoc

duration.Parse() parses a formatted string and returns the time.Duration value it represents.

Usage

package duration_test

import (
	"fmt"

	"github.com/k1LoW/duration"
)

func ExampleParse() {
	d, _ := duration.Parse("3 days 4 hours")
	fmt.Printf("%s", d)
	// Output: 76h0m0s
}

Supported unit of time

Unit of time value
ns time.Nanosecond
nsec time.Nanosecond
nanosecond time.Nanosecond
nanoseconds time.Nanosecond
us time.Microsecond
usec time.Microsecond
microsecond time.Microsecond
microseconds time.Microsecond
ms time.Millisecond
msec time.Millisecond
millisecond time.Millisecond
milliseconds time.Millisecond
s time.Second
sec time.Second
second time.Second
seconds time.Second
m time.Minute
min time.Minute
minute time.Minute
minutes time.Minute
h time.Hour
hour time.Hour
hours time.Hour
d time.Hour * 24
day time.Hour * 24
days time.Hour * 24
w time.Hour * 24 * 7
week time.Hour * 24 * 7
weeks time.Hour * 24 * 7

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(s string) (time.Duration, error)

Parse parses a formatted string and returns the time.Duration value it represents.

Example
package main

import (
	"fmt"
	"log"

	"github.com/k1LoW/duration"
)

func main() {
	d, err := duration.Parse("3 days 4 hours")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s", d)
}
Output:

76h0m0s

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL