Module tvbrowser
Package devplugin

Class Date

  • All Implemented Interfaces:
    java.lang.Comparable<Date>

    public class Date
    extends java.lang.Object
    implements java.lang.Comparable<Date>
    the date of a program. it holds year, month and day.
    Author:
    Martin Oberhauser
    • Constructor Summary

      Constructors 
      Constructor Description
      Date()
      Constructs a new Date object, initialized with the current date.
      Date​(int year, int month, int dayOfMonth)
      constructs a new date initialized with the given arguments.
      Date​(short year, byte month, byte dayOfMonth)
      constructs a new date initialized with the given arguments.
      Date​(Date d)
      Constructs a new date from a date object, ie clones it.
      Date​(java.util.Calendar cal)
      constructs a new date from a calendar object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Date addDays​(int days)  
      int compareTo​(Date otherDate)
      static Date createDateFromValue​(long value)
      create a date from a value (see getValue).
      static Date createDDMMYYYY​(java.lang.String date, java.lang.String separator)
      creates a date from a formatted string of the form DD<separator>MM<separator>YYYY.
      static Date createYYMMDD​(java.lang.String date, java.lang.String separator)
      creates a date from a formatted string of the form YY<separator>MM<separator>DD.
      static Date createYYYYMMDD​(java.lang.String date, java.lang.String separator)
      creates a date from a formatted string of the form YYYY<separator>MM<separator>DD.
      boolean equals​(java.lang.Object obj)
      java.util.Calendar getCalendar()  
      java.util.Calendar getCalendar​(java.util.Locale locale)  
      static Date getCurrentDate()
      do not call this method repeatedly!
      java.lang.String getDateString()
      return the textual representation of this date with abbreviated day of week and abbreviated month name.
      int getDayOfMonth()  
      int getDayOfWeek()
      get the day of the week for this date.
      java.lang.String getFormattedString​(java.lang.String pattern)
      Returns a string of the date according to SimpleDateFormat
      java.lang.String getFormattedString​(java.lang.String pattern, java.util.Locale locale)
      Returns a string of the date according to SimpleDateFormat
      java.lang.String getLongDateString()
      return the textual representation of this date with full day of week and full month name (neither abbreviated).
      int getMonth()  
      int getNumberOfDaysSince​(Date date)  
      java.lang.String getShortDayLongMonthString()
      returns the textual representation of this date with abbreviated day of week, but full month.
      long getValue()
      TODO is that correct?
      int getWeekOfYear()
      Returns the week number within the current year.
      int getWeekOfYear​(java.util.Locale locale)
      Returns the week number within the current year.
      int getYear()  
      int hashCode()
      A hash code implementation that returns the same code for equal Dates.
      boolean isFirstDayOfWeek()
      ATTENTION: Altered with 3.4.4 is this the day of the week, which was setup as first day of the week by the user or the default first day of the week of the current Locale ?
      boolean isFirstDayOfWeek​(java.util.Locale locale)
      is this the first day of the week?
      static Date readData​(java.io.DataInput in)
      reads an instance from a DataInput.
      static void resetLocalizer()  
      java.lang.String toString()  
      void writeData​(java.io.DataOutput out)
      Writes this instance to a DataOutput.
      • Methods inherited from class java.lang.Object

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

      • Date

        public Date()
        Constructs a new Date object, initialized with the current date.
      • Date

        public Date​(short year,
                    byte month,
                    byte dayOfMonth)
        constructs a new date initialized with the given arguments.
        Parameters:
        year - Calendar.get(Calendar.YEAR)
        month - Calendar.get(Calendar.MONTH) + 1
        dayOfMonth - Calendar.get(Calendar.DAY_OF_MONTH)
      • Date

        public Date​(int year,
                    int month,
                    int dayOfMonth)
        constructs a new date initialized with the given arguments. This is a convenience method hiding the internal storage format.
        Parameters:
        year - Calendar.get(Calendar.YEAR)
        month - Calendar.get(Calendar.MONTH) + 1
        dayOfMonth - Calendar.get(Calendar.DAY_OF_MONTH)
      • Date

        public Date​(java.util.Calendar cal)
        constructs a new date from a calendar object.
        Parameters:
        cal - the calendar to create a date from.
      • Date

        public Date​(Date d)
        Constructs a new date from a date object, ie clones it.
        Parameters:
        d - the date to clone
    • Method Detail

      • getCurrentDate

        public static Date getCurrentDate()
        do not call this method repeatedly! always cache this value because this is a very slow function!
        Returns:
        the current date
      • createDateFromValue

        public static Date createDateFromValue​(long value)
        create a date from a value (see getValue).
        Parameters:
        value - the value to create a date from
        Returns:
        the date
      • createYYYYMMDD

        public static Date createYYYYMMDD​(java.lang.String date,
                                          java.lang.String separator)
        creates a date from a formatted string of the form YYYY<separator>MM<separator>DD.
        Parameters:
        date - the string to parse.
        separator - the separator separating the year, month and day sections of the string
        Returns:
        null if the parsing failed
      • createDDMMYYYY

        public static Date createDDMMYYYY​(java.lang.String date,
                                          java.lang.String separator)
        creates a date from a formatted string of the form DD<separator>MM<separator>YYYY.
        Parameters:
        date - the string to parse.
        separator - the separator separating the year, month and day sections of the string
        Returns:
        null if the parsing failed
      • createYYMMDD

        public static Date createYYMMDD​(java.lang.String date,
                                        java.lang.String separator)
        creates a date from a formatted string of the form YY<separator>MM<separator>DD. this method assumes that the date is in the 21st century, ie 20XX.
        Parameters:
        date - the string to parse.
        separator - the separator separating the year, month and day sections of the string
        Returns:
        null if the parsing failed
      • getNumberOfDaysSince

        public int getNumberOfDaysSince​(Date date)
        Parameters:
        date - The date to check for days since.
        Returns:
        The days since the given date.
        Since:
        0.9.7.4 This method may not return the exactly number of days since the calculation is confounded by daylight savings time switchovers... Around midnight the result may not be correct.
      • getYear

        public int getYear()
        Returns:
        the year (4 digits)
      • getMonth

        public int getMonth()
        Returns:
        the month (2 digits, starting with 1 for january)
      • getDayOfMonth

        public int getDayOfMonth()
        Returns:
        the day of month (2 digits, starting with 1)
      • getWeekOfYear

        public int getWeekOfYear()
        Returns the week number within the current year. Should not be used since value depends on default locale and thus changes from machine to machine. Since 3.0 better use getWeekOfYear(Locale locale) instead.
        Returns:
        The week number.
        Since:
        2.5.1
      • getWeekOfYear

        public int getWeekOfYear​(java.util.Locale locale)
        Returns the week number within the current year.
        Parameters:
        locale - The locale to be used
        Returns:
        The week number.
        Since:
        3.0
      • hashCode

        public int hashCode()
        A hash code implementation that returns the same code for equal Dates.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • getDateString

        public java.lang.String getDateString()
        return the textual representation of this date with abbreviated day of week and abbreviated month name. TODO the description does not fit the code. change code or change description?
        Returns:
        date string
      • getFormattedString

        public java.lang.String getFormattedString​(java.lang.String pattern)
        Returns a string of the date according to SimpleDateFormat
        Parameters:
        pattern - the pattern describing the date and time format
        Returns:
        the formatted date string.
        Since:
        3.0.2
      • getFormattedString

        public java.lang.String getFormattedString​(java.lang.String pattern,
                                                   java.util.Locale locale)
        Returns a string of the date according to SimpleDateFormat
        Parameters:
        pattern - the pattern describing the date and time format
        locale - the locale whose date format symbols should be used
        Returns:
        the formatted date string.
        Since:
        3.0.2
      • getLongDateString

        public java.lang.String getLongDateString()
        return the textual representation of this date with full day of week and full month name (neither abbreviated).
        Returns:
        date string
      • getShortDayLongMonthString

        public java.lang.String getShortDayLongMonthString()
        returns the textual representation of this date with abbreviated day of week, but full month.
        Returns:
        date as string
      • getValue

        public long getValue()
        TODO is that correct? its like hashCode.
        Returns:
        the value as in hashCode
      • getCalendar

        public java.util.Calendar getCalendar()
        Returns:
        the corresponding calendar for this date
      • getCalendar

        public java.util.Calendar getCalendar​(java.util.Locale locale)
        Parameters:
        locale - The locale to use for the calendar.
        Returns:
        the corresponding calendar for this date
        Since:
        3.0
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • addDays

        public Date addDays​(int days)
        Parameters:
        days - the days to add
        Returns:
        a new created date object
      • compareTo

        public int compareTo​(Date otherDate)
        Specified by:
        compareTo in interface java.lang.Comparable<Date>
        See Also:
        Comparable.compareTo(java.lang.Object)
      • getDayOfWeek

        public int getDayOfWeek()
        get the day of the week for this date.
        Returns:
        day of week, as Calendar.MONDAY and so on
        Since:
        2.6
      • isFirstDayOfWeek

        public boolean isFirstDayOfWeek()
        ATTENTION: Altered with 3.4.4 is this the day of the week, which was setup as first day of the week by the user or the default first day of the week of the current Locale ?
        Returns:
        true, if this is the first day of the week.
        Since:
        2.6
      • isFirstDayOfWeek

        public boolean isFirstDayOfWeek​(java.util.Locale locale)
        is this the first day of the week?
        Parameters:
        locale - The locale to be used
        Returns:
        true, if this is the first day of the week
        Since:
        3.0
      • writeData

        public void writeData​(java.io.DataOutput out)
                       throws java.io.IOException
        Writes this instance to a DataOutput.
        Parameters:
        out - the output to write to
        Throws:
        java.io.IOException - if something went wrong
      • readData

        public static Date readData​(java.io.DataInput in)
                             throws java.io.IOException
        reads an instance from a DataInput.
        Parameters:
        in - the input to read from
        Returns:
        the new created instance
        Throws:
        java.io.IOException - if somethin went wrong
      • resetLocalizer

        public static void resetLocalizer()