com.bradrydzewski.gwt.calendar.client
Class DateUtils

java.lang.Object
  extended by com.bradrydzewski.gwt.calendar.client.DateUtils

public class DateUtils
extends Object

Contains utility methods involving dates. This class should remain GWT-API independent.

Author:
Carlos D. Morales

Field Summary
static long MILLIS_IN_A_DAY
           
 
Constructor Summary
DateUtils()
           
 
Method Summary
static boolean areOnTheSameDay(Date dateOne, Date dateTwo)
          Indicates whether two dates are on the same date by comparing their day, month and year values.
static boolean areOnTheSameMonth(Date dateOne, Date dateTwo)
          Indicates whether two dates are on the same month of the same year.
static void copyTime(Date source, Date target)
          Copies the hours, minutes and seconds in the source date into the target date object.
static int differenceInDays(Date endDate, Date startDate)
          Returns the number of days between the passed dates.
static Date firstOfNextMonth(Date date)
          Returns the date corresponding to the first day of the next month relative to the passed date.
static Date firstOfTheMonth(Date anyDayInMonth)
          Returns a clone of the anyDayInMonth date set to the first day of whatever its month is.
static boolean isWeekend(Date day)
           
static int minutesSinceDayStarted(Date day)
          Returns the amount of minutes elapsed since the beginning of the passed day.
static Date moveOneDayForward(Date date)
          Moves the date of the passed object to be one day after whatever date it has.
static Date newDate(Date date)
          Creates a new date with whatever date/time the passed date object represents.
static Date previousDay(Date date)
          Returns a day exactly 24 hours before the instant passed as date.
static void resetTime(Date date)
          Resets the date to have no time modifiers (hours, minutes, seconds.)
static Date shiftDate(Date date, int shift)
          Moves a date shift days.
static int year(Date date)
          Returns the full year (4-digits) of the passed date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MILLIS_IN_A_DAY

public static final long MILLIS_IN_A_DAY
See Also:
Constant Field Values
Constructor Detail

DateUtils

public DateUtils()
Method Detail

differenceInDays

public static int differenceInDays(Date endDate,
                                   Date startDate)
Returns the number of days between the passed dates.

Parameters:
endDate - The upper limit of the date range
startDate - The lower limit of the date range
Returns:
The number of days between endDate and starDate (inclusive)

year

public static int year(Date date)
Returns the full year (4-digits) of the passed date.

Parameters:
date - The date whose year will be returned
Returns:
The full year of the passed date.

shiftDate

public static Date shiftDate(Date date,
                             int shift)
Moves a date shift days. A clone of date to prevent undesired object modifications.

Parameters:
date - The date to shift
shift - The number of days to push the original date forward
Returns:
A new date pushed shift days forward

resetTime

public static void resetTime(Date date)
Resets the date to have no time modifiers (hours, minutes, seconds.)

Parameters:
date - The date to reset

areOnTheSameDay

public static boolean areOnTheSameDay(Date dateOne,
                                      Date dateTwo)
Indicates whether two dates are on the same date by comparing their day, month and year values. Time values such as hours and minutes are not considered in this comparison.

Parameters:
dateOne - The first date to test
dateTwo - The second date to test
Returns:
true if both dates have their date, month and year properties with the exact same values (whatever they are)

areOnTheSameMonth

public static boolean areOnTheSameMonth(Date dateOne,
                                        Date dateTwo)
Indicates whether two dates are on the same month of the same year.

Parameters:
dateOne - The first date of the comparison
dateTwo - The second date of the comparison
Returns:
true if both dates have the same year and month, false otherwise

firstOfTheMonth

public static Date firstOfTheMonth(Date anyDayInMonth)
Returns a clone of the anyDayInMonth date set to the first day of whatever its month is.

Parameters:
anyDayInMonth - Any date on a month+year
Returns:
A clone of the anyDayInMonth date, representing the first day of that same month and year

moveOneDayForward

public static Date moveOneDayForward(Date date)
Moves the date of the passed object to be one day after whatever date it has.

Parameters:
date - An object representing a date
Returns:
The day

firstOfNextMonth

public static Date firstOfNextMonth(Date date)
Returns the date corresponding to the first day of the next month relative to the passed date.

Parameters:
date - The reference date
Returns:
The first day of the next month, if the month of the passed date corresponds to december (11) one will be added to the year of the returned date.

previousDay

public static Date previousDay(Date date)
Returns a day exactly 24 hours before the instant passed as date. // TODO: This logic should address the time zone offset

Parameters:
date - A point in time from which the moment 24 hours before will be calculated
Returns:
A new object 24 hours prior to the passed date

copyTime

public static void copyTime(Date source,
                            Date target)
Copies the hours, minutes and seconds in the source date into the target date object.

Parameters:
source - The date with the hour, minutes and seconds to be copied
target - The date whose time fields will be set

minutesSinceDayStarted

public static int minutesSinceDayStarted(Date day)
Returns the amount of minutes elapsed since the beginning of the passed day.

Parameters:
day - The day to calculate the elapsed minutes
Returns:
The number of minutes since day started

newDate

public static Date newDate(Date date)
Creates a new date with whatever date/time the passed date object represents.

Parameters:
date - The source date
Returns:
A new date object representing the same date and time as the passed object

isWeekend

public static boolean isWeekend(Date day)


Copyright © 2012. All Rights Reserved.