Class WDate

java.lang.Object
eu.webtoolkit.jwt.WDate
All Implemented Interfaces:
Comparable<WDate>

public class WDate extends Object implements 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

    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(Date date)
    Specify a date by a Date object.
  • Method Summary

    Modifier and Type
    Method
    Description
    addDays(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
    after(WDate when)
    Tests if this date is after the specified date.
    boolean
    before(WDate when)
    Tests if this date is after the specified date.
    int
    Compares this WDate object with the specified WDate object for order.
    boolean
    equals(Object other)
    Compares two dates for equality.
    static WDate
    fromJulianDay(int jd)
    Converts a Julian Day jd to a WDate.
    static WDate
    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.
    Returns the internal Date object.
    int
    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
    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
    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.
    Gets this date's time
    getTimeTo(WDate other, int minValue)
    Returns the difference between two WDate values (as text).
    int
    Year
    int
    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
    setTime(WTime time)
    Sets this date's time by WTime When the new date is invalid, an IllegalArgumentException is thrown.
    static void
    Sets default timezone If null, then the default (local) timezone will be used.
    int
    Converts the date to a Julian day.
    Format this date to a String using a default format.
    toString(String format)
    Format this date to a WString using a specified format.
    toString(String format, boolean localized)
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • setTimezone

      public static void setTimezone(TimeZone timeZone)
      Sets default timezone If null, 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 is null.
    • 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.
      See Also:
    • 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.
      See Also:
    • 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

      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:
    • 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:
    • 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 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:
    • 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(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:
      equals in class Object
    • getDefaultFormat

      public static 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:
    • 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:
    • 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:
    • 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:
    • fromString

      public static WDate fromString(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

      public static WDate fromString(String text, String format)
      Parse a String to a date using a specified format. The format follows the same syntax as used by toString(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

      public String toString()
      Format this date to a String using a default format. The default format is "ddd MMM d yyyy".
      Overrides:
      toString in class Object
      See Also:
    • toString

      public String toString(String format)
      Format this date to a WString using a specified format. The format is a string interpreted by SimpleDateFormat.
    • toString

      public String toString(String format, boolean localized)
    • fromJulianDay

      public static WDate fromJulianDay(int jd)
      Converts a Julian Day jd to a WDate.
      See Also:
    • getDate

      public Date getDate()
      Returns the internal Date object.
    • hashCode

      public int hashCode()
      Returns a hash code value for the object.
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(WDate o)
      Compares this WDate object with the specified WDate object for order.
      Specified by:
      compareTo in interface Comparable<WDate>