Skip to content

Commit

Permalink
Add support for now() FHIR Path version of Now().
Browse files Browse the repository at this point in the history
This addresses part of #39.

PiperOrigin-RevId: 651178839
  • Loading branch information
suyashkumar authored and copybara-github committed Jul 11, 2024
1 parent 863e6ce commit 3c34da7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions parser/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,17 @@ func (p *Parser) loadSystemOperators() error {
}
},
},
{
name: "now",
operands: [][]types.IType{{}},
model: func() model.IExpression {
return &model.Now{
NaryExpression: &model.NaryExpression{
Expression: model.ResultType(types.DateTime),
},
}
},
},
{
name: "TimeOfDay",
operands: [][]types.IType{{}},
Expand Down
10 changes: 10 additions & 0 deletions parser/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,16 @@ func TestBuiltInFunctions(t *testing.T) {
},
},
},
{
name: "now()",
cql: "now()",
want: &model.Now{
NaryExpression: &model.NaryExpression{
Operands: []model.IExpression{},
Expression: model.ResultType(types.DateTime),
},
},
},
{
name: "TimeOfDay()",
cql: "TimeOfDay()",
Expand Down
12 changes: 12 additions & 0 deletions tests/enginetests/operator_datetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,18 @@ func TestEvaluationTimestamp(t *testing.T) {
},
wantResult: newOrFatal(t, result.DateTime{Date: time.Date(2024, time.January, 1, 0, 0, 0, 1, time.UTC), Precision: model.MILLISECOND}),
},
{
name: "now() returns passed evaluation timestamp",
cql: "define TESTRESULT: now()",
evaluationTimestamp: time.Date(2024, time.January, 1, 0, 0, 0, 1, time.UTC),
wantModel: &model.Now{
NaryExpression: &model.NaryExpression{
Operands: []model.IExpression{},
Expression: model.ResultType(types.DateTime),
},
},
wantResult: newOrFatal(t, result.DateTime{Date: time.Date(2024, time.January, 1, 0, 0, 0, 1, time.UTC), Precision: model.MILLISECOND}),
},
{
name: "Time returns passed evaluation timestamp time components",
cql: "define TESTRESULT: TimeOfDay()",
Expand Down

0 comments on commit 3c34da7

Please sign in to comment.