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!
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:
durationSecondsdurationMillisecondsdurationMicrosecondsdurationNanosecondsdurationMinutesdurationHoursdurationDaysdurationWeeksThese functions would return the duration expressed in the corresponding unit (typically as an integer or float, depending on Sprig conventions).
Duration manipulation
durationRoundTo: Round a duration to a specified duration (time.Duration.Roundfunction).durationTruncateTo: Truncate a duration to a specified duration (time.Duration.Truncatefunction).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!