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

pkg/time: support conversion of time to unix #319

Open
cueckoo opened this issue Jul 3, 2021 · 3 comments
Open

pkg/time: support conversion of time to unix #319

cueckoo opened this issue Jul 3, 2021 · 3 comments
Labels
Accepted builtin Discuss Requires maintainer discussion FeatureRequest New feature or request

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

Originally opened by @rogpeppe in cuelang/cue#319

Currently we can convert from unix seconds to RFC3339 but not vice-versa.
It would also be nice to be able to add dates, etc.

@cueckoo cueckoo added Accepted builtin FeatureRequest New feature or request labels Jul 3, 2021
@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @antong in cuelang/cue#319 (comment)

I was looking for a way to write constraints on time fields, such as to require a field to be within a certain time range. I think having a function to convert to UNIX time would help. When you say "add dates, etc.", do you mean expose functions for time arithmetic like the Go time.Sub(), Add(), AddDate() and so on? I think that would be useful. And being able to convert to UNIX time would allow to do this with the durations that can already be parsed and validated by the time package.

About time constraints, If I understand correctly the time values as handled by the time package are actually RFC3339Nano formatted strings. (If this is so, we should probably document it. I didn't see it explicitly stated in the package doc.) As the doc says, RFC3339Nano doesn't necessarily sort correctly, so I feel a bit uneasy about that. But I guess it can only sort incorrectly between values that fall within the same second.

@oncilla
Copy link
Contributor

oncilla commented Aug 4, 2021

I would like to work on this.

I propose the following usage:

import "time"

timestamp: "2021-08-04T18:37:48Z00:00"

unixTime: 1628102268
unixTime: time.ToUnix(timestamp) 

nanoTime: 1628102268 * 1G
nanoTime: time.ToUnixNano(timestamp) 

If you agree, let me know, and I can start working on this.

oncilla added a commit to oncilla/cue that referenced this issue Aug 4, 2021
@myitcv myitcv added the Discuss Requires maintainer discussion label Aug 10, 2021
@myitcv
Copy link
Member

myitcv commented Aug 10, 2021

Thanks for your interest, @oncilla - @mpvl and I will discuss at our next issue review session and revert back.

@myitcv myitcv added zzz Discuss and removed Discuss Requires maintainer discussion labels Jan 29, 2022
@myitcv myitcv added Discuss Requires maintainer discussion and removed zzz Discuss labels Feb 9, 2022
@myitcv myitcv added the zGarden label Jun 15, 2023
@mvdan mvdan removed the zGarden label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted builtin Discuss Requires maintainer discussion FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants