fr.tireme.schemadoc.xs2dtd.utils
Class DateTime

java.lang.Object
  extended by java.util.Calendar
      extended by java.util.GregorianCalendar
          extended by fr.tireme.schemadoc.xs2dtd.utils.DateTime
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.util.Calendar>

public class DateTime
extends java.util.GregorianCalendar
implements java.io.Serializable

A DateTime object is used to manage Date in the system and to ensure sql date format compatibility

Author:
niemaz@xrce.xerox.com
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.GregorianCalendar
AD, BC
 
Fields inherited from class java.util.Calendar
ALL_STYLES, AM, AM_PM, APRIL, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DST_OFFSET, ERA, FEBRUARY, FIELD_COUNT, FRIDAY, HOUR, HOUR_OF_DAY, JANUARY, JULY, JUNE, LONG, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SHORT, SUNDAY, THURSDAY, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, YEAR, ZONE_OFFSET
 
Constructor Summary
DateTime()
          The object is initialized with the current date
DateTime(java.util.Date date)
          Initialize this DateTime object with a date one
DateTime(java.lang.String dateTime)
          The object is initizialized with the given datetime String which comes form the database.
 
Method Summary
 java.lang.String account()
          Account representation of the DateTime object (month - day)
 void addDay(int day)
          Add a day
 void addDayOfYear(int day)
          Add a day
 void addHour(int hour)
          Add an hour
 void addMinute(int minute)
          Add a minute
 void addMonth(int month)
          Add a month
 void addSecond(int second)
          Add a second
 void addWeekOfYear(int day)
          Add a week
 void addYear(int year)
          Add a year
 java.lang.String compact()
          Compact representation of the DateTime object which can be re-used to rebuild the DateTime object
 java.lang.String date()
           
 int difference(DateTime date)
          To compute the difference (in days) between this date and the other date.
 long differenceInMillis(DateTime date)
          Compute the difference in milliseconds
static java.lang.String duration(DateTime date1, DateTime date2)
          Work for duration less then 24h
static int durationInSecond(DateTime date1, DateTime date2)
          Work for duration less then 24h
 java.lang.String file()
          Representation for file of the DateTime object
 int getDay()
          Get day
 int getDayOfWeek()
          Get day ofthe week
 int getHour()
          Get hour
 int getMinute()
          Get minute
 int getMonth()
          Get month
 int getTimeInSecond()
          Get the time in milliseconds
 int getTimeInSecond(DateTime date)
          Get the time in milliseconds
 int getYear()
          Get year
static void init(int gmt)
          Initialize object.
 void setBeginOfDay()
          Set the beginning of the day (00:00:00)
 void setDay(int day)
          Set day
 void setEndOfDay()
          Set the end of the day (23:59:59)
 void setFirstDayOfMonth(int firstDay)
          Set the first day of the month (SUNDAY, MONDAY ..)
 void setHour(int hour)
          Set hour
 void setHourOfDay(int hour)
          Set the Hour of Day(0-23,24 means changing of day) (minutes,seconds .. are set to 0)
 void setMinute(int minute)
          Set minute
 void setMonth(int month)
          Set month
static void setNewDateFormat(java.text.DateFormat newDateFormat)
          To set a new DateFormat
static void setNewTimeZone(java.util.TimeZone newTimeZone)
          To set a new TimeZone
 void setYear(int year)
           
 java.lang.String toSql()
          Sql representation of the DataTime object to put in the database
 java.lang.String toSqlDate()
           
 java.lang.String toString()
          External representation of the DateTime object
 
Methods inherited from class java.util.GregorianCalendar
add, clone, equals, getActualMaximum, getActualMinimum, getGreatestMinimum, getGregorianChange, getLeastMaximum, getMaximum, getMinimum, getTimeZone, hashCode, isLeapYear, roll, roll, setGregorianChange, setTimeZone
 
Methods inherited from class java.util.Calendar
after, before, clear, clear, compareTo, get, getAvailableLocales, getDisplayName, getDisplayNames, getFirstDayOfWeek, getInstance, getInstance, getInstance, getInstance, getMinimalDaysInFirstWeek, getTime, getTimeInMillis, isLenient, isSet, set, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTime, setTimeInMillis
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateTime

public DateTime()
The object is initialized with the current date


DateTime

public DateTime(java.lang.String dateTime)
The object is initizialized with the given datetime String which comes form the database. It can also be initialized with a DateTime.compact() String.

Parameters:
dateTime - String format

DateTime

public DateTime(java.util.Date date)
Initialize this DateTime object with a date one

Parameters:
date - Date format
Method Detail

init

public static void init(int gmt)
Initialize object. Invoked on object creation

Parameters:
gmt - offset

toSql

public java.lang.String toSql()
Sql representation of the DataTime object to put in the database

Returns:
the sql datetime string

toSqlDate

public java.lang.String toSqlDate()
Returns:
the SQL Date

toString

public java.lang.String toString()
External representation of the DateTime object

Overrides:
toString in class java.util.Calendar
Returns:
the external representation

date

public java.lang.String date()
Returns:
a date String like Jan,25 1999

compact

public java.lang.String compact()
Compact representation of the DateTime object which can be re-used to rebuild the DateTime object

Returns:
a compact representation

account

public java.lang.String account()
Account representation of the DateTime object (month - day)

Returns:
String

file

public java.lang.String file()
Representation for file of the DateTime object

Returns:
String

duration

public static java.lang.String duration(DateTime date1,
                                        DateTime date2)
Work for duration less then 24h

Parameters:
date1 - - start time
date2 - - end time
Returns:
String

durationInSecond

public static int durationInSecond(DateTime date1,
                                   DateTime date2)
Work for duration less then 24h

Parameters:
date1 - - start time
date2 - - end time
Returns:
int - seconds

setNewDateFormat

public static void setNewDateFormat(java.text.DateFormat newDateFormat)
To set a new DateFormat

Parameters:
newDateFormat -

setNewTimeZone

public static void setNewTimeZone(java.util.TimeZone newTimeZone)
To set a new TimeZone

Parameters:
newTimeZone -

difference

public int difference(DateTime date)
To compute the difference (in days) between this date and the other date. Applies a round conversion.

Parameters:
date - the second argument
Returns:
the difference (can be negative)

differenceInMillis

public long differenceInMillis(DateTime date)
Compute the difference in milliseconds

Parameters:
date - the second argument
Returns:
the difference (can be negative)

setHourOfDay

public void setHourOfDay(int hour)
Set the Hour of Day(0-23,24 means changing of day) (minutes,seconds .. are set to 0)


setEndOfDay

public void setEndOfDay()
Set the end of the day (23:59:59)


setBeginOfDay

public void setBeginOfDay()
Set the beginning of the day (00:00:00)


setFirstDayOfMonth

public void setFirstDayOfMonth(int firstDay)
Set the first day of the month (SUNDAY, MONDAY ..)

Parameters:
firstDay -

getTimeInSecond

public int getTimeInSecond(DateTime date)
Get the time in milliseconds

Parameters:
date - - the date to convert
Returns:
int - the date converted

getTimeInSecond

public int getTimeInSecond()
Get the time in milliseconds

Returns:
int - the date converted

addSecond

public void addSecond(int second)
Add a second

Parameters:
second - - the minute to add

addMinute

public void addMinute(int minute)
Add a minute

Parameters:
minute - - the minute to add

addHour

public void addHour(int hour)
Add an hour

Parameters:
hour - - the hour to add

addDay

public void addDay(int day)
Add a day

Parameters:
day - - the day to add

addDayOfYear

public void addDayOfYear(int day)
Add a day

Parameters:
day - - the day to add

addWeekOfYear

public void addWeekOfYear(int day)
Add a week

Parameters:
day - - the day to add

addMonth

public void addMonth(int month)
Add a month

Parameters:
month - - the month to add

addYear

public void addYear(int year)
Add a year

Parameters:
year - - the year to add

setMinute

public void setMinute(int minute)
Set minute

Parameters:
minute - - the minute to set

setHour

public void setHour(int hour)
Set hour

Parameters:
hour - - the hour to set

setDay

public void setDay(int day)
Set day

Parameters:
day - - the day to set

setMonth

public void setMonth(int month)
Set month

Parameters:
month - - the month to set

setYear

public void setYear(int year)
Parameters:
year -

getMinute

public int getMinute()
Get minute

Returns:
int

getHour

public int getHour()
Get hour

Returns:
int

getDay

public int getDay()
Get day

Returns:
int

getDayOfWeek

public int getDayOfWeek()
Get day ofthe week

Returns:
int

getMonth

public int getMonth()
Get month

Returns:
int

getYear

public int getYear()
Get year

Returns:
int