Package org.vaadin.miki.shared.dates
Class DatePattern
java.lang.Object
org.vaadin.miki.shared.dates.DatePattern
- All Implemented Interfaces:
Serializable
A description of pattern for dates.
- Since:
- 2020-04-23
- Author:
- miki
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines available ways of displaying month.static enumDefines available display order of dates. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charDefault separator,-.static final charShorthand for no separator (character 0). -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new pattern, with no display name.DatePattern(String string) Creates a new pattern using given display name. -
Method Summary
Modifier and TypeMethodDescriptionbooleanintReturns the base century for use withsetShortYear(boolean).intReturns boundary year to distinguish betweengetBaseCentury()and the previous one, whenisShortYear()istrue.Returns display name defined in the constructor.Returns current display order.Returns current month display mode.charReturns current separator between parts.inthashCode()booleanChecks whether or not there is a separator present.booleanChecks whether or not the years below thegetCenturyBoundaryYear()belong to century previous thangetBaseCentury(), used whenisShortYear()istrue.booleanChecks whether year number should be shortened to two digits;falseby default.booleanWhether or not short year is accepted as user input even ifisShortYear()returnsfalse.booleanChecks whether days should be prefixed with0.voidsetBaseCentury(int baseCentury) Sets the base century for parsing dates withsetShortYear(boolean).voidsetCenturyBoundaryYear(int centuryBoundaryYear) Sets new century boundary year for use withsetShortYear(boolean)andsetBaseCentury(int).voidsetDisplayOrder(DatePattern.Order displayOrder) Sets new display order.voidsetMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode) Sets month display mode from available options.voidsetPreviousCenturyBelowBoundary(boolean previousCenturyBelowBoundary) Sets whether or not years beforegetCenturyBoundaryYear()belong to the century previous thangetBaseCentury().voidsetSeparator(char separator) Sets new separator.voidsetShortYear(boolean shortYear) Sets whether or not to use only the last two digits of the year.voidsetShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted) Allows short year to be always accepted as input.voidsetZeroPrefixedDay(boolean zeroPrefixedDay) Sets whether or not days should be prefixed with0.toString()withBaseCentury(int baseCentury) ChainssetBaseCentury(int)and returns itself.withCenturyBoundaryYear(int centuryBoundaryYear) ChainssetCenturyBoundaryYear(int)and returns itself.withDisplayOrder(DatePattern.Order displayOrder) ChainssetDisplayOrder(Order)and returns itself.withMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode) ChainssetMonthDisplayMode(MonthDisplayMode)and returns itself.Identical towithSeparator(DatePattern.NO_SEPARATOR.withPreviousCenturyBelowBoundary(boolean belowBoundaryIsPreviousCentury) ChainssetPreviousCenturyBelowBoundary(boolean)and returns itself.withSeparator(char separator) ChainssetSeparator(char)and returns itself.withShortYear(boolean shortYear) ChainssetShortYear(boolean)and returns itself.withShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted) ChainssetShortYearAlwaysAccepted(boolean)and returns itself.withZeroPrefixedDay(boolean zeroPrefixedDay) ChainssetZeroPrefixedDay(boolean)and returns itself.
-
Field Details
-
NO_SEPARATOR
public static final char NO_SEPARATORShorthand for no separator (character 0).- See Also:
-
DEFAULT_SEPARATOR
public static final char DEFAULT_SEPARATORDefault separator,-.- See Also:
-
-
Constructor Details
-
DatePattern
public DatePattern()Creates a new pattern, with no display name. -
DatePattern
Creates a new pattern using given display name.- Parameters:
string- Display name. It is only used intoString().
-
-
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 thanNO_SEPARATOR.
-
setSeparator
public void setSeparator(char separator) Sets new separator. If the separator isNO_SEPARATOR(zero), zero-prefixed month and zero-prefixed day will be automatically enabled.- Parameters:
separator- Separator between parts.
-
withSeparator
ChainssetSeparator(char)and returns itself.- Parameters:
separator- Separator.- Returns:
- This.
- See Also:
-
withoutSeparator
Identical towithSeparator(DatePattern.NO_SEPARATOR.- Returns:
- This.
- See Also:
-
isZeroPrefixedDay
public boolean isZeroPrefixedDay()Checks whether days should be prefixed with0.- Returns:
- Whether or not days will be zero-prefixed (
09instead of9);trueby default.
-
setZeroPrefixedDay
public void setZeroPrefixedDay(boolean zeroPrefixedDay) Sets whether or not days should be prefixed with0. When there is no separator and this flag is turned off, the separator will be set toDEFAULT_SEPARATOR.- Parameters:
zeroPrefixedDay- Whentrueand day is one digit, zero will be added in front of that number.
-
withZeroPrefixedDay
ChainssetZeroPrefixedDay(boolean)and returns itself.- Parameters:
zeroPrefixedDay- Whether or not to zero-prefix days.- Returns:
- This.
- See Also:
-
getMonthDisplayMode
Returns current month display mode.- Returns:
- A month display mode.
DatePattern.MonthDisplayMode.ZERO_PREFIXED_NUMBERby default.
-
isShortYear
public boolean isShortYear()Checks whether year number should be shortened to two digits;falseby 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- Whentrue, year will be truncated to last two digits.- See Also:
-
withShortYear
ChainssetShortYear(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 withsetShortYear(boolean).- Returns:
- The number corresponding to the century. Defaults to
21, which means years are assumed to be in2000s. - See Also:
-
setBaseCentury
public void setBaseCentury(int baseCentury) Sets the base century for parsing dates withsetShortYear(boolean).- Parameters:
baseCentury- Base century to use (e.g. when set to19, year will be in1800s).- See Also:
-
withBaseCentury
ChainssetBaseCentury(int)and returns itself.- Parameters:
baseCentury- New value for base century.- Returns:
- This.
-
getDisplayOrder
Returns current display order.- Returns:
- A display
DatePattern.Order. Defaults toDatePattern.Order.YEAR_MONTH_DAY.
-
getCenturyBoundaryYear
public int getCenturyBoundaryYear()Returns boundary year to distinguish betweengetBaseCentury()and the previous one, whenisShortYear()istrue.- Returns:
- A year. Default is
40.
-
setCenturyBoundaryYear
public void setCenturyBoundaryYear(int centuryBoundaryYear) Sets new century boundary year for use withsetShortYear(boolean)andsetBaseCentury(int).- Parameters:
centuryBoundaryYear- A year. Please use values between0and99.
-
withCenturyBoundaryYear
ChainssetCenturyBoundaryYear(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 thegetCenturyBoundaryYear()belong to century previous thangetBaseCentury(), used whenisShortYear()istrue.- Returns:
- When
true, years belowgetCenturyBoundaryYear()are assumed to be in a century beforegetBaseCentury();falseby default.
-
setPreviousCenturyBelowBoundary
public void setPreviousCenturyBelowBoundary(boolean previousCenturyBelowBoundary) Sets whether or not years beforegetCenturyBoundaryYear()belong to the century previous thangetBaseCentury().- Parameters:
previousCenturyBelowBoundary- New value to use.
-
withPreviousCenturyBelowBoundary
ChainssetPreviousCenturyBelowBoundary(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- Whentrue, 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 ifisShortYear()returnsfalse.- Returns:
- When
true, user can input last two digits of the year and it will be properly parsed.
-
withShortYearAlwaysAccepted
ChainssetShortYearAlwaysAccepted(boolean)and returns itself.- Parameters:
shortYearAlwaysAccepted- Whether or not to always accept short year as user input.- Returns:
- This.
- See Also:
-
getDisplayName
Returns display name defined in the constructor. The display name is irrelevant inequals(Object)andhashCode().- Returns:
- Display name. May be
nullwhen no-arg constructor has been used.
-
equals
-
hashCode
public int hashCode() -
toString
-