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

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 80db317d EMPIREDB-431 DateUtils: function getDateBetween added
80db317d is described below

commit 80db317d0cda47da0da76776c639d0adce7bea52
Author: Rainer Döbele <[email protected]>
AuthorDate: Tue Nov 12 16:11:40 2024 +0100

    EMPIREDB-431
    DateUtils: function getDateBetween added
---
 .../src/main/java/org/apache/empire/commons/DateUtils.java   | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/empire-db/src/main/java/org/apache/empire/commons/DateUtils.java 
b/empire-db/src/main/java/org/apache/empire/commons/DateUtils.java
index 48129aff..ae646e9b 100644
--- a/empire-db/src/main/java/org/apache/empire/commons/DateUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/commons/DateUtils.java
@@ -30,6 +30,7 @@ import java.time.format.FormatStyle;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.slf4j.Logger;
@@ -193,6 +194,17 @@ public class DateUtils
         return (compareDates(date1, date2)==0);
     }
     
+    public static int getDaysBetween(Date date1, Date date2)
+    {
+        if (date1==null)
+            date1= getDateNow();
+        if (date2==null)
+            date2= getDateNow();
+        // calc
+        long diffInMillies = date2.getTime() - date1.getTime();
+        return (int)TimeUnit.DAYS.convert(diffInMillies, 
TimeUnit.MILLISECONDS);
+    }
+    
     // ------- parsing functions -----
 
     public static Date parseDate(String sDate, Locale locale)

Reply via email to