carvel-dev / ytt

YAML templating tool that works on YAML structure instead of text
https://carvel.dev/ytt
Apache License 2.0
1.66k stars 135 forks source link

time module #426

Open cppforlife opened 3 years ago

cppforlife commented 3 years ago

Describe the problem/challenge you have

even though ytt does not have access to current time, it's handy to be able to work with date/time formats. for example i'd like to parse two iso8601 timestamps, compare them or increment/decrement them.

Example of a timestamp i'd like to work with (from k8s): creationTimestamp: "2021-06-11T05:00:49Z" and want to be able to add/substract durations (as desribed by go's time.Duration)

Describe the solution you'd like

i think exposing time functionality as provided by go will be the easiest way to go about this. lets discuss the api for time module in this issue.


Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible" 👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

pivotaljohn commented 3 years ago

Is this specifically about ytt templates being able to parse strings into time.Time?

Or are you thinking that this involves plumbing through https://yaml.org/type/timestamp.html . Meaning that if a timestamp is specified in say a Data Value (with the !!timestamp tag), it would populate in data.values as a Starlark wrapper for time.Time?

pivotaljohn commented 3 years ago

This is certainly in scope for what ytt aims to do. Reads like a valuable (if general) use-case. ==> "carvel accepted"

We're chatting about scope on this. ==> "discussion"

cppforlife commented 3 years ago

Is this specifically about ytt templates being able to parse strings into time.Time?

this. definitely not the other. also time.Duration.

cari-lynn commented 3 years ago

Looks like there is a time module in starlark-go. Since this was added recently and ytt is using a forked version of starlark we can take this as inspiration. It has

from_timestamp(sec, nsec)
is_valid_timezone(loc)
now()
parse_duration(d)
parseTime(x, format, location)
time(year, month, day, hour, minute, second, nanosecond, location)

With ytt being hermetic now() is not applicable. I could see a function like parseTime() as useful for supporting multiple time formats.

aaronshurley commented 3 years ago

Moving this to the Unprioritized Backlog for now. Sounds like this is something that would be beneficial but requires a little more design discussion. For now, it's not in our roadmap. Open for contributions.