duration

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

README

Duration

ISO 8601 duration parse

Example

duration, err := duration.Parse("P3Y6M4DT12H30M5S")
if err != nil {
    ...
}
fmt.Printf("%#v\n", data)
// Output: duration.Duration{Year:3, Month:6, Day:4, Hour:12, Minute:30, Second:5}

Format

ISO 8601 duration format ISO 8601 Durations are expressed using the following format, where (n) is replaced by the value for each of the date and time elements that follow the (n):

P(n)Y(n)M(n)DT(n)H(n)M(n)S

Where:

  • P is the duration designator (referred to as "period"), and is always placed at the beginning of the duration.
  • Y is the year designator that follows the value for the number of years.
  • M is the month designator that follows the value for the number of months.
  • W is the week designator that follows the value for the number of weeks.
  • D is the day designator that follows the value for the number of days.
  • T is the time designator that precedes the time components.
  • H is the hour designator that follows the value for the number of hours.
  • M is the minute designator that follows the value for the number of minutes.
  • S is the second designator that follows the value for the number of seconds.

License

GNU General Public License v3.0 or later

See LICENSE to see the full text.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrParsing = errors.New("parsing error")

ErrParsing represents a parsing error

Functions

This section is empty.

Types

type Duration

type Duration struct {
	Year   float64
	Month  float64
	Day    float64
	Hour   float64
	Minute float64
	Second float64
}

Duration represents a iso8601 duration

func Parse

func Parse(input string) (Duration, error)

Parse parses a duration in iso8601 format

Example
package main

import (
	"fmt"

	"github.com/jacoelho/duration"
)

func main() {
	data, _ := duration.Parse("P3Y6M4DT12H30M5S")
	fmt.Printf("%#v\n", data)
}
Output:

duration.Duration{Year:3, Month:6, Day:4, Hour:12, Minute:30, Second:5}

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Duration) String

func (d Duration) String() string

Strings implements fmt.Stringer

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Jump to

Keyboard shortcuts

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