Skip to content

Achsion/iso8601

Repository files navigation

iso8601 Duration parser and formatter

GoDoc GoReport

The current go native time pkg does not support any ISO 8601 duration strings.

This library provides the functionality to parse and format a native Go time.Duration to and from an ISO 8601-2 duration string.

What is still missing?

Currently, fast formatting (Format) does not support duration parts smaller than one second.

Installation

go get github.com/Achsion/iso8601/v2

will resolve and add the package to the current development module, along with its dependencies.

Usage

package main

import (
	"github.com/Achsion/iso8601"
)

func main() {
	// Quick parsing to go duration:
	duration, err := iso8601.ParseToDuration("P1Y1M1DT1H1M1.1S")

	// Slower, but more complete parsing to custom duration struct:
	isoDuration, err := iso8601.DurationFromString("P1Y1M1DT1H1M1.1S")
}

About

A fast iso8601 duration parser

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages