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

kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 3110f02  [BUG][API]Fix format2Duration when parameter has one is null 
(#4802)
3110f02 is described below

commit 3110f023afcc3a57afa41f6b485284f5d2bd7cc4
Author: felix.wang <[email protected]>
AuthorDate: Fri Feb 19 23:18:11 2021 +0800

    [BUG][API]Fix format2Duration when parameter has one is null (#4802)
    
    * fix format2Duration when parameter has one is null
---
 .../org/apache/dolphinscheduler/common/utils/DateUtils.java    |  3 +++
 .../apache/dolphinscheduler/common/utils/DateUtilsTest.java    | 10 +++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
index a531299..c484dc0 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
@@ -259,6 +259,9 @@ public class DateUtils {
      * @return format time
      */
     public static String format2Duration(Date d1, Date d2) {
+        if (d1 == null || d2 == null) {
+            return null;
+        }
         return format2Duration(differMs(d1, d2));
     }
 
diff --git 
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
 
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
index 63f0be5..4a88085 100644
--- 
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
+++ 
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java
@@ -153,7 +153,7 @@ public class DateUtilsTest {
 
     @Test
     public void getCurrentTimeStamp() {
-        String timeStamp =  DateUtils.getCurrentTimeStamp();
+        String timeStamp = DateUtils.getCurrentTimeStamp();
         Assert.assertNotNull(timeStamp);
     }
 
@@ -196,4 +196,12 @@ public class DateUtilsTest {
 
     }
 
+    @Test
+    public void testNullDuration() {
+        // days hours minutes seconds
+        Date d1 = DateUtils.stringToDate("2020-01-20 11:00:00");
+        Date d2 = null;
+        Assert.assertNull(DateUtils.format2Duration(d1, d2));
+    }
+
 }

Reply via email to