com.acsinet_solutions.util
Class DateUtils

java.lang.Object
  extended by com.acsinet_solutions.util.DateUtils

public final class DateUtils
extends java.lang.Object

Useful Date and Calendar utility methods.

Author:
Santiago Arriaga

Constructor Summary
DateUtils()
           
 
Method Summary
static boolean dayIsAfter(java.util.Calendar date1, java.util.Calendar date2)
          Implementation of a day granularity comparison
static boolean dayIsAfterOrEqual(java.util.Calendar date1, java.util.Calendar date2)
          Implementation of a day granularity comparison
static boolean dayIsBefore(java.util.Calendar date1, java.util.Calendar date2)
          Implementation of a day granularity comparison
static boolean dayIsBeforeOrEqual(java.util.Calendar date1, java.util.Calendar date2)
          Implementation of a day granularity comparison
static boolean dayIsEqual(java.util.Calendar date1, java.util.Calendar date2)
          Implementation of a day granularity comparison
static java.lang.String format(java.util.Calendar date)
          Return a simple date format
static java.util.Calendar getCalendar(int day, int month, int year)
          Return a non-lenient calendar for the given day specification.
static java.util.Calendar getCalendar(ValidationIssueBuilder builder, int day, int month, int year)
          Return a non-lenient calendar for the given day specification.
static java.lang.String getDateRange(java.util.Calendar startDate, java.util.Calendar endDate, java.util.Locale locale)
          Obtain a String for the given date range formatted in the given locale.
static int getDayDifference(java.util.Calendar last, java.util.Calendar first)
          Get the difference in days betweek both dates
static int getDayDifference(java.util.Date last, java.util.Date first)
          Get the difference in days betweek both dates
static int getDayOfWeek(java.util.Calendar calendar)
          Get the day of week for the given date
static java.lang.String getMonthName(int i, java.util.Locale locale)
          Get the month's name in the given locale
static int getWeekDifference(java.util.Calendar last, java.util.Calendar first)
          Get the difference in weeks betweek both dates
static int getWeekDifference(java.util.Date last, java.util.Date first)
          Get the difference in weeks betweek both dates
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtils

public DateUtils()
Method Detail

getCalendar

public static java.util.Calendar getCalendar(int day,
                                             int month,
                                             int year)
                                      throws ValidationException
Return a non-lenient calendar for the given day specification.

Parameters:
day - day of month
month - 1-based month of year
year - 4-digit year
Returns:
A not-null Calendar instance
Throws:
ValidationException

getCalendar

public static java.util.Calendar getCalendar(ValidationIssueBuilder builder,
                                             int day,
                                             int month,
                                             int year)
Return a non-lenient calendar for the given day specification.

Parameters:
day - day of month
month - 1-based month of year
year - 4-digit year
Returns:
A not-null Calendar instance

format

public static java.lang.String format(java.util.Calendar date)
Return a simple date format

Parameters:
date - A not-null valid Calendar instance
Returns:
A not-null String instance

dayIsBefore

public static boolean dayIsBefore(java.util.Calendar date1,
                                  java.util.Calendar date2)
Implementation of a day granularity comparison

Returns:
true if date1 before date2 in days.

dayIsBeforeOrEqual

public static boolean dayIsBeforeOrEqual(java.util.Calendar date1,
                                         java.util.Calendar date2)
Implementation of a day granularity comparison

Returns:
true if date1 before date2 in days.

dayIsAfter

public static boolean dayIsAfter(java.util.Calendar date1,
                                 java.util.Calendar date2)
Implementation of a day granularity comparison

Returns:
true if date1 after date2 in days.

dayIsAfterOrEqual

public static boolean dayIsAfterOrEqual(java.util.Calendar date1,
                                        java.util.Calendar date2)
Implementation of a day granularity comparison

Returns:
true if date1 after date2 in days.

dayIsEqual

public static boolean dayIsEqual(java.util.Calendar date1,
                                 java.util.Calendar date2)
Implementation of a day granularity comparison

Returns:
true if date1 after date2 in days.

getMonthName

public static java.lang.String getMonthName(int i,
                                            java.util.Locale locale)
Get the month's name in the given locale

Parameters:
i - the month's index from 1 to 12

getDateRange

public static java.lang.String getDateRange(java.util.Calendar startDate,
                                            java.util.Calendar endDate,
                                            java.util.Locale locale)
Obtain a String for the given date range formatted in the given locale.


getDayOfWeek

public static int getDayOfWeek(java.util.Calendar calendar)
Get the day of week for the given date

Parameters:
calendar - A not-null Calendar instance
Returns:
A 0 to 6 int: 0 for monday, 6 for sunday

getDayDifference

public static int getDayDifference(java.util.Date last,
                                   java.util.Date first)
Get the difference in days betweek both dates


getDayDifference

public static int getDayDifference(java.util.Calendar last,
                                   java.util.Calendar first)
Get the difference in days betweek both dates


getWeekDifference

public static int getWeekDifference(java.util.Date last,
                                    java.util.Date first)
Get the difference in weeks betweek both dates


getWeekDifference

public static int getWeekDifference(java.util.Calendar last,
                                    java.util.Calendar first)
Get the difference in weeks betweek both dates