Class DatePattern

java.lang.Object
org.vaadin.miki.shared.dates.DatePattern
All Implemented Interfaces:
Serializable

public class DatePattern extends Object implements Serializable
A description of pattern for dates.
Since:
2020-04-23
Author:
miki
See Also:
  • Field Details

    • NO_SEPARATOR

      public static final char NO_SEPARATOR
      Shorthand for no separator (character 0).
      See Also:
    • DEFAULT_SEPARATOR

      public static final char DEFAULT_SEPARATOR
      Default separator, -.
      See Also:
  • Constructor Details

    • DatePattern

      public DatePattern()
      Creates a new pattern, with no display name.
    • DatePattern

      public DatePattern(String string)
      Creates a new pattern using given display name.
      Parameters:
      string - Display name. It is only used in toString().
  • Method Details

    • getSeparator

      public char getSeparator()
      Returns current separator between parts.
      Returns:
      Separator.
    • hasSeparator

      public boolean hasSeparator()
      Checks whether or not there is a separator present.
      Returns:
      Whether or not getSeparator() returns something else than NO_SEPARATOR.
    • setSeparator

      public void setSeparator(char separator)
      Sets new separator. If the separator is NO_SEPARATOR (zero), zero-prefixed month and zero-prefixed day will be automatically enabled.
      Parameters:
      separator - Separator between parts.
    • withSeparator

      public DatePattern withSeparator(char separator)
      Chains setSeparator(char) and returns itself.
      Parameters:
      separator - Separator.
      Returns:
      This.
      See Also:
    • withoutSeparator

      public DatePattern withoutSeparator()
      Identical to withSeparator(DatePattern.NO_SEPARATOR.
      Returns:
      This.
      See Also:
    • isZeroPrefixedDay

      public boolean isZeroPrefixedDay()
      Checks whether days should be prefixed with 0.
      Returns:
      Whether or not days will be zero-prefixed (09 instead of 9); true by default.
    • setZeroPrefixedDay

      public void setZeroPrefixedDay(boolean zeroPrefixedDay)
      Sets whether or not days should be prefixed with 0. When there is no separator and this flag is turned off, the separator will be set to DEFAULT_SEPARATOR.
      Parameters:
      zeroPrefixedDay - When true and day is one digit, zero will be added in front of that number.
    • withZeroPrefixedDay

      public DatePattern withZeroPrefixedDay(boolean zeroPrefixedDay)
      Chains setZeroPrefixedDay(boolean) and returns itself.
      Parameters:
      zeroPrefixedDay - Whether or not to zero-prefix days.
      Returns:
      This.
      See Also:
    • setMonthDisplayMode

      public void setMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode)
      Sets month display mode from available options.
      Parameters:
      monthDisplayMode - Month display mode.
    • getMonthDisplayMode

      public DatePattern.MonthDisplayMode getMonthDisplayMode()
      Returns current month display mode.
      Returns:
      A month display mode. DatePattern.MonthDisplayMode.ZERO_PREFIXED_NUMBER by default.
    • withMonthDisplayMode

      public DatePattern withMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode)
      Chains setMonthDisplayMode(MonthDisplayMode) and returns itself.
      Parameters:
      monthDisplayMode - Month display mode.
      Returns:
      This
      See Also:
    • isShortYear

      public boolean isShortYear()
      Checks whether year number should be shortened to two digits; false by default.
      Returns:
      When true, only the last two digits of the year will be displayed.
    • setShortYear

      public void setShortYear(boolean shortYear)
      Sets whether or not to use only the last two digits of the year.
      Parameters:
      shortYear - When true, year will be truncated to last two digits.
      See Also:
    • withShortYear

      public DatePattern withShortYear(boolean shortYear)
      Chains setShortYear(boolean) and returns itself.
      Parameters:
      shortYear - Whether or not to use shortened year.
      Returns:
      This.
    • getBaseCentury

      public int getBaseCentury()
      Returns the base century for use with setShortYear(boolean).
      Returns:
      The number corresponding to the century. Defaults to 21, which means years are assumed to be in 2000s.
      See Also:
    • setBaseCentury

      public void setBaseCentury(int baseCentury)
      Sets the base century for parsing dates with setShortYear(boolean).
      Parameters:
      baseCentury - Base century to use (e.g. when set to 19, year will be in 1800s).
      See Also:
    • withBaseCentury

      public DatePattern withBaseCentury(int baseCentury)
      Chains setBaseCentury(int) and returns itself.
      Parameters:
      baseCentury - New value for base century.
      Returns:
      This.
    • getDisplayOrder

      public DatePattern.Order getDisplayOrder()
      Returns current display order.
      Returns:
      A display DatePattern.Order. Defaults to DatePattern.Order.YEAR_MONTH_DAY.
    • setDisplayOrder

      public void setDisplayOrder(DatePattern.Order displayOrder)
      Sets new display order.
      Parameters:
      displayOrder - A display DatePattern.Order.
    • withDisplayOrder

      public DatePattern withDisplayOrder(DatePattern.Order displayOrder)
      Chains setDisplayOrder(Order) and returns itself.
      Parameters:
      displayOrder - Display DatePattern.Order to use.
      Returns:
      This.
    • getCenturyBoundaryYear

      public int getCenturyBoundaryYear()
      Returns boundary year to distinguish between getBaseCentury() and the previous one, when isShortYear() is true.
      Returns:
      A year. Default is 40.
    • setCenturyBoundaryYear

      public void setCenturyBoundaryYear(int centuryBoundaryYear)
      Sets new century boundary year for use with setShortYear(boolean) and setBaseCentury(int).
      Parameters:
      centuryBoundaryYear - A year. Please use values between 0 and 99.
    • withCenturyBoundaryYear

      public DatePattern withCenturyBoundaryYear(int centuryBoundaryYear)
      Chains setCenturyBoundaryYear(int) and returns itself.
      Parameters:
      centuryBoundaryYear - New century boundary year.
      Returns:
      This.
      See Also:
    • isPreviousCenturyBelowBoundary

      public boolean isPreviousCenturyBelowBoundary()
      Checks whether or not the years below the getCenturyBoundaryYear() belong to century previous than getBaseCentury(), used when isShortYear() is true.
      Returns:
      When true, years below getCenturyBoundaryYear() are assumed to be in a century before getBaseCentury(); false by default.
    • setPreviousCenturyBelowBoundary

      public void setPreviousCenturyBelowBoundary(boolean previousCenturyBelowBoundary)
      Sets whether or not years before getCenturyBoundaryYear() belong to the century previous than getBaseCentury().
      Parameters:
      previousCenturyBelowBoundary - New value to use.
    • withPreviousCenturyBelowBoundary

      public DatePattern withPreviousCenturyBelowBoundary(boolean belowBoundaryIsPreviousCentury)
      Chains setPreviousCenturyBelowBoundary(boolean) and returns itself.
      Parameters:
      belowBoundaryIsPreviousCentury - Value to use.
      Returns:
      This.
      See Also:
    • setShortYearAlwaysAccepted

      public void setShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted)
      Allows short year to be always accepted as input.
      Parameters:
      shortYearAlwaysAccepted - When true, short year can always be entered and will be parsed properly and displayed as full year.
      See Also:
    • isShortYearAlwaysAccepted

      public boolean isShortYearAlwaysAccepted()
      Whether or not short year is accepted as user input even if isShortYear() returns false.
      Returns:
      When true, user can input last two digits of the year and it will be properly parsed.
    • withShortYearAlwaysAccepted

      public DatePattern withShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted)
      Chains setShortYearAlwaysAccepted(boolean) and returns itself.
      Parameters:
      shortYearAlwaysAccepted - Whether or not to always accept short year as user input.
      Returns:
      This.
      See Also:
    • getDisplayName

      public String getDisplayName()
      Returns display name defined in the constructor. The display name is irrelevant in equals(Object) and hashCode().
      Returns:
      Display name. May be null when no-arg constructor has been used.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object