Skip to content

Add duration helper functions to Sprig date functions #466

@aeroyorch

Description

@aeroyorch

Context

While working on improving duration handling in Helm templates, we identified a set of duration helper functions that would be useful.

An initial proposal was made in Helm repository: helm/helm#31695

During that discussion, it was suggested that these helpers would fit better in Sprig, as it is already used by Helm and the functionality is not Helm-specific.

Proposed functions

Duration parsing:

  • mustToDuration: Parse a duration string (e.g. "5m", "2h30m", or seconds like "1", "1.5", etc.) into a duration value, failing on error.

Duration unit extractors:

  • durationSeconds
  • durationMilliseconds
  • durationMicroseconds
  • durationNanoseconds
  • durationMinutes
  • durationHours
  • durationDays
  • durationWeeks

These functions would return the duration expressed in the corresponding unit (typically as an integer or float, depending on Sprig conventions).

Duration manipulation

Status

This issue is intended as a discussion starter. The function names and exact semantics can be adjusted to align with Sprig’s conventions and maintainers’ preferences. Also if the proposal is ok, I could implement these functions and submit a PR.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions