Package eu.webtoolkit.jwt
Class WDate
java.lang.Object
eu.webtoolkit.jwt.WDate
- All Implemented Interfaces:
Comparable<WDate>
Class which holds a date on the gregorian calendar, specified as
day/month/year.
A valid date may be specified by year, month, and day of month (using the
WDate(int, int, int)
constructor, or the
setDate(int year, int month, int day)
method). When attempting to
specify an invalid date (with an impossible combination of year/month/date)
an IllegalArgumentException
will be thrown.
The class provides a flexible way for converting between strings and dates.
Use toString() to convert to strings, and fromString() for parsing strings.
Both methods take a format string, and the same format syntax is supported by
both methods.
Simple operations are supported to compare dates, or to calculate with dates.-
Constructor Summary
ConstructorDescriptionWDate
(int year, int month, int day) Specify a date by year, month (1-12), and day (1-31) When the date is invalid, an IllegalArgumentException is thrown.WDate
(int year, int month, int day, int hour, int minute, int second) Set a date by year, month (1-12), day (1-31), hour (0-23), minute (0-59), second (0 - 59) When the date is invalid, an IllegalArgumentException is thrown.WDate
(int year, int month, int day, int hour, int minute, int second, int millisecond) Set a date by year, month (1-12), day (1-31), hour (0-23), minute (0-59), second (0 - 59), millisecond (0 - 999) When the date is invalid, an IllegalArgumentException is thrown.Specify a date by a Date object. -
Method Summary
Modifier and TypeMethodDescriptionaddDays
(int ndays) Add days to a date.addMilliseconds
(int nMilliseconds) Adds milliseconds.addMonths
(int nmonths) Add months to a date.addSeconds
(int nSeconds) Adds seconds.addYears
(int nyears) Add years to a date.boolean
Tests if this date is after the specified date.boolean
Tests if this date is after the specified date.int
Compares this WDate object with the specified WDate object for order.boolean
Compares two dates for equality.static WDate
fromJulianDay
(int jd) Converts a Julian Day jd to a WDate.static WDate
fromString
(String text) Parse a WString to a date using a default format.static WDate
fromString
(String text, String format) Parse a String to a date using a specified format.static WDate
Construct a date for the current client date.static WDate
Construct a date for the current server date.getDate()
Returns the internal Date object.int
getDay()
Day of month (1-31)int
Day of week (1-7)int
Returns the number of days from this date to date.static String
Returns the default date format.int
getHour()
Hour (0-24)static WString
getLongDayName
(int weekday) Returns the long day name.static WString
getLongMonthName
(int month) Returns the long month name.int
Millisecond (0-999)long
Returns the difference between to time values (in milliseconds).int
Minute (0-59)int
getMonth()
Month (1-12)int
Second (0-59)int
Returns the difference between to time values (in seconds).static WString
getShortDayName
(int weekday) Returns the short day name.static WString
getShortMonthName
(int month) Returns the short month name.getTime()
Gets this date's timeReturns the difference between two WDate values (as text).int
getYear()
Yearint
hashCode()
Returns a hash code value for the object.void
setDate
(int year, int month, int day) Set a date by year, month (1-12), day (1-31) When the new date is invalid, an IllegalArgumentException is thrown.void
setDate
(int year, int month, int day, int hour, int minute, int second) Set a date by year, month (1-12), and day (1-31), hour (0-23), minute (0-59), second (0 - 59).void
setDate
(int year, int month, int day, int hour, int minute, int second, int millisecond) Set a date by year, month (1-12), day (1-31), hour (0-23), minute (0-59), second (0 - 59), millisecond (0 - 999) When the new date is invalid, an IllegalArgumentException is thrown.void
setTime
(int hour, int minute) Set this date's time by hour (0-23) and minute (0-59).void
setTime
(int hour, int minute, int second) Set this date's time by hour (0-23), minute (0-59) and second (0 - 59).void
setTime
(int hour, int minute, int second, int millisecond) Set this date's time by hour (0-23), minute (0-59), second (0 - 59) and millisecond (0 - 999).void
Sets this date's time by WTime When the new date is invalid, an IllegalArgumentException is thrown.static void
setTimezone
(TimeZone timeZone) Sets default timezone Ifnull
, then the default (local) timezone will be used.int
Converts the date to a Julian day.toString()
Format this date to a String using a default format.Format this date to a WString using a specified format.
-
Constructor Details
-
WDate
public WDate(int year, int month, int day, int hour, int minute, int second, int millisecond) Set a date by year, month (1-12), day (1-31), hour (0-23), minute (0-59), second (0 - 59), millisecond (0 - 999) When the date is invalid, an IllegalArgumentException is thrown. -
WDate
public WDate(int year, int month, int day, int hour, int minute, int second) Set a date by year, month (1-12), day (1-31), hour (0-23), minute (0-59), second (0 - 59) When the date is invalid, an IllegalArgumentException is thrown. -
WDate
public WDate(int year, int month, int day) Specify a date by year, month (1-12), and day (1-31) When the date is invalid, an IllegalArgumentException is thrown. -
WDate
Specify a date by a Date object.
-
-
Method Details
-
setTimezone
Sets default timezone Ifnull
, then the default (local) timezone will be used. You may want to change this to e.g. GMT to not be affected by oddities in the local time zone, such as for example missing 'time'. (see e.g. http://stackoverflow.com/questions/6140624/java-missing-28-seconds) The default isnull
. -
setDate
public void setDate(int year, int month, int day, int hour, int minute, int second, int millisecond) Set a date by year, month (1-12), day (1-31), hour (0-23), minute (0-59), second (0 - 59), millisecond (0 - 999) When the new date is invalid, an IllegalArgumentException is thrown. -
setDate
public void setDate(int year, int month, int day) Set a date by year, month (1-12), day (1-31) When the new date is invalid, an IllegalArgumentException is thrown.- See Also:
-
setDate
public void setDate(int year, int month, int day, int hour, int minute, int second) Set a date by year, month (1-12), and day (1-31), hour (0-23), minute (0-59), second (0 - 59). When the new date is invalid, an IllegalArgumentException is thrown. -
setTime
public void setTime(int hour, int minute, int second, int millisecond) Set this date's time by hour (0-23), minute (0-59), second (0 - 59) and millisecond (0 - 999). When the new date is invalid, an IllegalArgumentException is thrown. -
setTime
public void setTime(int hour, int minute, int second) Set this date's time by hour (0-23), minute (0-59) and second (0 - 59). When the new date is invalid, an IllegalArgumentException is thrown. -
setTime
public void setTime(int hour, int minute) Set this date's time by hour (0-23) and minute (0-59). When the new date is invalid, an IllegalArgumentException is thrown. -
setTime
Sets this date's time by WTime When the new date is invalid, an IllegalArgumentException is thrown. -
getTime
Gets this date's time- Returns:
- WTime object
-
addSeconds
Adds seconds. Returns a time that is nSeconds seconds later than this time. Negative values for nSeconds will result in a time that is as many seconds earlier. -
addMilliseconds
Adds milliseconds. Returns a time that is nMilliseconds milliseconds later than this time. Negative values for nMilliseconds will result in a time that is as many seconds earlier. -
addDays
Add days to a date. Returns a date that is ndays later than this date. Negative values for ndays will result in a date that is as many days earlier.- See Also:
-
addMonths
Add months to a date. Returns a date that is the same day of the month, but nmonths later than this date. Negative values for nmonths will result in a date that is as many months earlier.- See Also:
-
addYears
Add years to a date. Returns a date that is nyears later than this date. Negative values for nyears will result in a date that is as many years earlier.- See Also:
-
getYear
public int getYear()Year -
getMonth
public int getMonth()Month (1-12) -
getDay
public int getDay()Day of month (1-31) -
getHour
public int getHour()Hour (0-24) -
getMinute
public int getMinute()Minute (0-59) -
getSecond
public int getSecond()Second (0-59) -
getMillisecond
public int getMillisecond()Millisecond (0-999) -
getSecondsTo
Returns the difference between to time values (in seconds). -
getMillisecondsTo
Returns the difference between to time values (in milliseconds). -
getDayOfWeek
public int getDayOfWeek()Day of week (1-7) -
getDaysTo
Returns the number of days from this date to date. -
getTimeTo
Returns the difference between two WDate values (as text). This returns a textual representation of the approximate difference between this time and other . The textual representation returns the difference as a number of seconds, minutes, hours, days, weeks, months, or years, using the coarsest unit that is more than \p minValue.- See Also:
-
before
Tests if this date is after the specified date.- Parameters:
when
- - a date.- Returns:
- true if and only if the instant represented by this Date object is strictly earlier than the instant represented by when; false otherwise.
-
after
Tests if this date is after the specified date.- Parameters:
when
- - a date.- Returns:
- true if and only if the instant represented by this Date object is strictly later than the instant represented by when; false otherwise.
-
equals
Compares two dates for equality. The result is true if and only if the argument is not null and is a Date object that represents the same point in time, to the millisecond, as this object. Thus, two Date objects are equal if and only if the getTime method returns the same long value for both. -
getDefaultFormat
Returns the default date format. -
getCurrentDate
Construct a date for the current client date. This method uses browser information to retrieve the date that is configured in the client. -
getCurrentServerDate
Construct a date for the current server date. This method returns the date as indicated by the system clock of the server. -
getShortDayName
Returns the short day name. Results (for given weekDay) are (default English):
"Mon" (1),
"Tue" (2),
"Wed" (3),
"Thu" (4),
"Fri" (5),
"Sat" (6),
"Sun" (7). The result is affected by localization using the "Wt.WDate.Mon" to "Wt.WDate.Sun" keys.- See Also:
-
getShortMonthName
Returns the short month name. Results (for given month) are (default English):
"Jan" (1),
"Feb" (2),
"Mar" (3),
"Apr" (4),
"May" (5),
"Jun" (6),
"Jul" (7),
"Aug" (8),
"Sep" (9),
"Oct" (10),
"Nov" (11),
"Dec" (12). The result is affected by localization using the "Wt.WDate.Jan" to "Wt.WDate.Dec" keys.- See Also:
-
getLongDayName
Returns the long day name. Results (for given weekDay) are (default English):
"Monday" (1),
"Tuesday" (2),
"Wednesday" (3),
"Thursday" (4),
"Friday" (5),
"Saturday" (6),
"Sunday" (7). The result is affected by localization using the "Wt.WDate.Monday" to "Wt.WDate.Sunday" keys.- See Also:
-
getLongMonthName
Returns the long month name. Results (for given month) are (default English):
"January" (1),
"February" (2),
"March" (3),
"April" (4),
"May" (5),
"June" (6),
"July" (7),
"August" (8),
"September" (9),
"October" (10),
"November" (11),
"December" (12). The result is affected by localization using the "Wt.WDate.January" to "Wt.WDate.December" keys.- See Also:
-
fromString
Parse a WString to a date using a default format. The default format is "ddd MMM d yyyy". For example, a date specified as:"Wed Aug 29 2007"
will be parsed as a date that equals a date constructed as:WDate d = new WDate(2007,8,29);
When the date could not be parsed or is not valid, null is returned.- See Also:
-
fromString
Parse a String to a date using a specified format. The format follows the same syntax as used bytoString(String format)
. When the date could not be parsed or is not valid, null is returned.- See Also:
-
toJulianDay
public int toJulianDay()Converts the date to a Julian day.- See Also:
-
toString
Format this date to a String using a default format. The default format is "ddd MMM d yyyy". -
toString
Format this date to a WString using a specified format. The format is a string interpreted bySimpleDateFormat
. -
toString
-
fromJulianDay
Converts a Julian Day jd to a WDate.- See Also:
-
getDate
Returns the internal Date object. -
hashCode
public int hashCode()Returns a hash code value for the object. -
compareTo
Compares this WDate object with the specified WDate object for order.- Specified by:
compareTo
in interfaceComparable<WDate>
-