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 IsExpired ¶
IsExpired reports whether a cache entry last refreshed at updatedAt has exceeded ttl.
A zero TTL (see IsZeroTTL) is always expired. A non-zero TTL is parsed with ParseDuration; on a parse error the error is returned and callers should fail safe by treating the entry as expired to avoid serving stale data. This helper makes no decision for an empty ttl (""). The meaning of "no TTL configured" differs between subsystems (reuse-forever versus refresh-each-run), so callers handle "" explicitly.
func IsZeroTTL ¶
IsZeroTTL reports whether the TTL string represents a zero duration.
ParseDuration rejects "0" (a zero duration is not a valid period for cleanup scheduling), but for cache TTLs a zero value is a legitimate, common case meaning "always expired / never reuse". Callers detect it with this helper before parsing.
func Parse ¶
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 ¶
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.