-
Notifications
You must be signed in to change notification settings - Fork 292
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
time.Format does something that is not intuitive #1508
Comments
I think time.Format is meant to be used to specify constraints on the format of string representations of dates and timestamps, and for that use it is quite useful and intuitive. For instance:
There is also #319 that could help manipulating dates and timestamps. But are you looking for something like a time.FormatString() that would return a string? I don't know what the arguments would be. For it to work in a general case it would have to know about locations / time zones. JSON and CUE don't have time types so have to rely on numbers and strings. It could be an interesting thing to think about how the hermetic CUE could handle something like externally defined time zones that may change suddenly with political decisions. |
Maybe time.Format just needs a different name? In its current form it is ambiguous whether "Format" is used as a noun or a verb. The name time.FormatString(layout, value) is clear in that it is not used as a constraint. Some ideas for the name of the constraint:
It may be a good convention to use boolean-y IsFoo() names for constraints, but how to distinguish constraints from actual boolean values? |
@antong @bttk It is a bit hard to change the names, as it would break configurations, but we are pre-v1, so we can do it with a bit of transition plan. This is one potential path: Note that we already have This is a bit ugly for boolean checks, but ultimately it is probably nicer to have separate builtins for validators and simple boolean checks, as it just reads better. So the path would be: Phase 1: Introduce Phase 1b: Phase 2: Phase 3 (a few 0.x.0 versions later): Phase 4: |
So the easiest to provide the functionality for now is to introduce |
As for |
Down the line, FormatString should replace Format with new semantics. It is added now as FormatString to aid in the transition. Closes #1508 Change-Id: I1d80aab593a7e8b18dd500d73aef12fb9e5bfa4b Signed-off-by: Marcel van Lohuizen <[email protected]>
Down the line, FormatString should replace Format with new semantics. It is added now as FormatString to aid in the transition. Closes #1508 Change-Id: I1d80aab593a7e8b18dd500d73aef12fb9e5bfa4b Signed-off-by: Marcel van Lohuizen <[email protected]>
Down the line, FormatString should replace Format with new semantics. It is added now as FormatString to aid in the transition. Closes #1508 Change-Id: I1d80aab593a7e8b18dd500d73aef12fb9e5bfa4b Signed-off-by: Marcel van Lohuizen <[email protected]>
Down the line, FormatString should replace Format with new semantics. It is added now as FormatString to aid in the transition. Issue #1508 Change-Id: I1d80aab593a7e8b18dd500d73aef12fb9e5bfa4b Signed-off-by: Marcel van Lohuizen <[email protected]>
Down the line, FormatString should replace Format with new semantics. It is added now as FormatString to aid in the transition. Issue #1508 Change-Id: I1d80aab593a7e8b18dd500d73aef12fb9e5bfa4b Signed-off-by: Marcel van Lohuizen <[email protected]>
I also think it would be good if there was some clearer way to directly see that, and how a function can be used as a validator. I think it is so that if the function returns bool (+ perhaps an error), or *Bottom, then you can use it as a validator by omitting the first argument in the CUE invocation. But this is not really that intuitive. When used correctly these validators look really clear and nice, but when looking at the package reference doc, at least for me it isn't until you see an example. |
Yes, indeed, this is sorely lacking documentation. This is certainly on the todo list. |
My plan was to document this as part of a more broader function refinement that is alluded to in #943 |
Down the line, FormatString should replace Format with new semantics. It is added now as FormatString to aid in the transition. Issue #1508 Change-Id: I1d80aab593a7e8b18dd500d73aef12fb9e5bfa4b Signed-off-by: Marcel van Lohuizen <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/533448 Unity-Result: CUEcueckoo <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
The 0.4.3 part of this bug is fixed, moving to 0.5.x |
The v0.5.x milestone is now closed because we have moved onto focus on v0.6.0. Hence moving this to v0.6.x because this didn't get done in the stretch goal that is v0.5.x. |
I see no effective method for manipulating dates in CUE.
time.Parse
helps ingest strings with time values, but it also returns a string, which needs parsing to be useful.time.Format
is even less useful: it can be used to create a value representing a set of all strings matching the specified layout.Notice that Parse and Format take arguments in different orders.
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest release?
Yes
What did you see?
What did you expect to see?
The text was updated successfully, but these errors were encountered: