durationstring

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 5 Imported by: 1

README

durationstring

A simple Go package for working with string format durations, e.g. 1d4h

Usage

Parsing
d, err :=  durationstring.Parse("1d4h5ns")

assert.Equal(t, 1, d.Days)
assert.Equal(t, 4, d.Hours)
assert.Equal(t, 5, d.Nanoseconds)
String formatting
d := durationstring.NewDuration(1, 0, 0, 4, 0, 0, 0, 0, 0)
s := d.String()

assert.Equal(t, "1y4h", s)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration struct {
	Years        int
	Months       int
	Days         int
	Hours        int
	Minutes      int
	Seconds      int
	Milliseconds int
	Microseconds int
	Nanoseconds  int
}

func NewDuration

func NewDuration(years, months, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds int) *Duration

func Parse

func Parse(s string) (d *Duration, err error)

Parse takes string s and returns the duration in years, months, days, hours, minutes, seconds, nanoseconds, with a non-nil error if there was an error with parsing. Expects s in format ([0-9]+(y|mo|d|h|m|s|ns))+, and accepts any order e.g. 5y4m, 5s4d

func (*Duration) String

func (d *Duration) String() string

Jump to

Keyboard shortcuts

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