Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Seconds from Duration #373

Open
kevin-lindsay-1 opened this issue Jun 1, 2023 · 2 comments
Open

Parse Seconds from Duration #373

kevin-lindsay-1 opened this issue Jun 1, 2023 · 2 comments

Comments

@kevin-lindsay-1
Copy link

Attempting to simplify some templates, and currently I have a section that needs to create a duration and perform some math on it, and output certain fields as seconds. As a result, I need to have my template specify a duration in hours, minutes, and seconds. Once done, I then multiply those to get seconds, and then convert that duration.

Instead, it would be nice to be able to specify a duration and change it.

Current way to have to do this: Link to playground

Desired way to do this: Link to playground

@jouve
Copy link

jouve commented Sep 25, 2023

you could play tricks with dateModify+unixEpoch

{{- $now := now -}}
{{ sub ($now | dateModify "1h35m8s" | dateModify "-10s" | unixEpoch) ($now | unixEpoch) | duration }}

@42atomys
Copy link

Hello everyone 👋,

I wanted to let you know that this issue has been addressed in the fork of this project at go-sprout/sprout. The fix has been implemented starting from version v0.3.0.

With new function toDuration introduced in v0.3.0, the issue should be resolved.

The function is used to convert the string representation of the duration to the time.Duration type.
You can new do this by using the following code snippet:

{{ "1m32s" | toDuration | dateModify "+10s" }} // Output: 1m42s

For those looking for a solution, I recommend checking out the latest releases of the fork. This should help address the issue discussed in this thread.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants