This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new aa0df96ceb48 camel-core - simple languge add millis to date command
aa0df96ceb48 is described below

commit aa0df96ceb48cd6694948394ed5cefe87a95fef8
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Jan 24 18:54:40 2026 +0100

    camel-core - simple languge add millis to date command
---
 .../org/apache/camel/catalog/languages/simple.json      |  2 +-
 .../camel/language/csimple/joor/OriginalSimpleTest.java | 17 ++++++++++++++++-
 .../org/apache/camel/language/simple/simple.json        |  2 +-
 .../docs/modules/languages/pages/simple-language.adoc   |  5 ++++-
 .../apache/camel/language/csimple/CSimpleHelper.java    |  2 ++
 .../apache/camel/language/simple/SimpleConstants.java   |  2 +-
 .../camel/language/simple/SimpleExpressionBuilder.java  |  9 ++++++---
 .../language/simple/ast/SimpleFunctionExpression.java   |  3 +++
 .../org/apache/camel/language/simple/SimpleTest.java    | 13 ++++++++++++-
 9 files changed, 46 insertions(+), 9 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/simple.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/simple.json
index 43afc5b8cc86..b2dc86943096 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/simple.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/languages/simple.json
@@ -48,7 +48,7 @@
     "collate(num)": { "index": 21, "kind": "function", "displayName": "Group 
Message Body into Sub Lists", "group": "function", "label": "function", 
"required": false, "javaType": "java.util.Iterator", "prefix": "${", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The collate function iterates the message body and 
groups the data into sub lists of specified size. This can be used with the 
Splitter EIP to split a message body and group\/ba [...]
     "concat(exp,exp,separator)": { "index": 22, "kind": "function", 
"displayName": "Concat", "group": "function", "label": "function", "required": 
false, "javaType": "String", "prefix": "${", "deprecated": false, 
"deprecationNote": "", "autowired": false, "secret": false, "description": 
"Performs a string concat using two expressions (message body as default) with 
optional separator", "ognl": false, "suffix": "}" },
     "convertTo(exp,type)": { "index": 23, "kind": "function", "displayName": 
"Convert To", "group": "function", "label": "function", "required": false, 
"javaType": "", "prefix": "${", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "Converts the message body 
(or expression) to the specified type.", "ognl": true, "suffix": "}" },
-    "date(command)": { "index": 24, "kind": "function", "displayName": "Parse 
Date", "group": "function", "label": "function", "required": false, "javaType": 
"java.util.Date", "prefix": "${", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "Evaluates to a 
java.util.Date object. Supported commands are: `now` for current timestamp, 
`exchangeCreated` for the timestamp when the current exchange was created, 
`header.xxx` to use the Long\/Date ob [...]
+    "date(command)": { "index": 24, "kind": "function", "displayName": "Parse 
Date", "group": "function", "label": "function", "required": false, "javaType": 
"java.util.Date", "prefix": "${", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "Evaluates to a 
java.util.Date object. Supported commands are: `now` for current timestamp, 
`millis` for current timestamp in millis (unix epoch), `exchangeCreated` for 
the timestamp when the current exch [...]
     "date-with-timezone(command:timezone:pattern)": { "index": 25, "kind": 
"function", "displayName": "Date Formatter", "group": "function", "label": 
"function", "required": false, "javaType": "String", "prefix": "${", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "Formats the date to a String using the given date 
pattern, and with support for timezone. Supported commands are: `now` for 
current timestamp, `exchangeCreated` for the timesta [...]
     "distinct(val...)": { "index": 26, "kind": "function", "displayName": 
"Distinct Values", "group": "function", "label": "function", "required": false, 
"javaType": "Set", "prefix": "${", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "Returns a set of all the 
values with duplicates removed", "ognl": false, "suffix": "}" },
     "empty(type)": { "index": 27, "kind": "function", "displayName": "Create 
Empty Object", "group": "function", "label": "function", "required": false, 
"javaType": "Object", "prefix": "${", "deprecated": true, "deprecationNote": 
"", "autowired": false, "secret": false, "description": "Creates a new empty 
object (decided by type). Use `string` to create an empty String. Use `list` to 
create an empty `java.util.ArrayList`. Use `map` to create an empty 
`java.util.LinkedHashMap`. Use `set`  [...]
diff --git 
a/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/OriginalSimpleTest.java
 
b/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/OriginalSimpleTest.java
index 97e88e3f650c..192be8370c8c 100644
--- 
a/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/OriginalSimpleTest.java
+++ 
b/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/OriginalSimpleTest.java
@@ -721,8 +721,23 @@ public class OriginalSimpleTest extends 
LanguageTestSupport {
 
     @Test
     public void testDateNow() {
-        Object out = evaluateExpression("${date:now:hh:mm:ss a}", null);
+        Object out = evaluateExpression("${date:now}", null);
         assertNotNull(out);
+        assertIsInstanceOf(Date.class, out);
+
+        out = evaluateExpression("${date:now:hh:mm:ss a}", null);
+        assertNotNull(out);
+        out = evaluateExpression("${date:now:hh:mm:ss}", null);
+        assertNotNull(out);
+        out = evaluateExpression("${date:now-2h:hh:mm:ss}", null);
+        assertNotNull(out);
+    }
+
+    @Test
+    public void testDateMillis() {
+        Object out = evaluateExpression("${date:millis}", null);
+        assertNotNull(out);
+        assertIsInstanceOf(Long.class, out);
     }
 
     @Test
diff --git 
a/core/camel-core-languages/src/generated/resources/META-INF/org/apache/camel/language/simple/simple.json
 
b/core/camel-core-languages/src/generated/resources/META-INF/org/apache/camel/language/simple/simple.json
index 43afc5b8cc86..b2dc86943096 100644
--- 
a/core/camel-core-languages/src/generated/resources/META-INF/org/apache/camel/language/simple/simple.json
+++ 
b/core/camel-core-languages/src/generated/resources/META-INF/org/apache/camel/language/simple/simple.json
@@ -48,7 +48,7 @@
     "collate(num)": { "index": 21, "kind": "function", "displayName": "Group 
Message Body into Sub Lists", "group": "function", "label": "function", 
"required": false, "javaType": "java.util.Iterator", "prefix": "${", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The collate function iterates the message body and 
groups the data into sub lists of specified size. This can be used with the 
Splitter EIP to split a message body and group\/ba [...]
     "concat(exp,exp,separator)": { "index": 22, "kind": "function", 
"displayName": "Concat", "group": "function", "label": "function", "required": 
false, "javaType": "String", "prefix": "${", "deprecated": false, 
"deprecationNote": "", "autowired": false, "secret": false, "description": 
"Performs a string concat using two expressions (message body as default) with 
optional separator", "ognl": false, "suffix": "}" },
     "convertTo(exp,type)": { "index": 23, "kind": "function", "displayName": 
"Convert To", "group": "function", "label": "function", "required": false, 
"javaType": "", "prefix": "${", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "Converts the message body 
(or expression) to the specified type.", "ognl": true, "suffix": "}" },
-    "date(command)": { "index": 24, "kind": "function", "displayName": "Parse 
Date", "group": "function", "label": "function", "required": false, "javaType": 
"java.util.Date", "prefix": "${", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "Evaluates to a 
java.util.Date object. Supported commands are: `now` for current timestamp, 
`exchangeCreated` for the timestamp when the current exchange was created, 
`header.xxx` to use the Long\/Date ob [...]
+    "date(command)": { "index": 24, "kind": "function", "displayName": "Parse 
Date", "group": "function", "label": "function", "required": false, "javaType": 
"java.util.Date", "prefix": "${", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "Evaluates to a 
java.util.Date object. Supported commands are: `now` for current timestamp, 
`millis` for current timestamp in millis (unix epoch), `exchangeCreated` for 
the timestamp when the current exch [...]
     "date-with-timezone(command:timezone:pattern)": { "index": 25, "kind": 
"function", "displayName": "Date Formatter", "group": "function", "label": 
"function", "required": false, "javaType": "String", "prefix": "${", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "Formats the date to a String using the given date 
pattern, and with support for timezone. Supported commands are: `now` for 
current timestamp, `exchangeCreated` for the timesta [...]
     "distinct(val...)": { "index": 26, "kind": "function", "displayName": 
"Distinct Values", "group": "function", "label": "function", "required": false, 
"javaType": "Set", "prefix": "${", "deprecated": false, "deprecationNote": "", 
"autowired": false, "secret": false, "description": "Returns a set of all the 
values with duplicates removed", "ognl": false, "suffix": "}" },
     "empty(type)": { "index": 27, "kind": "function", "displayName": "Create 
Empty Object", "group": "function", "label": "function", "required": false, 
"javaType": "Object", "prefix": "${", "deprecated": true, "deprecationNote": 
"", "autowired": false, "secret": false, "description": "Creates a new empty 
object (decided by type). Use `string` to create an empty String. Use `list` to 
create an empty `java.util.ArrayList`. Use `map` to create an empty 
`java.util.LinkedHashMap`. Use `set`  [...]
diff --git 
a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
 
b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
index 23889d70e326..fb25c08d3519 100644
--- 
a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
+++ 
b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
@@ -324,6 +324,7 @@ And the `not` function is function to inverse the boolean 
value.
 [width="100%",cols="10%,10%,80%",options="header",]
 |====
 |Function |Response Type |Description
+|`date:millis` | `long` | Returns the current timestamp as millis in unix 
epoch.
 |`date:command` | `Date` | Evaluates to a `java.util.Date` object. Supported 
commands are: `now` for current timestamp, `exchangeCreated` for the timestamp 
when the current exchange was created, `header.xxx` to use the `Long/Date` 
object in the header with the key xxx. `variable.xxx` to use the `Long/Date` in 
the variable with the key xxx. `exchangeProperty.xxx` to use the `Long/Date` 
object in the exchange property with the key xxx. `file` for the last modified 
timestamp of the file (on [...]
 |`date:command:pattern` | `String` | Date formatting using 
`java.text.SimpleDateFormat` patterns. See `data:command` function for 
additional documentation on the commands.
 |`date-with-timezone:command:timezone:pattern` | `String` | Date formatting 
using `java.text.SimpleDateFormat` timezones and patterns. See `data:command` 
function for additional documentation on the commands.
@@ -332,6 +333,8 @@ And the `not` function is function to inverse the boolean 
value.
 The date functions is used for parsing and formatting with date and times.
 
 For example to get the current time use `${date:now}` which is returned as a 
`java.util.Date` object.
+And you can use `${date:millis}` to get unix epoch timestamp as a long value.
+
 If you want to format this to a String value, you can use the pattern command, 
such as `${date:now:hh:mm:ss}`.
 And to get the time 8 hours in the future `${date:now+8h:hh:mm:ss}`.
 
@@ -386,7 +389,7 @@ This will get the `Date` object from the header with key 
birthday, and format th
 |`capitalize()` | `String` | Capitalizes the message body as a String value 
(upper case every words)
 |`capitalize(exp)` | `String` | Capitalizes the expression as a String value 
(upper case every words)
 |`concat(exp,exp,separator)` | `String` | Performs a string concat using two 
expressions (message body as default) with optional separator (uses comma by 
default).
-|`join(separator,prefix,exp` | `String` | The join function iterates the 
message body (by default) and joins the data into a `String`. The separator is 
by default a comma. The prefix is optional. The join uses the message body as 
source by default. It is possible to refer to another source (simple language) 
such as a header via the exp parameter. For example 
`join('&','id=','$\{header.ids}')`
+|`join(separator,prefix,exp)` | `String` | The join function iterates the 
message body (by default) and joins the data into a `String`. The separator is 
by default a comma. The prefix is optional. The join uses the message body as 
source by default. It is possible to refer to another source (simple language) 
such as a header via the exp parameter. For example 
`join('&','id=','$\{header.ids}')`
 |`lowercase()` | `String` | Lowercases the message body
 |`lowercase(exp)` | `String` | Lowercases the expression
 |`normalizeWhitespace()` | `String` | Normalizes the whitespace in the message 
body by cleaning up excess whitespaces.
diff --git 
a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
 
b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
index 83e22d5695de..902de3f38451 100644
--- 
a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
+++ 
b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
@@ -406,6 +406,8 @@ public final class CSimpleHelper {
             date = LanguageHelper.dateFromExchangeCreated(exchange);
         } else if (command.startsWith("header.")) {
             date = LanguageHelper.dateFromHeader(exchange, command, (e, o) -> 
failDueToMissingObjectAtCommand(command));
+        } else if (command.startsWith("variable.")) {
+            date = LanguageHelper.dateFromVariable(exchange, command, (e, o) 
-> failDueToMissingObjectAtCommand(command));
         } else if (command.startsWith("exchangeProperty.")) {
             date = LanguageHelper.dateFromExchangeProperty(exchange, command,
                     (e, o) -> failDueToMissingObjectAtCommand(command));
diff --git 
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleConstants.java
 
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleConstants.java
index c5d494fa31c9..0e12b00e0ff3 100644
--- 
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleConstants.java
+++ 
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleConstants.java
@@ -107,7 +107,7 @@ public final class SimpleConstants {
               displayName = "Convert To")
     public static final String CONVERT_TO = "convertTo(exp,type)";
 
-    @Metadata(description = "Evaluates to a java.util.Date object. Supported 
commands are: `now` for current timestamp, `exchangeCreated` for the timestamp 
when the current exchange was created, `header.xxx` to use the Long/Date object 
in the header with the key xxx. `variable.xxx` to use the Long/Date in the 
variable with the key xxx. `exchangeProperty.xxx` to use the Long/Date object 
in the exchange property with the key xxx. `file` for the last modified 
timestamp of the file (availabl [...]
+    @Metadata(description = "Evaluates to a java.util.Date object. Supported 
commands are: `now` for current timestamp, `millis` for current timestamp in 
millis (unix epoch), `exchangeCreated` for the timestamp when the current 
exchange was created, `header.xxx` to use the Long/Date object in the header 
with the key xxx. `variable.xxx` to use the Long/Date in the variable with the 
key xxx. `exchangeProperty.xxx` to use the Long/Date object in the exchange 
property with the key xxx. `file [...]
               label = "function", javaType = "java.util.Date", displayName = 
"Parse Date")
     public static final String DATE = "date(command)";
 
diff --git 
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java
 
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java
index eb82f20278f9..debbc4c9e813 100644
--- 
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java
+++ 
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java
@@ -2239,8 +2239,11 @@ public final class SimpleExpressionBuilder {
             @Override
             public Object evaluate(Exchange exchange) {
                 Date date = evalDate(exchange, command);
-
-                return LanguageHelper.applyDateOffsets(date, offsets, pattern, 
timezone);
+                Object answer = LanguageHelper.applyDateOffsets(date, offsets, 
pattern, timezone);
+                if ("millis".equals(command) && answer instanceof Date d) {
+                    answer = d.getTime();
+                }
+                return answer;
             }
 
             @Override
@@ -2258,7 +2261,7 @@ public final class SimpleExpressionBuilder {
 
     private static Date evalDate(Exchange exchange, String command) {
         Date date;
-        if ("now".equals(command)) {
+        if ("now".equals(command) || "millis".equals(command)) {
             date = new Date();
         } else if ("exchangeCreated".equals(command)) {
             date = LanguageHelper.dateFromExchangeCreated(exchange);
diff --git 
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
 
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
index 9baf15f9d28a..1ed912970233 100644
--- 
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
+++ 
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
@@ -1627,6 +1627,9 @@ public class SimpleFunctionExpression extends 
LiteralExpression {
             return createCodeFileExpression(remainder);
         }
 
+        if ("date:millis".equals(function)) {
+            return "System.currentTimeMillis()";
+        }
         // date: prefix
         remainder = ifStartsWithReturnRemainder("date:", function);
         if (remainder != null) {
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index cdf0bbd2a64f..fbb31a78266a 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -663,7 +663,11 @@ public class SimpleTest extends LanguageTestSupport {
 
     @Test
     public void testDateNow() {
-        Object out = evaluateExpression("${date:now:hh:mm:ss a}", null);
+        Object out = evaluateExpression("${date:now}", null);
+        assertNotNull(out);
+        assertIsInstanceOf(Date.class, out);
+
+        out = evaluateExpression("${date:now:hh:mm:ss a}", null);
         assertNotNull(out);
         out = evaluateExpression("${date:now:hh:mm:ss}", null);
         assertNotNull(out);
@@ -671,6 +675,13 @@ public class SimpleTest extends LanguageTestSupport {
         assertNotNull(out);
     }
 
+    @Test
+    public void testDateMillis() {
+        Object out = evaluateExpression("${date:millis}", null);
+        assertNotNull(out);
+        assertIsInstanceOf(Long.class, out);
+    }
+
     @Test
     public void testDateExchangeCreated() {
         Object out

Reply via email to