From 9e71c66e2d5149bfb8c0daedf035414a70f9d2f4 Mon Sep 17 00:00:00 2001 From: Suyash Kumar Date: Wed, 10 Jul 2024 19:55:15 -0700 Subject: [PATCH] Add support for now() FHIR Path version of Now(). This addresses part of https://github.com/google/cql/issues/39. PiperOrigin-RevId: 651237467 --- parser/operators.go | 11 +++++++++++ parser/operators_test.go | 10 ++++++++++ tests/enginetests/operator_datetime_test.go | 12 ++++++++++++ 3 files changed, 33 insertions(+) diff --git a/parser/operators.go b/parser/operators.go index d61236f..02e45fe 100644 --- a/parser/operators.go +++ b/parser/operators.go @@ -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{{}}, diff --git a/parser/operators_test.go b/parser/operators_test.go index 8d3525f..11daf1a 100644 --- a/parser/operators_test.go +++ b/parser/operators_test.go @@ -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()", diff --git a/tests/enginetests/operator_datetime_test.go b/tests/enginetests/operator_datetime_test.go index 4568a5f..9470413 100644 --- a/tests/enginetests/operator_datetime_test.go +++ b/tests/enginetests/operator_datetime_test.go @@ -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()",