public class DatePattern extends Object implements Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
DatePattern.MonthDisplayMode
Defines available ways of displaying month.
|
static class |
DatePattern.Order
Defines available display order of dates.
|
| Modifier and Type | Field and Description |
|---|---|
static char |
DEFAULT_SEPARATOR
Default separator,
-. |
static char |
NO_SEPARATOR
Shorthand for no separator (character 0).
|
| Constructor and Description |
|---|
DatePattern()
Creates a new pattern, with no display name.
|
DatePattern(String string)
Creates a new pattern using given display name.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
int |
getBaseCentury()
Returns the base century for use with
setShortYear(boolean). |
int |
getCenturyBoundaryYear()
Returns boundary year to distinguish between
getBaseCentury() and the previous one, when isShortYear() is true. |
String |
getDisplayName()
Returns display name defined in the constructor.
|
DatePattern.Order |
getDisplayOrder()
Returns current display order.
|
DatePattern.MonthDisplayMode |
getMonthDisplayMode()
Returns current month display mode.
|
char |
getSeparator()
Returns current separator between parts.
|
int |
hashCode() |
boolean |
hasSeparator()
Checks whether or not there is a separator present.
|
boolean |
isPreviousCenturyBelowBoundary()
Checks whether or not the years below the
getCenturyBoundaryYear() belong to century previous than getBaseCentury(), used when isShortYear() is true. |
boolean |
isShortYear()
Checks whether year number should be shortened to two digits;
false by default. |
boolean |
isShortYearAlwaysAccepted()
Whether or not short year is accepted as user input even if
isShortYear() returns false. |
boolean |
isZeroPrefixedDay()
Checks whether days should be prefixed with
0. |
void |
setBaseCentury(int baseCentury)
Sets the base century for parsing dates with
setShortYear(boolean). |
void |
setCenturyBoundaryYear(int centuryBoundaryYear)
Sets new century boundary year for use with
setShortYear(boolean) and setBaseCentury(int). |
void |
setDisplayOrder(DatePattern.Order displayOrder)
Sets new display order.
|
void |
setMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode)
Sets month display mode from available options.
|
void |
setPreviousCenturyBelowBoundary(boolean previousCenturyBelowBoundary)
Sets whether or not years before
getCenturyBoundaryYear() belong to the century previous than getBaseCentury(). |
void |
setSeparator(char separator)
Sets new separator.
|
void |
setShortYear(boolean shortYear)
Sets whether or not to use only the last two digits of the year.
|
void |
setShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted)
Allows short year to be always accepted as input.
|
void |
setZeroPrefixedDay(boolean zeroPrefixedDay)
Sets whether or not days should be prefixed with
0. |
String |
toString() |
DatePattern |
withBaseCentury(int baseCentury)
Chains
setBaseCentury(int) and returns itself. |
DatePattern |
withCenturyBoundaryYear(int centuryBoundaryYear)
Chains
setCenturyBoundaryYear(int) and returns itself. |
DatePattern |
withDisplayOrder(DatePattern.Order displayOrder)
Chains
setDisplayOrder(Order) and returns itself. |
DatePattern |
withMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode)
Chains
setMonthDisplayMode(MonthDisplayMode) and returns itself. |
DatePattern |
withoutSeparator()
Identical to
withSeparator(DatePattern.NO_SEPARATOR. |
DatePattern |
withPreviousCenturyBelowBoundary(boolean belowBoundaryIsPreviousCentury)
Chains
setPreviousCenturyBelowBoundary(boolean) and returns itself. |
DatePattern |
withSeparator(char separator)
Chains
setSeparator(char) and returns itself. |
DatePattern |
withShortYear(boolean shortYear)
Chains
setShortYear(boolean) and returns itself. |
DatePattern |
withShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted)
Chains
setShortYearAlwaysAccepted(boolean) and returns itself. |
DatePattern |
withZeroPrefixedDay(boolean zeroPrefixedDay)
Chains
setZeroPrefixedDay(boolean) and returns itself. |
public static final char NO_SEPARATOR
public static final char DEFAULT_SEPARATOR
-.public DatePattern()
public DatePattern(String string)
string - Display name. It is only used in toString().public char getSeparator()
public boolean hasSeparator()
getSeparator() returns something else than NO_SEPARATOR.public void setSeparator(char separator)
NO_SEPARATOR (zero), zero-prefixed month and zero-prefixed day will be automatically enabled.separator - Separator between parts.public DatePattern withSeparator(char separator)
setSeparator(char) and returns itself.separator - Separator.setSeparator(char),
withoutSeparator()public DatePattern withoutSeparator()
withSeparator(DatePattern.NO_SEPARATOR.withSeparator(char),
setSeparator(char)public boolean isZeroPrefixedDay()
0.09 instead of 9); true by default.public void setZeroPrefixedDay(boolean zeroPrefixedDay)
0.
When there is no separator and this flag is turned off, the separator will be set to DEFAULT_SEPARATOR.zeroPrefixedDay - When true and day is one digit, zero will be added in front of that number.public DatePattern withZeroPrefixedDay(boolean zeroPrefixedDay)
setZeroPrefixedDay(boolean) and returns itself.zeroPrefixedDay - Whether or not to zero-prefix days.setZeroPrefixedDay(boolean)public void setMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode)
monthDisplayMode - Month display mode.public DatePattern.MonthDisplayMode getMonthDisplayMode()
DatePattern.MonthDisplayMode.ZERO_PREFIXED_NUMBER by default.public DatePattern withMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode)
setMonthDisplayMode(MonthDisplayMode) and returns itself.monthDisplayMode - Month display mode.setMonthDisplayMode(MonthDisplayMode)public boolean isShortYear()
false by default.true, only the last two digits of the year will be displayed.public void setShortYear(boolean shortYear)
shortYear - When true, year will be truncated to last two digits.setBaseCentury(int),
setCenturyBoundaryYear(int),
setPreviousCenturyBelowBoundary(boolean)public DatePattern withShortYear(boolean shortYear)
setShortYear(boolean) and returns itself.shortYear - Whether or not to use shortened year.public int getBaseCentury()
setShortYear(boolean).21, which means years are assumed to be in 2000s.isShortYear()public void setBaseCentury(int baseCentury)
setShortYear(boolean).baseCentury - Base century to use (e.g. when set to 19, year will be in 1800s).setShortYear(boolean)public DatePattern withBaseCentury(int baseCentury)
setBaseCentury(int) and returns itself.baseCentury - New value for base century.public DatePattern.Order getDisplayOrder()
DatePattern.Order. Defaults to DatePattern.Order.YEAR_MONTH_DAY.public void setDisplayOrder(DatePattern.Order displayOrder)
displayOrder - A display DatePattern.Order.public DatePattern withDisplayOrder(DatePattern.Order displayOrder)
setDisplayOrder(Order) and returns itself.displayOrder - Display DatePattern.Order to use.public int getCenturyBoundaryYear()
getBaseCentury() and the previous one, when isShortYear() is true.40.public void setCenturyBoundaryYear(int centuryBoundaryYear)
setShortYear(boolean) and setBaseCentury(int).centuryBoundaryYear - A year. Please use values between 0 and 99.public DatePattern withCenturyBoundaryYear(int centuryBoundaryYear)
setCenturyBoundaryYear(int) and returns itself.centuryBoundaryYear - New century boundary year.setCenturyBoundaryYear(int)public boolean isPreviousCenturyBelowBoundary()
getCenturyBoundaryYear() belong to century previous than getBaseCentury(), used when isShortYear() is true.true, years below getCenturyBoundaryYear() are assumed to be in a century before getBaseCentury(); false by default.public void setPreviousCenturyBelowBoundary(boolean previousCenturyBelowBoundary)
getCenturyBoundaryYear() belong to the century previous than getBaseCentury().previousCenturyBelowBoundary - New value to use.public DatePattern withPreviousCenturyBelowBoundary(boolean belowBoundaryIsPreviousCentury)
setPreviousCenturyBelowBoundary(boolean) and returns itself.belowBoundaryIsPreviousCentury - Value to use.setPreviousCenturyBelowBoundary(boolean)public void setShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted)
shortYearAlwaysAccepted - When true, short year can always be entered and will be parsed properly and displayed as full year.setBaseCentury(int),
setCenturyBoundaryYear(int),
setPreviousCenturyBelowBoundary(boolean),
setShortYear(boolean)public boolean isShortYearAlwaysAccepted()
isShortYear() returns false.true, user can input last two digits of the year and it will be properly parsed.public DatePattern withShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted)
setShortYearAlwaysAccepted(boolean) and returns itself.shortYearAlwaysAccepted - Whether or not to always accept short year as user input.setShortYearAlwaysAccepted(boolean)public String getDisplayName()
equals(Object) and hashCode().null when no-arg constructor has been used.Copyright © 2023 Miki. All rights reserved.