Browse Source

[BUG][API]Fix format2Duration when parameter has one is null (#4802)

* fix format2Duration when parameter has one is null
pull/3/MERGE
felix.wang 4 years ago committed by GitHub
parent
commit
3110f023af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java
  2. 8
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java

3
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java

@ -259,6 +259,9 @@ public class DateUtils {
* @return format time * @return format time
*/ */
public static String format2Duration(Date d1, Date d2) { public static String format2Duration(Date d1, Date d2) {
if (d1 == null || d2 == null) {
return null;
}
return format2Duration(differMs(d1, d2)); return format2Duration(differMs(d1, d2));
} }

8
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java

@ -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));
}
} }

Loading…
Cancel
Save