diff --git a/src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java b/src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java index 983a397..73d1ff9 100644 --- a/src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java +++ b/src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java @@ -26,6 +26,7 @@ import eu.europa.ted.efx.model.Context.FieldContext; import eu.europa.ted.efx.model.Context.NodeContext; import eu.europa.ted.efx.model.expressions.Expression; +import eu.europa.ted.efx.model.expressions.TypedExpression; import eu.europa.ted.efx.model.expressions.path.PathExpression; import eu.europa.ted.efx.model.expressions.path.StringPathExpression; import eu.europa.ted.efx.model.expressions.scalar.StringExpression; @@ -33,6 +34,7 @@ import eu.europa.ted.efx.model.templates.ContentBlock; import eu.europa.ted.efx.model.templates.ContentBlockStack; import eu.europa.ted.efx.model.templates.Markup; +import eu.europa.ted.efx.model.types.EfxDataType; import eu.europa.ted.efx.model.variables.Variable; import eu.europa.ted.efx.model.variables.VariableList; import eu.europa.ted.efx.sdk1.EfxParser.AssetIdContext; @@ -426,7 +428,20 @@ public void exitAssetId(AssetIdContext ctx) { */ @Override public void exitStandardExpressionBlock(StandardExpressionBlockContext ctx) { - this.stack.push(this.stack.pop(Expression.class)); + var expression = this.stack.pop(Expression.class); + + // This is a hack to make sure that the date and time expressions are rendered in the correct + // format. We had to do this because EFX 1 does not support the format-date() and format-time() + // functions. + if (TypedExpression.class.isAssignableFrom(expression.getClass())) { + if (EfxDataType.Date.class.isAssignableFrom(((TypedExpression) expression).getDataType())) { + expression = new StringExpression("format-date(" + expression.getScript() + ", '[D01]/[M01]/[Y0001]')"); + } else if (EfxDataType.Time.class.isAssignableFrom(((TypedExpression) expression).getDataType())) { + expression = new StringExpression("format-time(" + expression.getScript() + ", '[H01]:[m01] [Z]')"); + } + } + + this.stack.push(expression); } /*** diff --git a/src/test/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1Test.java b/src/test/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1Test.java index 7d3b3d9..f002a9c 100644 --- a/src/test/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1Test.java +++ b/src/test/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1Test.java @@ -343,4 +343,14 @@ void testEndOfLineComments() { "let block01() -> { label(concat('field', '|', 'name', '|', 'BT-00-Text'))text(' ')text('blah blah') }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} #{name|BT-00-Text} blah blah // comment blah blah")); } + + @Test + void testImplicitFormatting_Dates() { + assertEquals("let block01() -> { eval(format-date(PathNode/StartDateField/xs:date(text()), '[D01]/[M01]/[Y0001]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartDate}")); + } + + @Test + void testImplicitFormatting_Times() { + assertEquals("let block01() -> { eval(format-time(PathNode/StartTimeField/xs:time(text()), '[H01]:[m01] [Z]')) }\nfor-each(/*).call(block01())", translateTemplate("{ND-Root} ${BT-00-StartTime}")); + } }