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

ast: Add AST builder methods for datetime-related types and operators #57

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

patjakdev
Copy link
Collaborator

Issue #, if available: None

Description of changes: Add missing AST builder methods for datetime and duration literals as well as their associated methods.

Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
Comment on lines +83 to +89
func Datetime(t time.Time) Node {
return Value(types.FromStdTime(t))
}

func Duration(d time.Duration) Node {
return Value(types.FromStdDuration(d))
}
Copy link
Collaborator Author

@patjakdev patjakdev Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if these could take their counterparts from the types library like the other builder functions, but alas they cannot because the types types don't have the same underlying structure as the stdlib types.

I looked into making types.Datetime a wrapper around time.Time so that we could support both types as an argument here, but you end up giving types.Datetime at least one of the same footguns that time.Time has: the == operator does not return true if two instances represent the same moment of time in two different locations. Instead, you need to use the .Equal() method to resolve that.

That ugliness was enough to convince me that we should keep the simpler representation that we have now.

@patjakdev patjakdev marked this pull request as ready for review November 8, 2024 19:16
@patjakdev patjakdev requested a review from apg November 8, 2024 19:16
@patjakdev patjakdev merged commit 1bf4c4e into cedar-policy:main Nov 8, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants