duration

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: BSD-3-Clause, MIT Imports: 7 Imported by: 16

README

iso8601duration

ISO8601 Duration Parser for Golang

This is a hard fork of ChannelMeter/iso8601duration.

Documentation

Go Reference

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")

	// ErrNoMonth is raised when a month is in the format string
	ErrNoMonth = errors.New("no months allowed")
)

Functions

This section is empty.

Types

type Duration

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

func FromString

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

func (*Duration) HasTimePart

func (d *Duration) HasTimePart() bool

func (*Duration) String

func (d *Duration) String() string

String prints out the value passed in. It's not strictly according to the ISO spec, but it's pretty close. In particular, to completely conform it would need to round up to the next largest unit. 61 seconds to 1 minute 1 second, for example. It would also need to disallow weeks mingling with other units.

func (*Duration) ToDuration

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

Directories

Path Synopsis
cmd
parse command
parse is a command-line tool to parse ISO8601 duration strings and print their Golang time.Duration equivalents.
parse is a command-line tool to parse ISO8601 duration strings and print their Golang time.Duration equivalents.

Jump to

Keyboard shortcuts

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