VLab Common 1.2

pl.psnc.vlab.util
Class DateTools

java.lang.Object
  extended by pl.psnc.vlab.util.DateTools

public class DateTools
extends java.lang.Object

DateTools class - utility class for dealing with dates.

Author:
Dominik Stoklosa (~osa~)
Email address
osa@man.poznan.pl

Constructor Summary
DateTools()
          Creates new instance of Date Tools with default locale (English), default date pattern (dd, MMMM yyyy) and default time pattern (kk:mm:ss a)
DateTools(java.util.Locale locale, java.lang.String datePattern, java.lang.String timePattern)
          Creates new instance of Date Tools
 
Method Summary
 java.util.Date add(java.util.Date date, int field, int amount)
          Adds the specified amount of units to the given date
 java.util.Date addDay(java.util.Date date)
          Adds one day to current date
 java.util.Date addMonth(java.util.Date date, int months)
          Adds some months to the given date
 java.lang.String convertToFormat(java.lang.String newFormat, java.lang.String date, java.lang.String time)
          Convert the date and time to the given date and time format
 java.lang.String getDateAsString(java.util.Date date)
          Converts a given date into a string representation according to locale and date pattern.
 java.util.Date getDateFromString(java.lang.String value)
          Get date from string value.
 java.lang.String getDateTimeAsString(java.util.Date date)
          Converts a given date into a string date and time representation according to locale and time pattern.
 java.util.Date getDateTimeFromString(java.lang.String value)
          Get date and time from string value.
 java.lang.String getTimeAsString(java.util.Date date)
          Converts a given date into a string time representation according to locale and time pattern.
 java.util.Date getTimeFromString(java.lang.String value)
          Get time from string value.
 boolean isDateValid(java.lang.String date)
          Checks whether the given string date representation is valid according to the locale and date pattern.
 boolean isEqual(java.util.Date d1, java.util.Date d2)
          Compares two dates objects.
 boolean isGreater(java.util.Date d1, java.util.Date d2)
          Compares two dates objects.
 boolean isSmaller(java.util.Date d1, java.util.Date d2)
          Compares two dates objects.
 boolean isTimeValid(java.lang.String time)
          Checks whether the given string time representation is valid according to the locale and time pattern.
 java.util.Date setTime(java.util.Date date, java.util.Date time)
          Set the time to the current date
 java.util.Date subtractDay(java.util.Date date)
          Subtracts one day to current date
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateTools

public DateTools()
Creates new instance of Date Tools with default locale (English), default date pattern (dd, MMMM yyyy) and default time pattern (kk:mm:ss a)


DateTools

public DateTools(java.util.Locale locale,
                 java.lang.String datePattern,
                 java.lang.String timePattern)
Creates new instance of Date Tools

Parameters:
datePattern - date pattern
timePattern - time pattern
locale - locale, which will be used for the given date object
Method Detail

getDateAsString

public java.lang.String getDateAsString(java.util.Date date)
Converts a given date into a string representation according to locale and date pattern.

Parameters:
date - date
Returns:
date in the string representaion

getTimeAsString

public java.lang.String getTimeAsString(java.util.Date date)
Converts a given date into a string time representation according to locale and time pattern.

Parameters:
date - time in the string representaion
Returns:
date in the string representaion

getDateTimeAsString

public java.lang.String getDateTimeAsString(java.util.Date date)
Converts a given date into a string date and time representation according to locale and time pattern.

Parameters:
date - time in the string representaion
Returns:
date in the string representaion

getDateTimeFromString

public java.util.Date getDateTimeFromString(java.lang.String value)
Get date and time from string value.

Parameters:
value - date object
Returns:
new date object or NULL if the value is incorrect date

getDateFromString

public java.util.Date getDateFromString(java.lang.String value)
Get date from string value.

Parameters:
value - date object
Returns:
new date object or NULL if the value is incorrect date

getTimeFromString

public java.util.Date getTimeFromString(java.lang.String value)
Get time from string value.

Parameters:
value - date object
Returns:
new date object or NULL if the value is incorrect date

convertToFormat

public java.lang.String convertToFormat(java.lang.String newFormat,
                                        java.lang.String date,
                                        java.lang.String time)
Convert the date and time to the given date and time format

Parameters:
newFormat - new date format
date - date
time - time
Returns:
date in the string representaion

isDateValid

public boolean isDateValid(java.lang.String date)
Checks whether the given string date representation is valid according to the locale and date pattern.

Parameters:
date - date
Returns:
true if date is valid according to the given locale and format false otherwise

isTimeValid

public boolean isTimeValid(java.lang.String time)
Checks whether the given string time representation is valid according to the locale and time pattern.

Parameters:
time - time
Returns:
true if time is valid according to the given locale and format false otherwise

addDay

public java.util.Date addDay(java.util.Date date)
Adds one day to current date

Parameters:
date - date
Returns:
date object

addMonth

public java.util.Date addMonth(java.util.Date date,
                               int months)
Adds some months to the given date

Parameters:
months - number of month to be added
date - current date
Returns:
current date updated with one day

add

public java.util.Date add(java.util.Date date,
                          int field,
                          int amount)
Adds the specified amount of units to the given date

Parameters:
field - the date field, which should be changed i.e. Calendar.MONTH, Calnedar.MINUTE
amount - amount of units to be added
date - current date
Returns:
new date updated with the specified amount

subtractDay

public java.util.Date subtractDay(java.util.Date date)
Subtracts one day to current date

Parameters:
date - date
Returns:
date object

isGreater

public boolean isGreater(java.util.Date d1,
                         java.util.Date d2)
Compares two dates objects. If first argument is after the second date return true.

Parameters:
d1 - first date
d2 - second date
Returns:
true if date d1 is greater than d2 false otherwise

isEqual

public boolean isEqual(java.util.Date d1,
                       java.util.Date d2)
Compares two dates objects. If first argument is the same as the second date return true.

Parameters:
d1 - date
d2 - date
Returns:
true if date d1 equals to d2 false otherwise

isSmaller

public boolean isSmaller(java.util.Date d1,
                         java.util.Date d2)
Compares two dates objects. If first argument is before the second date return true.

Parameters:
d1 - first date
d2 - second date
Returns:
true if date d1 is smaller than d2 false otherwise

setTime

public java.util.Date setTime(java.util.Date date,
                              java.util.Date time)
Set the time to the current date

Parameters:
date - date to be set
time - time to be set
Returns:
date object

VLab Common 1.2

Copyright 2004 by VLAB Dominik Stoklosa.