Help us shape the future of Go! Take the 2026 Go Developer Survey

iso8601

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package iso8601 parses and formats the PnDTnHnMnS/PTnHnMnS subset of ISO 8601 durations used by Azure Service Bus's LockDuration/ DefaultMessageTimeToLive XML properties, and by ARM's equivalent JSON properties on Microsoft.ServiceBus queue/topic/subscription resources. Extracted from services/azureservicebus (M5) when services/azurearm (M9) became a second caller needing the exact same logic -- mirroring pkgs/odatatable's earlier extraction for the same reason (AZURE.md section 9's M6 milestone).

Index

Constants

View Source
const Zero = "PT0S"

Zero is the shortest valid ISO 8601 representation of "no duration", used by Format for a non-positive input.

Variables

View Source
var ErrInvalidDuration = errors.New("iso8601: invalid duration")

ErrInvalidDuration is returned by Parse for a string that doesn't match the supported PnDTnHnMnS/PTnHnMnS subset.

Functions

func Format

func Format(d time.Duration) string

Format is Parse's inverse. A non-positive duration formats as Zero.

func Parse

func Parse(s string) (time.Duration, error)

Parse parses the PnDTnHnMnS/PTnHnMnS subset of ISO 8601 durations used by Service Bus's LockDuration and DefaultMessageTimeToLive properties (MaxDeliveryCount, unlike those two, is a plain integer, not a duration, and does not go through this parser). Fractional seconds are supported. A value that would overflow time.Duration's int64-nanosecond range is clamped to the maximum representable time.Duration (~292 years) rather than erroring -- real Service Bus's own "infinite" sentinel for these fields, "P10675199DT2H48M5.4775807S", is itself just .NET's TimeSpan.MaxValue (which is exactly math.MaxInt64 100-nanosecond ticks, i.e. very close to Go's own int64-nanosecond time.Duration ceiling) spelled out in ISO 8601, so this clamp is a deliberate, documented approximation of that sentinel rather than a real precision loss for any duration Service Bus itself would ever produce.

Types

This section is empty.

Jump to

Keyboard shortcuts

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