MDi JLib
1.7.4

com.microdeveloper.common.date
Class EDate

java.lang.Object
  extended by com.microdeveloper.common.date.EDate

public class EDate
extends Object

Utilities to easily generate dates from simple calls. Simulates date functions typically found in PL/SQL to ease the transition to Java for Oracle developers.

Refer to SimpleDateFormat or see setFormat(java.lang.String) for information on format masks.

Since:
1.0
Version:
1.1
Author:
MicroDeveloper, Inc.

Constructor Summary
EDate()
          Creates a new instance of EDates initialized to the current Date.
EDate(Date d)
          Creates a new instance of EDate with an initial date specified by d
EDate(Date d, String format)
          Creates a new instance of EDate with an initial date specified using the date format specified
 
Method Summary
static Date addDays(Date date, int d)
          Adds the given number of days to the given date and returns the result
 void addDays(int d)
          Adds the given days to the current date established in this.
static Date addHours(Date date, int h)
          Adds the given number of hours to the date given
 void addHours(int h)
          Adds the given number of hours to the current time in this.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a property change listener
 long daysBetween(Date start, Date end)
          Returns the number of days between two dates as a real number
static Date epochToDate(int epochDate)
          Converts an Epoch date to a Date object.
 Date getDate()
          Gets the currently established date
 String getDate(String format, String timeZone)
          Returns the currently established date/time as a String using the format and time zone given
 String getDateFormatProperty()
          Returns the current date format property
static int getDays(GregorianCalendar g1, GregorianCalendar g2)
          Number of days between two Gregorian dates.
 EDateInterface geteDateInterface()
          Returns the interface.
static String getElapsedHMS(int timeInSeconds)
          Creates a textual representaion of the time given as seconds in the form of "hh hour(s) mm minute(s) ss seconds(s)".
static int getElapsedSeconds(Date startTime, Date endTime)
          Calculates the number of seconds between two dates.
static long getElapsedSeconds(GregorianCalendar gc1, GregorianCalendar gc2)
          Calculates the number of seconds elapsed between two Gregorian dates
 int getEpochDate()
          Returns the objects current date/time as an Epoch date/time
 String getGMTDate()
          Returns the Greewich mean time as a String
 String getGMTDate(String format)
          Returns the current GMT date time in the format given
 String getLocalDate()
          Returns the current local date as a string
static int getMonths(GregorianCalendar g1, GregorianCalendar g2)
          Number of months between two Gregorian dates.
 String getSysDate()
          Returns the current system date (synonymous with the Oracle Sysdate function)
 String getSysDate(String format)
          Returns the current date time in the format given
 String getSysZone()
          Gets the zone for the system where the class is currently executing
 String getTimeZoneProperty()
          Returns the current time zone property
static String getToday()
          Returns the current system date
static String getToday(String format)
          Returns the current system date
 String getUTCDate()
          Returns the current UTC (universal coordinated) date as a string
 String getUTCDate(String format)
          Returns the current UTC date time in the format given
 String getZoneDate(String timeZone)
          Returns the current date time based on the timeZone given
 String getZoneDate(String format, String timeZone)
          Returns the current date time based on the timeZone given in the format given
 String getZoneList()
          Returns a list of the available java time zones
 String minutes_to_time(double min)
          Returns a string which represents the a time based on the number of minutes given.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a property change listener
 void resetTimeZone()
           
 void setDate(Date d)
           
 void setDate(String ds, String format)
          Sets the current date of this to the date String given based on the format given.
 void setDateFormatProperty(String value)
          Sets the current date format property
 void setEpochDate(int epochDate)
          Sets the current date time of the object to the given Epoch time
 void setFormat(String format)
          Sets the default format mask used for Date string operations.
 void setNow()
          Sets the date/time of the instanciated object to the current dat/time
 void setTimeZoneProperty(String value)
          Sets the current time zone property
static Date subtractDays(Date date, int d)
          Subtracts the given number of days from the given date
 void subtractDays(int d)
          Subtracts the given number of days from this.
static Date subtractHours(Date date, int h)
          Subtracts a given number of hours from the given date
 void subtractHours(int h)
          Subtracts the given number of hours from this.
static Date toDate(String ds, String format)
          Converts a given String to a Date object using the format given
 int toEpoch()
          Converts the current objects Date to an Epoch date
static int toEpoch(Date d)
          Converts the given date to an Epoch date
 String toString()
          Returns this object as a String
 String toString(String format)
          Returns this object as a String in the format given
static String toString(String format, Date d, TimeZone tz)
          Converts a given date into a String using the format given for the specified time zone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EDate

public EDate()
Creates a new instance of EDates initialized to the current Date.


EDate

public EDate(Date d)
Creates a new instance of EDate with an initial date specified by d

Parameters:
d - the date to initialize the EDate object to

EDate

public EDate(Date d,
             String format)
Creates a new instance of EDate with an initial date specified using the date format specified

Parameters:
d - the date to initialize the EDate object to
format - the default date format to use for this object
Method Detail

setFormat

public void setFormat(String format)
Sets the default format mask used for Date string operations.

The format mask should follow the java SimpleDateFormat model. If an invalid format is given, the default format is used instead. The default date format is "E, MMM d, yyyy HH:mm:ss"

Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800

Parameters:
format -

setDate

public void setDate(Date d)

toString

public static String toString(String format,
                              Date d,
                              TimeZone tz)
Converts a given date into a String using the format given for the specified time zone.

Parameters:
format - java date mask format
d - date to convert
tz - timezone to use for the conversion
Returns:
date respresented as a String in the requested format

getDate

public String getDate(String format,
                      String timeZone)
Returns the currently established date/time as a String using the format and time zone given

Parameters:
format - java date mask format
timeZone - timezone to use for the conversion
Returns:
completed String representing the currently established date time in the format requested

addDays

public static Date addDays(Date date,
                           int d)
Adds the given number of days to the given date and returns the result

Parameters:
date -
d - number of days to add to the given date
Returns:
date with d days added to it

addHours

public static Date addHours(Date date,
                            int h)
Adds the given number of hours to the date given

Parameters:
date - date to increment
h - hours to increment by
Returns:
resulting date

subtractDays

public static Date subtractDays(Date date,
                                int d)
Subtracts the given number of days from the given date

Parameters:
date - the date to subtract from
d - number of days to subtract
Returns:
date with d days subtracted

subtractHours

public static Date subtractHours(Date date,
                                 int h)
Subtracts a given number of hours from the given date

Parameters:
date - the date to subtract from
h - number of hours to subtract
Returns:
date with h hours subtracted

resetTimeZone

public void resetTimeZone()

toDate

public static Date toDate(String ds,
                          String format)
Converts a given String to a Date object using the format given

Parameters:
ds - Date/time expressed as a String
format - format to use in decoding the date String
Returns:
Date object representing the given String

toEpoch

public static int toEpoch(Date d)
Converts the given date to an Epoch date

Parameters:
d - Date to convert
Returns:
Epoch date representing the given date

epochToDate

public static Date epochToDate(int epochDate)
Converts an Epoch date to a Date object.

Parameters:
epochDate - date expressed as an epoch date (an integer)
Returns:
Date object created from the epoch date

getElapsedSeconds

public static int getElapsedSeconds(Date startTime,
                                    Date endTime)
Calculates the number of seconds between two dates.

Parameters:
startTime - starting time as a Date object
endTime - ending time as a Date object
Returns:
number of whole seconds between the two given dates

getDays

public static int getDays(GregorianCalendar g1,
                          GregorianCalendar g2)
Number of days between two Gregorian dates.

Parameters:
g1 - first Gregorian date
g2 - second Gregorian date
Returns:
whole days between the g1 and g2 dates

getMonths

public static int getMonths(GregorianCalendar g1,
                            GregorianCalendar g2)
Number of months between two Gregorian dates.

Parameters:
g1 - first Gregorian date
g2 - second Gregorian date
Returns:
whole months between the g1 and g2 dates

getElapsedHMS

public static String getElapsedHMS(int timeInSeconds)
Creates a textual representaion of the time given as seconds in the form of "hh hour(s) mm minute(s) ss seconds(s)". For example, 60 seconds would equal "00 hour(s) 01 minute(s) 00 seconds(s)

Parameters:
timeInSeconds - seconds to convert
Returns:
seconds represented in a textual format

getElapsedSeconds

public static long getElapsedSeconds(GregorianCalendar gc1,
                                     GregorianCalendar gc2)
Calculates the number of seconds elapsed between two Gregorian dates

Parameters:
gc1 - first Gregorian date
gc2 - second Gregorian date
Returns:
whole seconds between the g1 and g2 dates

geteDateInterface

public EDateInterface geteDateInterface()
Returns the interface.

Returns:
EDateInterface

getDateFormatProperty

public String getDateFormatProperty()
Returns the current date format property

Returns:
current format for string conversions

setDateFormatProperty

public void setDateFormatProperty(String value)
Sets the current date format property

Parameters:
value - date format to use

getTimeZoneProperty

public String getTimeZoneProperty()
Returns the current time zone property

Returns:
String representing the current time zone

setTimeZoneProperty

public void setTimeZoneProperty(String value)
Sets the current time zone property

Parameters:
value - the time zone to use

getToday

public static String getToday()
Returns the current system date

Returns:
String representing the current date/time

getToday

public static String getToday(String format)
Returns the current system date

Parameters:
format - java date mask format to use which overrides the default format
Returns:
String representing the current date/time

getSysDate

public String getSysDate()
Returns the current system date (synonymous with the Oracle Sysdate function)

Returns:
String representing the current date/time

getLocalDate

public String getLocalDate()
Returns the current local date as a string

Returns:
String representing the current local date/time

getUTCDate

public String getUTCDate()
Returns the current UTC (universal coordinated) date as a string

Returns:
String representing the current UTC date/time

getGMTDate

public String getGMTDate()
Returns the Greewich mean time as a String

Returns:
Current Greenwich mean time

getSysDate

public String getSysDate(String format)
Returns the current date time in the format given

Parameters:
format - java date mask format to use which overrides the current property
Returns:
The current date/time in the format requested
See Also:
getSysDate()

getUTCDate

public String getUTCDate(String format)
Returns the current UTC date time in the format given

Parameters:
format - java date mask format to use which overrides the current property
Returns:
The current UTC date/time in the format requested
See Also:
getUTCDate()

getGMTDate

public String getGMTDate(String format)
Returns the current GMT date time in the format given

Parameters:
format - java date mask format to use which overrides the current property
Returns:
The current GMT date/time in the format requested
See Also:
getGMTDate()

getZoneDate

public String getZoneDate(String timeZone)
Returns the current date time based on the timeZone given

Parameters:
timeZone - java Timezone to use
Returns:
date/time as a String

getZoneDate

public String getZoneDate(String format,
                          String timeZone)
Returns the current date time based on the timeZone given in the format given

Parameters:
timeZone - java Timezone to use
format - java date mask format to use which overrides the current property
Returns:
date/time as a String

getZoneList

public String getZoneList()
Returns a list of the available java time zones

Returns:
the list of zones as a String

getSysZone

public String getSysZone()
Gets the zone for the system where the class is currently executing

Returns:
String representing the current Zone for the executing system

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a property change listener

Parameters:
listener - the listener to add

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a property change listener

Parameters:
listener - the listener to remove

getDate

public Date getDate()
Gets the currently established date

Returns:
Date object representing the objects established date/time

setNow

public void setNow()
Sets the date/time of the instanciated object to the current dat/time


toString

public String toString()
Returns this object as a String

Overrides:
toString in class Object
Returns:
this converted to a String

toString

public String toString(String format)
Returns this object as a String in the format given

Parameters:
format - format to use
Returns:
this converted to a String

addDays

public void addDays(int d)
Adds the given days to the current date established in this.

Parameters:
d - days to add

addHours

public void addHours(int h)
Adds the given number of hours to the current time in this.

Parameters:
h - hours to add

subtractHours

public void subtractHours(int h)
Subtracts the given number of hours from this.

Parameters:
h - hours to subtract

subtractDays

public void subtractDays(int d)
Subtracts the given number of days from this.

Parameters:
d - days to subtract

minutes_to_time

public String minutes_to_time(double min)
Returns a string which represents the a time based on the number of minutes given.

Parameters:
min - minutes to convert
Returns:
String based representation

setDate

public void setDate(String ds,
                    String format)
Sets the current date of this to the date String given based on the format given.

Parameters:
ds - Date/time as a String
format - format for the given Date/time to use in decoding the String

toEpoch

public int toEpoch()
Converts the current objects Date to an Epoch date

Returns:
Currently established date/time as an Epoch date/time
See Also:
getEpochDate()

getEpochDate

public int getEpochDate()
Returns the objects current date/time as an Epoch date/time

Returns:
Currently established date/time as an Epoch date/time
See Also:
toEpoch()

setEpochDate

public void setEpochDate(int epochDate)
Sets the current date time of the object to the given Epoch time

Parameters:
epochDate - date/time expressed as an Epoch date

daysBetween

public long daysBetween(Date start,
                        Date end)
Returns the number of days between two dates as a real number

Parameters:
start - first date
end - second date
Returns:
number days between them as a real number

MDi JLib
1.7.4

Copyright©2001-2007 MicroDeveloper, Inc. All Rights Reserved.