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

davsclaus pushed a commit to branch fix/CAMEL-24375
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b2b04eb03e609e8c9aa24da76ebc85d950db5377
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Aug 9 15:37:38 2026 +0200

    CAMEL-24375: parseDuration should handle plain millis value without relying 
on type converter
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../CamelContextHelperParseDurationTest.java       | 63 ++++++++++++++++++++++
 .../apache/camel/support/CamelContextHelper.java   | 14 ++++-
 2 files changed, 76 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/support/CamelContextHelperParseDurationTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/support/CamelContextHelperParseDurationTest.java
new file mode 100644
index 000000000000..eb75b198cf89
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/support/CamelContextHelperParseDurationTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.support;
+
+import java.time.Duration;
+
+import org.apache.camel.ContextTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class CamelContextHelperParseDurationTest extends ContextTestSupport {
+
+    @Test
+    void testParseDurationMillis() {
+        Duration d = CamelContextHelper.parseDuration(context, "20000");
+        assertThat(d).isEqualTo(Duration.ofMillis(20000));
+    }
+
+    @Test
+    void testParseDurationHumanReadable() {
+        Duration d = CamelContextHelper.parseDuration(context, "20s");
+        assertThat(d).isEqualTo(Duration.ofSeconds(20));
+    }
+
+    @Test
+    void testParseDurationHumanReadableMinutes() {
+        Duration d = CamelContextHelper.parseDuration(context, "1m30s");
+        assertThat(d).isEqualTo(Duration.ofSeconds(90));
+    }
+
+    @Test
+    void testParseDurationISO8601() {
+        Duration d = CamelContextHelper.parseDuration(context, "PT20S");
+        assertThat(d).isEqualTo(Duration.ofSeconds(20));
+    }
+
+    @Test
+    void testParseDurationISO8601Lowercase() {
+        Duration d = CamelContextHelper.parseDuration(context, "pt20s");
+        assertThat(d).isEqualTo(Duration.ofSeconds(20));
+    }
+
+    @Test
+    void testParseDurationNull() {
+        Duration d = CamelContextHelper.parseDuration(context, null);
+        assertThat(d).isNull();
+    }
+}
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
index 7e8b29c80caa..2d28ecef21c1 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
@@ -461,7 +461,19 @@ public final class CamelContextHelper {
      * @throws IllegalStateException is thrown if illegal argument or type 
conversion not possible
      */
     public static Duration parseDuration(CamelContext camelContext, String 
text) {
-        return parse(camelContext, Duration.class, text);
+        if (text == null) {
+            return null;
+        }
+        // ensure we support property placeholders
+        String s = camelContext.resolvePropertyPlaceholders(text);
+        if (s == null) {
+            return null;
+        }
+        if (s.startsWith("P") || s.startsWith("-P") || s.startsWith("p") || 
s.startsWith("-p")) {
+            return Duration.parse(s);
+        } else {
+            return Duration.ofMillis(TimeUtils.toMilliSeconds(s));
+        }
     }
 
     /**

Reply via email to