Skip to content

Commit e98544a

Browse files
committed
TEDEFO-4994 Add tests for current-date and current-time functions
1 parent 132b679 commit e98544a

4 files changed

Lines changed: 71 additions & 0 deletions

File tree

src/main/java/eu/europa/ted/efx/interfaces/ScriptGenerator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,13 @@ public DateExpression composeSubtraction(final DateExpression date,
926926
*/
927927
public TimeExpression composeToTimeConversion(StringExpression pop);
928928

929+
/**
930+
* Returns the current time as a time expression in the target language.
931+
*
932+
* @return A time expression representing the current time.
933+
*/
934+
public TimeExpression getCurrentTime();
935+
929936
// #endregion Time Functions ------------------------------------------------
930937

931938
// #region Duration Functions -----------------------------------------------

src/main/java/eu/europa/ted/efx/sdk2/EfxExpressionTranslatorV2.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,6 +3197,11 @@ public void exitDateMinusDurationFunction(DateMinusDurationFunctionContext ctx)
31973197
this.exitDateDurationSubtraction();
31983198
}
31993199

3200+
@Override
3201+
public void exitCurrentDateFunction(CurrentDateFunctionContext ctx) {
3202+
this.stack.push(this.script.getCurrentDate());
3203+
}
3204+
32003205
@Override
32013206
public void exitYearFromDateFunction(YearFromDateFunctionContext ctx) {
32023207
this.stack.push(this.script.composeYearFunction(this.stack.pop(DateExpression.class)));
@@ -3221,6 +3226,11 @@ public void exitTimeFromStringFunction(TimeFromStringFunctionContext ctx) {
32213226
this.stack.push(this.script.composeToTimeConversion(this.stack.pop(StringExpression.class)));
32223227
}
32233228

3229+
@Override
3230+
public void exitCurrentTimeFunction(CurrentTimeFunctionContext ctx) {
3231+
this.stack.push(this.script.getCurrentTime());
3232+
}
3233+
32243234
@Override
32253235
public void exitHoursFromTimeFunction(HoursFromTimeFunctionContext ctx) {
32263236
this.stack.push(this.script.composeHoursFunction(this.stack.pop(TimeExpression.class)));

src/main/java/eu/europa/ted/efx/xpath/XPathScriptGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@ public TimeExpression composeToTimeConversion(StringExpression time) {
821821
return new TimeExpression("xs:time(" + time.getScript() + ")");
822822
}
823823

824+
@Override
825+
public TimeExpression getCurrentTime() {
826+
return new TimeExpression("current-time()");
827+
}
828+
824829
//#endregion Time functions -------------------------------------------------
825830

826831
//#region Duration functions ------------------------------------------------

src/test/java/eu/europa/ted/efx/sdk2/EfxExpressionTranslatorV2Test.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,37 @@ void testDateFromStringFunction() {
24762476
"ND-Root", "date(BT-00-Text)");
24772477
}
24782478

2479+
@Test
2480+
void testCurrentDateFunction() {
2481+
testExpressionTranslationWithContext("current-date()", "ND-Root", "current-date()");
2482+
}
2483+
2484+
@Test
2485+
void testCurrentDateComparedToField() {
2486+
testExpressionTranslationWithContext(
2487+
"current-date() > PathNode/StartDateField/xs:date(text())",
2488+
"ND-Root", "current-date() > BT-00-StartDate");
2489+
}
2490+
2491+
@Test
2492+
void testCurrentDatePlusDuration() {
2493+
testExpressionTranslationWithContext(
2494+
"(current-date() + xs:dayTimeDuration('P30D'))",
2495+
"ND-Root", "add-duration(current-date(), P30D)");
2496+
}
2497+
2498+
@Test
2499+
void testYearFromCurrentDate() {
2500+
testExpressionTranslationWithContext("year-from-date(current-date())",
2501+
"ND-Root", "year(current-date())");
2502+
}
2503+
2504+
@Test
2505+
void testMonthFromCurrentDate() {
2506+
testExpressionTranslationWithContext("month-from-date(current-date())",
2507+
"ND-Root", "month(current-date())");
2508+
}
2509+
24792510
// #endregion: Date functions
24802511

24812512
// #region: Time functions --------------------------------------------------
@@ -2486,6 +2517,24 @@ void testTimeFromStringFunction() {
24862517
"ND-Root", "time(BT-00-Text)");
24872518
}
24882519

2520+
@Test
2521+
void testCurrentTimeFunction() {
2522+
testExpressionTranslationWithContext("current-time()", "ND-Root", "current-time()");
2523+
}
2524+
2525+
@Test
2526+
void testCurrentTimeComparedToField() {
2527+
testExpressionTranslationWithContext(
2528+
"current-time() > PathNode/StartTimeField/xs:time(text())",
2529+
"ND-Root", "current-time() > BT-00-StartTime");
2530+
}
2531+
2532+
@Test
2533+
void testHoursFromCurrentTime() {
2534+
testExpressionTranslationWithContext("hours-from-time(current-time())",
2535+
"ND-Root", "hours(current-time())");
2536+
}
2537+
24892538
// #endregion: Time functions
24902539

24912540
// #region Duration functions

0 commit comments

Comments
 (0)