Author: agilliland
Date: Wed Jul 25 11:52:35 2007
New Revision: 559556

URL: http://svn.apache.org/viewvc?view=rev&rev=559556
Log:
add methods for start of hour and start/end of hour.

Modified:
    roller/trunk/components/core/src/java/org/apache/roller/util/DateUtil.java

Modified: 
roller/trunk/components/core/src/java/org/apache/roller/util/DateUtil.java
URL: 
http://svn.apache.org/viewvc/roller/trunk/components/core/src/java/org/apache/roller/util/DateUtil.java?view=diff&rev=559556&r1=559555&r2=559556
==============================================================================
--- roller/trunk/components/core/src/java/org/apache/roller/util/DateUtil.java 
(original)
+++ roller/trunk/components/core/src/java/org/apache/roller/util/DateUtil.java 
Wed Jul 25 11:52:35 2007
@@ -54,6 +54,32 @@
     
     
     /**
+     * Returns a Date set to the first possible millisecond of the day, just
+     * after midnight. If a null day is passed in, a new Date is created.
+     * midnight (00m 00h 00s)
+     */
+    public static Date getStartOfDay(Date day) {
+        return getStartOfDay(day, Calendar.getInstance());
+    }
+    
+    
+    /**
+     * Returns a Date set to the first possible millisecond of the day, just
+     * after midnight. If a null day is passed in, a new Date is created.
+     * midnight (00m 00h 00s)
+     */
+    public static Date getStartOfDay(Date day, Calendar cal) {
+        if (day == null) day = new Date();
+        cal.setTime(day);
+        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
+        cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
+        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
+        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
+        return cal.getTime();
+    }
+    
+    
+    /**
      * Returns a Date set to the last possible millisecond of the day, just
      * before midnight. If a null day is passed in, a new Date is created.
      * midnight (00m 00h 00s)
@@ -75,6 +101,29 @@
     
     
     /**
+     * Returns a Date set to the first possible millisecond of the hour.
+     * If a null day is passed in, a new Date is created.
+     */
+    public static Date getStartOfHour(Date day) {
+        return getStartOfHour(day, Calendar.getInstance());
+    }
+    
+    
+    /**
+     * Returns a Date set to the first possible millisecond of the hour.
+     * If a null day is passed in, a new Date is created.
+     */
+    public static Date getStartOfHour(Date day, Calendar cal) {
+        if (day == null) day = new Date();
+        cal.setTime(day);
+        cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
+        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
+        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
+        return cal.getTime();
+    }
+    
+    
+    /**
      * Returns a Date set to the last possible millisecond of the day, just
      * before midnight. If a null day is passed in, a new Date is created.
      * midnight (00m 00h 00s)
@@ -98,6 +147,49 @@
     
     
     /**
+     * Returns a Date set to the first possible millisecond of the minute.
+     * If a null day is passed in, a new Date is created.
+     */
+    public static Date getStartOfMinute(Date day) {
+        return getStartOfMinute(day, Calendar.getInstance());
+    }
+    
+    
+    /**
+     * Returns a Date set to the first possible millisecond of the minute.
+     * If a null day is passed in, a new Date is created.
+     */
+    public static Date getStartOfMinute(Date day, Calendar cal) {
+        if (day == null) day = new Date();
+        cal.setTime(day);
+        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
+        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
+        return cal.getTime();
+    }
+    
+    
+    /**
+     * Returns a Date set to the last possible millisecond of the minute.
+     * If a null day is passed in, a new Date is created.
+     */
+    public static Date getEndOfMinute(Date day) {
+        return getEndOfMinute(day, Calendar.getInstance());
+    }
+    
+    
+    public static Date getEndOfMinute(Date day, Calendar cal) {
+        if (day == null || cal == null) {
+            return day;
+        }
+        
+        cal.setTime(day);
+        cal.set(Calendar.SECOND,      cal.getMaximum(Calendar.SECOND));
+        cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
+        return cal.getTime();
+    }
+    
+    
+    /**
      * Returns a Date set to the first possible millisecond of the month, just
      * after midnight. If a null day is passed in, a new Date is created.
      * midnight (00m 00h 00s)
@@ -153,32 +245,6 @@
         // back up one day
         cal.add(Calendar.DAY_OF_MONTH, -1);
         
-        return cal.getTime();
-    }
-    
-    
-    /**
-     * Returns a Date set to the first possible millisecond of the day, just
-     * after midnight. If a null day is passed in, a new Date is created.
-     * midnight (00m 00h 00s)
-     */
-    public static Date getStartOfDay(Date day) {
-        return getStartOfDay(day, Calendar.getInstance());
-    }
-    
-    
-    /**
-     * Returns a Date set to the first possible millisecond of the day, just
-     * after midnight. If a null day is passed in, a new Date is created.
-     * midnight (00m 00h 00s)
-     */
-    public static Date getStartOfDay(Date day, Calendar cal) {
-        if (day == null) day = new Date();
-        cal.setTime(day);
-        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
-        cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
-        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
-        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
         return cal.getTime();
     }
     


Reply via email to