Author: milamber
Date: Thu Jul 12 08:51:22 2018
New Revision: 1835709
URL: http://svn.apache.org/viewvc?rev=1835709&view=rev
Log:
Allow use epoch time as Date String value in function __dateTimeConvert
Bugzilla Id: 62533
Modified:
jmeter/trunk/src/functions/org/apache/jmeter/functions/DateTimeConvertFunction.java
jmeter/trunk/xdocs/changes.xml
jmeter/trunk/xdocs/usermanual/functions.xml
Modified:
jmeter/trunk/src/functions/org/apache/jmeter/functions/DateTimeConvertFunction.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/DateTimeConvertFunction.java?rev=1835709&r1=1835708&r2=1835709&view=diff
==============================================================================
---
jmeter/trunk/src/functions/org/apache/jmeter/functions/DateTimeConvertFunction.java
(original)
+++
jmeter/trunk/src/functions/org/apache/jmeter/functions/DateTimeConvertFunction.java
Thu Jul 12 08:51:22 2018
@@ -20,6 +20,7 @@ package org.apache.jmeter.functions;
import java.text.SimpleDateFormat;
import java.util.Collection;
+import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -67,9 +68,15 @@ public class DateTimeConvertFunction ext
String sourceDateFormat = values[1].execute();
String targetDateFormat = values[2].execute();
try {
- SimpleDateFormat sourceDateFormatter = new
SimpleDateFormat(sourceDateFormat);
SimpleDateFormat targetDateFormatter = new
SimpleDateFormat(targetDateFormat);
- String newDate =
targetDateFormatter.format(sourceDateFormatter.parse(dateString));
+ String newDate;
+ if (sourceDateFormat != null && sourceDateFormat.length() > 0) {
+ SimpleDateFormat sourceDateFormatter = new
SimpleDateFormat(sourceDateFormat);
+ newDate =
targetDateFormatter.format(sourceDateFormatter.parse(dateString));
+ } else {
+ // dateString will be an epoch time
+ newDate = targetDateFormatter.format(new
Date(Long.parseLong(dateString)));
+ }
addVariableValue(newDate, values, 3);
return newDate;
} catch (Exception e) {
Modified: jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1835709&r1=1835708&r2=1835709&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Thu Jul 12 08:51:22 2018
@@ -123,6 +123,7 @@ this behaviour, set <code>httpclient.res
<ul>
<li><bug>62178</bug>Add default value to <code>__V</code> function.
Contributed by orimarko at gmail.com</li>
<li><bug>62178</bug>Add function <code>__threadGroupName</code> function
to obtain ThreadGroup name. Mainly contributed by orimarko at gmail.com</li>
+ <li><bug>62533</bug>Allow use epoch time as Date String value in function
<code>__dateTimeConvert</code> </li>
</ul>
<h3>I18N</h3>
<ul>
Modified: jmeter/trunk/xdocs/usermanual/functions.xml
URL:
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/functions.xml?rev=1835709&r1=1835708&r2=1835709&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jmeter/trunk/xdocs/usermanual/functions.xml Thu Jul 12 08:51:22 2018
@@ -1643,15 +1643,18 @@ returns:
</description>
<properties>
<property name="Date String" required="Yes">
- The date string to convert from Source Date Format to Target Date
Format.
+ The date string to convert from Source Date Format to Target Date
Format. A date as a epoch time could be use here if Source Date Format is empty.
</property>
- <property name="Source Date Format" required="Yes">The original date
format</property>
+ <property name="Source Date Format" required="No">The original date
format. If empty, the Date String field must be a epoch time.</property>
<property name="Target Date Format" required="Yes">The new date
format</property>
<property name="Name of variable" required="No">The name of the
variable to set.</property>
</properties>
<p>Example:
<source>${__dateTimeConvert(01212018,MMddyyyy,dd/MM/yyyy,)}</source>
returns <code>21/01/2018</code>
</p>
+ <p>
+ With epoch time value: 1526574881000,
<source>${__dateTimeConvert(1526574881000,,dd/MM/yyyy HH:mm,)}</source> returns
<code>17/05/2018 16:34</code>
+ </p>
</component>
<component index="§-num;.5.36" name="__isPropDefined">
<description>