Package eu.webtoolkit.jwt
Class WDate
- java.lang.Object
-
- eu.webtoolkit.jwt.WDate
-
- All Implemented Interfaces:
java.lang.Comparable<WDate>
public class WDate extends java.lang.Object implements java.lang.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 theWDate(int, int, int)constructor, or thesetDate(int year, int month, int day)method). When attempting to specify an invalid date (with an impossible combination of year/month/date) anIllegalArgumentExceptionwill 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
Constructors Constructor Description 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(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.WDate(java.util.Date date)Specify a date by a Date object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description WDateaddDays(int ndays)Add days to a date.WDateaddMilliseconds(int nMilliseconds)Adds milliseconds.WDateaddMonths(int nmonths)Add months to a date.WDateaddSeconds(int nSeconds)Adds seconds.WDateaddYears(int nyears)Add years to a date.booleanafter(WDate when)Tests if this date is after the specified date.booleanbefore(WDate when)Tests if this date is after the specified date.intcompareTo(WDate o)Compares this WDate object with the specified WDate object for order.booleanequals(java.lang.Object other)Compares two dates for equality.static WDatefromJulianDay(int jd)Converts a Julian Day jd to a WDate.static WDatefromString(java.lang.String text)Parse a WString to a date using a default format.static WDatefromString(java.lang.String text, java.lang.String format)Parse a String to a date using a specified format.static WDategetCurrentDate()Construct a date for the current client date.static WDategetCurrentServerDate()Construct a date for the current server date.java.util.DategetDate()Returns the internal Date object.intgetDay()Day of month (1-31)intgetDayOfWeek()Day of week (1-7)intgetDaysTo(WDate date)Returns the number of days from this date to date.static java.lang.StringgetDefaultFormat()Returns the default date format.intgetHour()Hour (0-24)static WStringgetLongDayName(int weekday)Returns the long day name.static WStringgetLongMonthName(int month)Returns the long month name.intgetMillisecond()Millisecond (0-999)longgetMillisecondsTo(WDate d)Returns the difference between to time values (in milliseconds).intgetMinute()Minute (0-59)intgetMonth()Month (1-12)intgetSecond()Second (0-59)intgetSecondsTo(WDate d)Returns the difference between to time values (in seconds).static WStringgetShortDayName(int weekday)Returns the short day name.static WStringgetShortMonthName(int month)Returns the short month name.WTimegetTime()Gets this date's timejava.lang.StringgetTimeTo(WDate other, int minValue)Returns the difference between two WDate values (as text).intgetYear()YearinthashCode()Returns a hash code value for the object.voidsetDate(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.voidsetDate(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).voidsetDate(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.voidsetTime(int hour, int minute)Set this date's time by hour (0-23) and minute (0-59).voidsetTime(int hour, int minute, int second)Set this date's time by hour (0-23), minute (0-59) and second (0 - 59).voidsetTime(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).voidsetTime(WTime time)Sets this date's time by WTime When the new date is invalid, an IllegalArgumentException is thrown.static voidsetTimezone(java.util.TimeZone timeZone)Sets default timezone Ifnull, then the default (local) timezone will be used.inttoJulianDay()Converts the date to a Julian day.java.lang.StringtoString()Format this date to a String using a default format.java.lang.StringtoString(java.lang.String format)Format this date to a WString using a specified format.java.lang.StringtoString(java.lang.String format, boolean localized)
-
-
-
Constructor Detail
-
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.- See Also:
setDate(int year, int month, int day),getYear(),getMonth(),getDay()
-
WDate
public WDate(java.util.Date date)
Specify a date by a Date object.
-
-
Method Detail
-
setTimezone
public static void setTimezone(java.util.TimeZone timeZone)
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(int, int, int, int, int, int)
-
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
public void setTime(WTime time)
Sets this date's time by WTime When the new date is invalid, an IllegalArgumentException is thrown.
-
getTime
public WTime getTime()
Gets this date's time- Returns:
- WTime object
-
addSeconds
public WDate addSeconds(int nSeconds)
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
public WDate addMilliseconds(int nMilliseconds)
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
public WDate addDays(int ndays)
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(int),addYears(int)
-
addMonths
public WDate addMonths(int nmonths)
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:
addDays(int),addYears(int)
-
addYears
public WDate addYears(int nyears)
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:
addDays(int),addMonths(int)
-
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
public int getSecondsTo(WDate d)
Returns the difference between to time values (in seconds).
-
getMillisecondsTo
public long getMillisecondsTo(WDate d)
Returns the difference between to time values (in milliseconds).
-
getDayOfWeek
public int getDayOfWeek()
Day of week (1-7)
-
getDaysTo
public int getDaysTo(WDate date)
Returns the number of days from this date to date.
-
getTimeTo
public java.lang.String getTimeTo(WDate other, int minValue)
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:
getDaysTo(WDate),getSecondsTo(WDate)
-
before
public boolean before(WDate when)
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
public boolean after(WDate when)
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
public boolean equals(java.lang.Object other)
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.- Overrides:
equalsin classjava.lang.Object
-
getDefaultFormat
public static java.lang.String getDefaultFormat()
Returns the default date format.
-
getCurrentDate
public static WDate 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
public static WDate getCurrentServerDate()
Construct a date for the current server date. This method returns the date as indicated by the system clock of the server.
-
getShortDayName
public static WString getShortDayName(int weekday)
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:
getLongDayName(int)
-
getShortMonthName
public static WString getShortMonthName(int month)
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:
getLongMonthName(int)
-
getLongDayName
public static WString getLongDayName(int weekday)
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:
getShortDayName(int)
-
getLongMonthName
public static WString getLongMonthName(int month)
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:
getShortDayName(int)
-
fromString
public static WDate fromString(java.lang.String text)
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(String, String)
-
fromString
public static WDate fromString(java.lang.String text, java.lang.String format)
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:
toString(String format)
-
toJulianDay
public int toJulianDay()
Converts the date to a Julian day.- See Also:
fromJulianDay(int)
-
toString
public java.lang.String toString()
Format this date to a String using a default format. The default format is "ddd MMM d yyyy".- Overrides:
toStringin classjava.lang.Object- See Also:
toString(String format),fromString(String)
-
toString
public java.lang.String toString(java.lang.String format)
Format this date to a WString using a specified format. The format is a string interpreted bySimpleDateFormat.
-
toString
public java.lang.String toString(java.lang.String format, boolean localized)
-
fromJulianDay
public static WDate fromJulianDay(int jd)
Converts a Julian Day jd to a WDate.- See Also:
toJulianDay()
-
getDate
public java.util.Date getDate()
Returns the internal Date object.
-
hashCode
public int hashCode()
Returns a hash code value for the object.- Overrides:
hashCodein classjava.lang.Object
-
-