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

Proposal: add toDuration #388

Open
andig opened this issue Nov 26, 2023 · 2 comments
Open

Proposal: add toDuration #388

andig opened this issue Nov 26, 2023 · 2 comments

Comments

@andig
Copy link

andig commented Nov 26, 2023

I'm using templates to build more complex yaml configuration based on user input without that user input being parsed into go types first. For purpose of calculating with durations I've added this:

"toDuration": func(v string) time.Duration {
	d, err := time.ParseDuration(v)
	if err != nil {
		panic(err)
	}
	return d
},

Seems this would be a good fit for the type conversion functions.

@cbandy
Copy link

cbandy commented Dec 8, 2023

I would like this as well. I am generating files where the output must be milliseconds, but I would like to read and write using time.Duration format. For example:

timeout: {{ (toDuration "3m").Milliseconds }}

renders

timeout: 180000

42atomys added a commit to go-sprout/sprout that referenced this issue May 9, 2024
## Description
This pull request introduce the `toDuration` as proposed in #8 and
Masterminds#388 using the `cast`
package.

## Changes
- Add the function `toDuration`

## Fixes #8 

## Checklist
- [x] I have read the **CONTRIBUTING.md** document.
- [x] My code follows the code style of this project.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [ ] I have updated the documentation accordingly.
- [x] This change requires a change to the documentation on the website.
@42atomys
Copy link

42atomys commented May 9, 2024

Hello everyone 👋,

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

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