humanduration

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 5 Imported by: 1

README

humanduration

convert a human readable duration to time.Duration

Go Documentation

this module is a port of parse-duration, from JavaScript to Go.

usage

go get git.sr.ht/~nbsp/humanduration

contributing

send patches to the mailing list. prefix patches with "[PATCH humanduration]".

see the guide to git send-email if this is your first time using sourcehut.

license

humanduration is licensed under the MIT license. refer to the license for details.

Documentation

Overview

Package humanduration implements a parser from human-readable durations to time.Duration.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidUnit = errors.New("invalid unit")

ErrInvalidUnit signifies that the specified unit could not be parsed into a duration.

Functions

func Parse

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

Parse takes a human-readable duration and converts it to a Go time.Duration.

Example
package main

import (
	"fmt"

	"git.sr.ht/~nbsp/humanduration"
)

func main() {
	duration, _ := humanduration.Parse("1 day, 3hrs 2sec")
	fmt.Println(duration)
}
Output:

27h0m2s

Types

This section is empty.

Jump to

Keyboard shortcuts

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