sprig icon indicating copy to clipboard operation
sprig copied to clipboard

Proposal: add toDuration

Open andig opened this issue 1 year ago • 2 comments

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.

andig avatar Nov 26 '23 04:11 andig

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

cbandy avatar Dec 08 '23 15:12 cbandy

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!

42atomys avatar May 09 '24 18:05 42atomys