duration

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package duration provides a partial implementation of ISO8601 durations. (no months)

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadFormat is returned when parsing fails
	ErrBadFormat = errors.New("bad format string")

	ErrWeeksNotWithYearsOrMonth = errors.New("weeks are not allowed with years or months")

	ErrMonthsInDurationUseOverload = errors.New("months are not allowed with the ToDuration method, use the overload instead")
)

Functions

This section is empty.

Types

type Duration

type Duration struct {
	Years        int
	Months       int
	Weeks        int
	Days         int
	Hours        int
	Minutes      int
	Seconds      int
	MilliSeconds int
}

func FromString

func FromString(dur string) (*Duration, error)

func (*Duration) HasTimePart

func (d *Duration) HasTimePart() bool

func (*Duration) Normalize added in v0.0.17

func (d *Duration) Normalize() error

Normalize makes sure that all fields are represented as the smallest meaningful value possible by dividing them out by the conversion factor to the larger unit. e.g. if you have a duration of 10 day, 25 hour, and 61 minute, it will be normalized to 1 week 5 days, 2 hours, and 1 minute. this function does not normalize days to months, weeks to months or weeks to years as they do not always convert with the same value. it also won't normalize days to weeks if months or years are present, and will return an error if the value is invalid

func (*Duration) String

func (d *Duration) String() string

String prints out the value passed in.

func (*Duration) ToDuration

func (d *Duration) ToDuration() (time.Duration, error)

func (*Duration) ToDurationWithMonths added in v0.0.18

func (d *Duration) ToDurationWithMonths(daysInAMonth int) (time.Duration, error)

Jump to

Keyboard shortcuts

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