Class LcDate

  • Direct Known Subclasses:
    ISODate

    public class LcDate
    extends Object
    The LcDate class defines objects in support of XFA date picture patterns.

    The date is internally represented as the number of days from the epoch, which is Jan 1, 1900, i.e., day 1 is Jan 1, 1900.

    Date picture patterns are used to parse and format date strings. Here are the metasymbols that form valid date picture patterns:

    D
    a one or two digit (1-31) day of month.
    DD
    a two digit (01-31) day of month.
    J
    a one, two or three digit (1-366) day of year.
    JJJ
    a three digit (001-366) day of year.
    E
    a one digit (1-7) day of week.
    EEE
    an abbreviated weekday name of the ambient locale.
    EEEE
    a full weekday name of the ambient locale.
    G
    a era name of the ambient locale.
    M
    a one or two digit (1-12) month of year.
    MM
    a two digit (01-12) month of year.
    MMM
    an abbreviated month name of the ambient locale.
    MMMM
    a full month name of the ambient locale.
    w
    a one digit (0-5) week of the month. Week 1 of a month is the earliest set of four contiguous days in that month that ends on a Saturday.
    WW
    a two digit (01-53) ISO8601 week of the year. Week 1 of a year is the week containing January 4.
    YY
    a two digit (00-99) year.
    YYYY
    a four digit (1900-2999) year.
    Here's a snippet of code illustrating the use of LcDate to reformat a date string
    
     
           import com.adobe.xfa.ut.LcDate;            // for defn of LcDate.
           ...
           LcDate today = new LcDate("", DEFAULT_CENTURY_SPLIT);
           String s = today.format("EEEE', the 'D' of 'MMMM', 'YYYY");
           System.out.println(s);
           LcDate date = new LcDate("28/2/2000", "D/M/YYYY",
                                     "", DEFAULT_CENTURY_SPLIT);
           date += 30;
           if (date.isValid())
               System.out.println(date.format(LcDate.getDateFormat(4, "pt_BR")););
      
     
    • Constructor Summary

      Constructors 
      Constructor Description
      LcDate​(int days, String locale, int centurySplit)
      Instantiates an LcDate object from the given number of days from the epoch and in the locale given.
      LcDate​(String locale, int centurySplit)
      Instantiates an LcDate object from today's date and in the locale given.
      LcDate​(String date, String pat, String locale, int centurySplit)
      Instantiates an LcDate object from the given date in the pattern given and in the locale given.
    • Field Detail

      • DATE_FMT2

        public static final String DATE_FMT2
        Alternate ISO8601/XFA date pattern string: YYYY-MM-DD.
        See Also:
        Constant Field Values
      • DEFAULT_CENTURY_SPLIT

        public static final int DEFAULT_CENTURY_SPLIT
        Default century split year: 30. This corresponds to the year 1930.
        See Also:
        Constant Field Values
      • DEFAULT_DATE_FMT

        public static final String DEFAULT_DATE_FMT
        Default LcDate pattern string for English_US locale: MMM D, YYYY.
        See Also:
        Constant Field Values
    • Constructor Detail

      • LcDate

        public LcDate​(int days,
                      String locale,
                      int centurySplit)
        Instantiates an LcDate object from the given number of days from the epoch and in the locale given. The epoch is such that day 1 corresponds to Jan 1, 1900.
        Parameters:
        days - the number of days from the epoch.
        locale - a locale string. When empty, it will default to the default locale.
        centurySplit - a century split year.
      • LcDate

        public LcDate​(String locale,
                      int centurySplit)
        Instantiates an LcDate object from today's date and in the locale given.
        Parameters:
        locale - a locale string. When empty, it will default to the default locale.
        centurySplit - a century split year.
      • LcDate

        public LcDate​(String date,
                      String pat,
                      String locale,
                      int centurySplit)
        Instantiates an LcDate object from the given date in the pattern given and in the locale given.
        Parameters:
        date - a date string.
        pat - a date pattern string used to parse the given date.
        locale - a locale string. When empty, it will default to the default locale.
        centurySplit - a century split year.
    • Method Detail

      • getDateFormat

        public static String getDateFormat​(int style,
                                           String locale)
        Gets the date pattern in the given style for the given locale.
        Parameters:
        style - a style value:
        0
        requests the locale specific default-style date pattern,
        1
        requests the locale specific short-style date pattern,
        2
        requests the locale specific medium-style date pattern,
        3
        requests the locale specific long-style date pattern, and
        4
        requests the locale specific full-style date pattern.
        Any other value requests the default-style date pattern.
        locale - a locale string. When empty, it will default to the default locale.
      • getLocalDateFormat

        public static String getLocalDateFormat​(int style,
                                                String locale)
        Gets the localized date pattern in the given style for the given locale.
        Parameters:
        style - a style value:
        0
        requests the locale specific default-style date pattern,
        1
        requests the locale specific short-style date pattern,
        2
        requests the locale specific medium-style date pattern,
        3
        requests the locale specific long-style date pattern, and
        4
        requests the locale specific full-style date pattern.
        Any other value requests the default-style date pattern.
        locale - a locale string. When empty, it will default to the default locale.
      • add

        public LcDate add​(int nDays)
        Adds the given number of days to this object.
        Parameters:
        nDays - the number of days to add.
        Returns:
        this modified object.
      • format

        public String format​(String pat)
        Formats this object according to the given a date pattern string.
        Parameters:
        pat - a date pattern string.
        Returns:
        the date string formatted according to the given pattern string, upon success, and the empty string, upon error.
      • getDays

        public int getDays()
        Gets the number of days since the epoch.
        Returns:
        the number of days, or 0 if this object is invalid.
      • getISOWeek

        public int getISOWeek()
        Gets the ISO8601 week of the year. ISO8601 defines the week as always starting with Monday being day 1 and finishing with Sunday being day 7. Therefore, the days of an ISO week can be in two different calendar years; and, because a calendar year has one or two more than 52x7=364 days, an ISO year has either 52 or 53 weeks. ISO defines the first week of a year as the week containing Jan 4!
        Returns:
        the week of the year in the range 1-53, or -1 upon an invalid date.
      • getISOYear

        public int getISOYear()
        Gets the ISO8601 year of the era.
        Returns:
        the year of the era in the range 1900-YYYY, or -1 upon an invalid date.
      • getMonth

        public int getMonth()
        Gets the month of the year.
        Returns:
        the month of the year in the range 1-12, where (1 = January), or -1 upon an invalid date.
      • getMonthDay

        public int getMonthDay()
        Gets the day of the month.
        Returns:
        the day of the month in the range 1-31, or -1 upon an invalid date.
      • getWeekDay

        public int getWeekDay()
        Gets the day of the week.
        Returns:
        the day of the week in the range of values 1-7, where (1 = Sunday), or -1 upon an invalid date.
      • getWeekMonth

        public int getWeekMonth()
        Gets the week of the month. Week 1 of a month is the earliest set of 4 contiguous days in that month, ending on the day before Sunday. Unlike week 1 of a year, week 1 of a month may be shorter than 7 days, need not start on Sunday, and will not include days of the previous month. For example, the first week of Jan 1998 is Sunday, Jan 4 through Saturday, Jan 10. Thursday, Jan 1 through Saturday, Jan 3 belongs to week 0.
        Returns:
        the week of the month in the range 0-5, or -1 upon an invalid date.
      • getYear

        public int getYear()
        Gets the year of the era.
        Returns:
        the year of the era in the range 1900-YYYY, or -1 upon an invalid date.
      • getYearDay

        public int getYearDay()
        Gets the day of the year.
        Returns:
        the day of the year in the range 1-366, or -1 upon an invalid date.
      • isValid

        public boolean isValid()
        Determines if this object is valid.
        Returns:
        boolean true if valid, and false otherwise.
      • setGMDate

        public void setGMDate()
        Sets this object to operate on Greenwich Mean date, which is the default. Any subsequent calls to the format method will result in date strings that are expressed in Greenwich Mean date.
      • setLocalDate

        public void setLocalDate()
        Sets this object to operate on local date as opposed to Greenwich Mean date. Any subsequent calls to the format method will result in date strings that are expressed in local date.
      • toString

        public String toString()
        Formats this object according to the default pattern.
        Overrides:
        toString in class Object
        Returns:
        the date string formatted according to the default pattern, upon success, and the empty string, upon error.