org.nuiton.util
Class DateUtils

java.lang.Object
  extended by org.nuiton.util.DateUtils

public class DateUtils
extends Object

Library for manipulating dates.

Version:
$Revision: 87 $ Last update: $Date: 2009-12-01 14:26:40 +0100 (Tue, 01 Dec 2009) $ by : $Author: fdesbois $
Author:
fdesbois

Field Summary
static String DEFAULT_PATTERN
           
static String MONTH_PATTERN
           
 
Constructor Summary
DateUtils()
           
 
Method Summary
static boolean between(Date myDate, Date beforeDate, Date afterDate)
          Check if the first date in argument is included between the two other dates.
static Date createDate(int dd, int mm, int yy)
          Create a new date from day, month and year (French version).
static Date createDateAfterToday(int ddStep, int mmStep, int yyStep)
          Create a new date after the current date (today) with modification on day, month and year.
static boolean currentPeriod(Date beforeDate, Date afterDate)
          Check if the current date is between the two dates in argument.
static String formatDate(Date date, String pattern)
          Format a date using the pattern in argument.
static String formatDate(Date date, String pattern, Locale locale)
           
static int getDifferenceInDays(Date beginDate, Date endDate)
          Do the difference between the two dates in argument.
static int getMonth(Date date)
          Get the month value from a date (between 0 and 11).
static String getMonthLibelle(int monthNumber)
          Get libelle of the month corresponding to the number given in argument.
static String getMonthLibelle(int monthNumber, Locale locale)
          Get libelle of the month corresponding to the number given in argument.
static Date parseDate(String date, String pattern)
          Parse a date using the pattern in argument.
static Date setFirstDayOfMonth(Date date)
          Set the first day of month to the date in argument.
static Date setLastDayOfMonth(Date date)
          Set the last day of month to the date in argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PATTERN

public static final String DEFAULT_PATTERN
See Also:
Constant Field Values

MONTH_PATTERN

public static final String MONTH_PATTERN
See Also:
Constant Field Values
Constructor Detail

DateUtils

public DateUtils()
Method Detail

formatDate

public static String formatDate(Date date,
                                String pattern)
Format a date using the pattern in argument. The pattern is the same using for DateFormat object.

Parameters:
date - the date to format
pattern - the pattern to use
Returns:
a String corresponding to the date formatted
See Also:
DateFormat

formatDate

public static String formatDate(Date date,
                                String pattern,
                                Locale locale)

parseDate

public static Date parseDate(String date,
                             String pattern)
                      throws ParseException
Parse a date using the pattern in argument. The pattern is the same using for DateFormat object.

Parameters:
date - the String to parse
pattern - the pattern to use
Returns:
a Date corresponding to the String argument parsed
Throws:
ParseException - for parsing errors
See Also:
DateFormat

createDate

public static Date createDate(int dd,
                              int mm,
                              int yy)
Create a new date from day, month and year (French version). The month is the real month of the year and not the one which is stored in Calendar object. *

Parameters:
dd - value of the day 1-31
mm - value of the month 1-12
yy - value of the year 0-9999
Returns:
a new date

createDateAfterToday

public static Date createDateAfterToday(int ddStep,
                                        int mmStep,
                                        int yyStep)
Create a new date after the current date (today) with modification on day, month and year. You can use negative values on arguments to have a date before today.

Parameters:
ddStep - nb days you want to increase from the current date
mmStep - nb months you want to increase from the current date
yyStep - nb years you want to increase from the current date
Returns:
a new date from the current date increase by days, months and years.

setLastDayOfMonth

public static Date setLastDayOfMonth(Date date)
Set the last day of month to the date in argument. The value depends on the month of the date. (30 april, 28 february, ...)

Parameters:
date - Date to modify
Returns:
the date with day of month modified

setFirstDayOfMonth

public static Date setFirstDayOfMonth(Date date)
Set the first day of month to the date in argument.

Parameters:
date - Date to modify
Returns:
the date with day of month modified

between

public static boolean between(Date myDate,
                              Date beforeDate,
                              Date afterDate)
Check if the first date in argument is included between the two other dates. The argument myDate can be equals to beforeDate or afterDate to validate the includes.

Parameters:
myDate - the date to test
beforeDate - the first date of the period to test
afterDate - the second date of the period to test
Returns:
true if myDate is included between beforeDate and afterDate

currentPeriod

public static boolean currentPeriod(Date beforeDate,
                                    Date afterDate)
Check if the current date is between the two dates in argument.

Parameters:
beforeDate - the first date of the period
afterDate - the second date of the period
Returns:
true if the current date is included between the two dates, false either
See Also:
between(java.util.Date, java.util.Date, java.util.Date)

getMonth

public static int getMonth(Date date)
Get the month value from a date (between 0 and 11).

Parameters:
date - the date to extract month
Returns:
the month value of the date

getDifferenceInDays

public static int getDifferenceInDays(Date beginDate,
                                      Date endDate)
Do the difference between the two dates in argument. The result is a number of days between the two dates. Ex : 28/01/2009 and 08/02/2009 return 11.

Parameters:
beginDate - first date
endDate - second date
Returns:
a number of days between beginDate and endDate

getMonthLibelle

public static String getMonthLibelle(int monthNumber,
                                     Locale locale)
Get libelle of the month corresponding to the number given in argument.

Parameters:
monthNumber - between 1-12
locale - Locale for language support
Returns:
a String corresponding to the libelle of the month

getMonthLibelle

public static String getMonthLibelle(int monthNumber)
Get libelle of the month corresponding to the number given in argument.

Parameters:
monthNumber - between 1-12
Returns:
a String corresponding to the libelle of the month


Copyright © 2004-2010 CodeLutin. All Rights Reserved.