diff --git a/docs/references/functions.md b/docs/references/functions.md index fade7160..eeaf65b4 100644 --- a/docs/references/functions.md +++ b/docs/references/functions.md @@ -11,23 +11,23 @@ Available through the _ExpressionConfiguration.StandardFunctionsDictionary_ cons ### Basic Functions -| Name | Description | -|--------------------------------------------|-------------------------------------------------------------------------------------------------------------------------| -| ABS(value) | Absolute (non-negative) value | -| CEILING(value) | Rounds the given value an integer using the rounding mode CEILING | -| COALESCE(value, ...) | Returns the first non-null parameter, or NULL if all parameters are null | -| FACT(base) | Calculates the factorial of a base value | -| FLOOR(value) | Rounds the given value an integer using the rounding mode FLOOR | -| IF(condition, resultIfTrue, resultIfFalse) | Conditional evaluation function. If _condition_ is true, the _resultIfTrue_ is returned, else the _resultIfFalse_ value | -| LOG(value) | The natural logarithm (base e) of a value | -| LOG10(value) | The base 10 logarithm of a value | -| MAX(value, ...) | Returns the maximum value of all parameters. If a parameter is of type _ARRAY_, the maximum of all elements is used. | -| MIN(value, ...) | Returns the minimum value of all parameters. If a parameter is of type _ARRAY_, the minimum of all elements is used. | -| NOT(value) | Boolean negation, implemented as a function (for compatibility) | -| RANDOM() | Produces a random value between 0 and 1 | -| ROUND(value, scale) | Rounds the given value to the specified scale, using the current rounding mode | -| SQRT(value) | Square root function | -| SUM(value, ...) | Returns the sum of all parameters. If a parameter is of type _ARRAY_, the sum of all elements is calculated. | +| Name | Description | +|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------------| +| ABS(value) | Absolute (non-negative) value | +| CEILING(value) | Rounds the given value an integer using the rounding mode CEILING | +| COALESCE(value, ...) | Returns the first non-null parameter, or NULL if all parameters are null | +| FACT(base) | Calculates the factorial of a base value | +| FLOOR(value) | Rounds the given value an integer using the rounding mode FLOOR | +| IF(condition, resultIfTrue, resultIfFalse) | Conditional evaluation function. If _condition_ is true, the _resultIfTrue_ is returned, else the _resultIfFalse_ value | +| LOG(value) | The natural logarithm (base e) of a value | +| LOG10(value) | The base 10 logarithm of a value | +| MAX(value, ...) | Returns the maximum value of all parameters. If a parameter is of type _ARRAY_, the maximum of all elements is calculated. | +| MIN(value, ...) | Returns the minimum value of all parameters. If a parameter is of type _ARRAY_, the minimum of all elements is calculated. | +| NOT(value) | Boolean negation, implemented as a function (for compatibility) | +| RANDOM() | Produces a random value between 0 and 1 | +| ROUND(value, scale) | Rounds the given value to the specified scale, using the current rounding mode | +| SQRT(value) | Square root function | +| SUM(value, ...) | Returns the sum of all parameters. If a parameter is of type _ARRAY_, the sum of all elements is calculated. | ### String Functions @@ -82,7 +82,7 @@ Available through the _ExpressionConfiguration.StandardFunctionsDictionary_ cons | Name | Description | |--------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| DT_DATE_NEW(year, month, day [,hour, minute, second, millis, nanos] [,zoneId]) | Returns a new DATE_TIME value with the given parameters. Any optional time zone (string) can be specified, e.g. "Europe/Berlin", or "GMT+02:00". If no zone id is specified, the configured zone id is used. | +| DT_DATE_NEW(year, month, day [,hour, minute, second, millis, nanos] [,zoneId]) | Returns a new DATE_TIME value with the given parameters. An optional time zone (string) can be specified, e.g. "Europe/Berlin", or "GMT+02:00". If no zone id is specified, the configured zone id is used. | | DT_DATE_NEW(millis) | Returns a new DATE_TIME from the epoch of 1970-01-01T00:00:00Z in milliseconds. | | DT_DATE_PARSE(value [,zoneId] [,format, ...]) | Converts the given string value to a date time value by using the optional time zone and formats. All formats are used until the first matching format. Without a format, the configured formats are used. Time zone can be NULL, the the configured time zone is used. | | DT_DATE_FORMAT(value, [,format] [,zoneId]) | Formats the given date-time to a string using the given optional format and time zone. Without a format, the first configured format is used. The zone id defaults to the configured zone id. | @@ -91,5 +91,5 @@ Available through the _ExpressionConfiguration.StandardFunctionsDictionary_ cons | DT_DURATION_PARSE(value) | Converts the given ISO-8601 duration string representation to a duration value. E.g. "P2DT3H4M" parses 2 days, 3 hours and 4 minutes. | | DT_DURATION_FROM_MILLIS(millis) | Returns a new DURATION value with the given milliseconds. | | DT_DURATION_TO_MILLIS(value) | Converts the given duration to a milliseconds value. | -| DT_DATE_NOW() | Produces a new DATE_TIME that represents the current date and time. | -| DT_DATE_TODAY([zoneId]) | Produces a new DATE_TIME that represents the current date, at midnight (00:00). An optional time zone (string) can be specified, e.g. "America/Sao_Paulo", or "GMT-03:00". If no zone id is specified, the configured zone id is used. | +| DT_NOW() | Produces a new DATE_TIME that represents the current moment in time. | +| DT_TODAY([zoneId]) | Produces a new DATE_TIME that represents the current date, at midnight (00:00). An optional time zone (string) can be specified, e.g. "America/Sao_Paulo", or "GMT-03:00". If no zone id is specified, the configured zone id is used. | diff --git a/src/main/java/com/ezylang/evalex/functions/FunctionIfc.java b/src/main/java/com/ezylang/evalex/functions/FunctionIfc.java index ee31efc9..d8e57cb8 100644 --- a/src/main/java/com/ezylang/evalex/functions/FunctionIfc.java +++ b/src/main/java/com/ezylang/evalex/functions/FunctionIfc.java @@ -82,7 +82,7 @@ default boolean isParameterLazy(int parameterIndex) { /** * Returns the count of non-var-arg parameters defined by this function. If the function has - * var-args, the the result is the count of parameter definitions - 1. + * var-args, the result is the count of parameter definitions - 1. * * @return the count of non-var-arg parameters defined by this function. */ diff --git a/src/main/java/com/ezylang/evalex/functions/basic/MaxFunction.java b/src/main/java/com/ezylang/evalex/functions/basic/MaxFunction.java index 4c9cff6f..031e2e57 100644 --- a/src/main/java/com/ezylang/evalex/functions/basic/MaxFunction.java +++ b/src/main/java/com/ezylang/evalex/functions/basic/MaxFunction.java @@ -22,6 +22,7 @@ import java.math.BigDecimal; /** Returns the maximum value of all parameters. */ +@FunctionParameter(name = "firstValue") @FunctionParameter(name = "value", isVarArg = true) public class MaxFunction extends AbstractMinMaxFunction { @Override diff --git a/src/main/java/com/ezylang/evalex/functions/basic/MinFunction.java b/src/main/java/com/ezylang/evalex/functions/basic/MinFunction.java index 1059ba6c..1a048fa1 100644 --- a/src/main/java/com/ezylang/evalex/functions/basic/MinFunction.java +++ b/src/main/java/com/ezylang/evalex/functions/basic/MinFunction.java @@ -22,6 +22,7 @@ import java.math.BigDecimal; /** Returns the minimum value of all parameters. */ +@FunctionParameter(name = "firstValue") @FunctionParameter(name = "value", isVarArg = true) public class MinFunction extends AbstractMinMaxFunction { @Override diff --git a/src/main/java/com/ezylang/evalex/functions/datetime/DateTimeNowFunction.java b/src/main/java/com/ezylang/evalex/functions/datetime/DateTimeNowFunction.java index 22392e0e..a99580d2 100644 --- a/src/main/java/com/ezylang/evalex/functions/datetime/DateTimeNowFunction.java +++ b/src/main/java/com/ezylang/evalex/functions/datetime/DateTimeNowFunction.java @@ -30,7 +30,7 @@ * *
* - * {@code DT_DATE_NOW() - startDateTime} + * {@code DT_NOW() - startDateTime} * *
* diff --git a/src/main/java/com/ezylang/evalex/functions/datetime/DateTimeTodayFunction.java b/src/main/java/com/ezylang/evalex/functions/datetime/DateTimeTodayFunction.java index 97c4fb02..708113a7 100644 --- a/src/main/java/com/ezylang/evalex/functions/datetime/DateTimeTodayFunction.java +++ b/src/main/java/com/ezylang/evalex/functions/datetime/DateTimeTodayFunction.java @@ -34,7 +34,7 @@ * *
* - * {@code IF(expiryDate > DT_DATE_TODAY(), "expired", "valid")} + * {@code IF(expiryDate > DT_TODAY(), "expired", "valid")} * *
* diff --git a/src/test/java/com/ezylang/evalex/functions/basic/BasicFunctionsTest.java b/src/test/java/com/ezylang/evalex/functions/basic/BasicFunctionsTest.java index f9ae420a..f3a7ddc8 100644 --- a/src/test/java/com/ezylang/evalex/functions/basic/BasicFunctionsTest.java +++ b/src/test/java/com/ezylang/evalex/functions/basic/BasicFunctionsTest.java @@ -79,6 +79,13 @@ void testMax(String expression, String expectedResult) assertExpressionHasExpectedResult(expression, expectedResult); } + @Test + void testMaxThrowsException() { + assertThatThrownBy(() -> new Expression("MAX()").evaluate()) + .isInstanceOf(ParseException.class) + .hasMessage("Not enough parameters for function"); + } + @ParameterizedTest @CsvSource( delimiter = ':', @@ -93,6 +100,13 @@ void testMin(String expression, String expectedResult) assertExpressionHasExpectedResult(expression, expectedResult); } + @Test + void testMinThrowsException() { + assertThatThrownBy(() -> new Expression("MIN()").evaluate()) + .isInstanceOf(ParseException.class) + .hasMessage("Not enough parameters for function"); + } + @ParameterizedTest @CsvSource( delimiter = ':',