duration

package
v1.206.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package duration provides utilities for parsing human-readable duration strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(s string) (int64, error)

Parse parses a duration string into seconds.

Supported formats:

  • Integer seconds: "3600" → 3600
  • Duration with suffix: "1h", "30m", "7d", "10s" → seconds
  • Keywords: "minute", "hourly", "daily", "weekly", "monthly", "yearly"

Examples:

Parse("3600")    → 3600, nil
Parse("1h")      → 3600, nil
Parse("7d")      → 604800, nil
Parse("daily")   → 86400, nil
Parse("invalid") → 0, error

func ParseDuration

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

ParseDuration parses a duration string and returns a time.Duration.

This is a convenience wrapper around Parse that converts the result from seconds to time.Duration.

Examples:

ParseDuration("1h")    → 1 * time.Hour, nil
ParseDuration("7d")    → 7 * 24 * time.Hour, nil
ParseDuration("daily") → 24 * time.Hour, nil

Types

This section is empty.

Jump to

Keyboard shortcuts

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