Package org.vaadin.miki.shared.dates
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDatePattern.MonthDisplayModeDefines available ways of displaying month.static classDatePattern.OrderDefines available display order of dates.
-
Field Summary
Fields Modifier and Type Field Description static charDEFAULT_SEPARATORDefault separator,-.static charNO_SEPARATORShorthand for no separator (character 0).
-
Constructor Summary
Constructors Constructor Description DatePattern()Creates a new pattern, with no display name.DatePattern(String string)Creates a new pattern using given display name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)intgetBaseCentury()Returns the base century for use withsetShortYear(boolean).intgetCenturyBoundaryYear()Returns boundary year to distinguish betweengetBaseCentury()and the previous one, whenisShortYear()istrue.StringgetDisplayName()Returns display name defined in the constructor.DatePattern.OrdergetDisplayOrder()Returns current display order.DatePattern.MonthDisplayModegetMonthDisplayMode()Returns current month display mode.chargetSeparator()Returns current separator between parts.inthashCode()booleanhasSeparator()Checks whether or not there is a separator present.booleanisPreviousCenturyBelowBoundary()Checks whether or not the years below thegetCenturyBoundaryYear()belong to century previous thangetBaseCentury(), used whenisShortYear()istrue.booleanisShortYear()Checks whether year number should be shortened to two digits;falseby default.booleanisShortYearAlwaysAccepted()Whether or not short year is accepted as user input even ifisShortYear()returnsfalse.booleanisZeroPrefixedDay()Checks 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.StringtoString()DatePatternwithBaseCentury(int baseCentury)ChainssetBaseCentury(int)and returns itself.DatePatternwithCenturyBoundaryYear(int centuryBoundaryYear)ChainssetCenturyBoundaryYear(int)and returns itself.DatePatternwithDisplayOrder(DatePattern.Order displayOrder)ChainssetDisplayOrder(Order)and returns itself.DatePatternwithMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode)ChainssetMonthDisplayMode(MonthDisplayMode)and returns itself.DatePatternwithoutSeparator()Identical towithSeparator(DatePattern.NO_SEPARATOR.DatePatternwithPreviousCenturyBelowBoundary(boolean belowBoundaryIsPreviousCentury)ChainssetPreviousCenturyBelowBoundary(boolean)and returns itself.DatePatternwithSeparator(char separator)ChainssetSeparator(char)and returns itself.DatePatternwithShortYear(boolean shortYear)ChainssetShortYear(boolean)and returns itself.DatePatternwithShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted)ChainssetShortYearAlwaysAccepted(boolean)and returns itself.DatePatternwithZeroPrefixedDay(boolean zeroPrefixedDay)ChainssetZeroPrefixedDay(boolean)and returns itself.
-
-
-
Field Detail
-
NO_SEPARATOR
public static final char NO_SEPARATOR
Shorthand for no separator (character 0).- See Also:
- Constant Field Values
-
DEFAULT_SEPARATOR
public static final char DEFAULT_SEPARATOR
Default separator,-.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 intoString().
-
-
Method Detail
-
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
public DatePattern withSeparator(char separator)
ChainssetSeparator(char)and returns itself.- Parameters:
separator- Separator.- Returns:
- This.
- See Also:
setSeparator(char),withoutSeparator()
-
withoutSeparator
public DatePattern withoutSeparator()
Identical towithSeparator(DatePattern.NO_SEPARATOR.- Returns:
- This.
- See Also:
withSeparator(char),setSeparator(char)
-
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
public DatePattern withZeroPrefixedDay(boolean zeroPrefixedDay)
ChainssetZeroPrefixedDay(boolean)and returns itself.- Parameters:
zeroPrefixedDay- Whether or not to zero-prefix days.- Returns:
- This.
- See Also:
setZeroPrefixedDay(boolean)
-
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_NUMBERby default.
-
withMonthDisplayMode
public DatePattern withMonthDisplayMode(DatePattern.MonthDisplayMode monthDisplayMode)
ChainssetMonthDisplayMode(MonthDisplayMode)and returns itself.- Parameters:
monthDisplayMode- Month display mode.- Returns:
- This
- See Also:
setMonthDisplayMode(MonthDisplayMode)
-
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:
setBaseCentury(int),setCenturyBoundaryYear(int),setPreviousCenturyBelowBoundary(boolean)
-
withShortYear
public DatePattern withShortYear(boolean shortYear)
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:
isShortYear()
-
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:
setShortYear(boolean)
-
withBaseCentury
public DatePattern withBaseCentury(int baseCentury)
ChainssetBaseCentury(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 toDatePattern.Order.YEAR_MONTH_DAY.
-
setDisplayOrder
public void setDisplayOrder(DatePattern.Order displayOrder)
Sets new display order.- Parameters:
displayOrder- A displayDatePattern.Order.
-
withDisplayOrder
public DatePattern withDisplayOrder(DatePattern.Order displayOrder)
ChainssetDisplayOrder(Order)and returns itself.- Parameters:
displayOrder- DisplayDatePattern.Orderto use.- Returns:
- This.
-
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
public DatePattern withCenturyBoundaryYear(int centuryBoundaryYear)
ChainssetCenturyBoundaryYear(int)and returns itself.- Parameters:
centuryBoundaryYear- New century boundary year.- Returns:
- This.
- See Also:
setCenturyBoundaryYear(int)
-
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
public DatePattern withPreviousCenturyBelowBoundary(boolean belowBoundaryIsPreviousCentury)
ChainssetPreviousCenturyBelowBoundary(boolean)and returns itself.- Parameters:
belowBoundaryIsPreviousCentury- Value to use.- Returns:
- This.
- See Also:
setPreviousCenturyBelowBoundary(boolean)
-
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:
setBaseCentury(int),setCenturyBoundaryYear(int),setPreviousCenturyBelowBoundary(boolean),setShortYear(boolean)
-
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
public DatePattern withShortYearAlwaysAccepted(boolean shortYearAlwaysAccepted)
ChainssetShortYearAlwaysAccepted(boolean)and returns itself.- Parameters:
shortYearAlwaysAccepted- Whether or not to always accept short year as user input.- Returns:
- This.
- See Also:
setShortYearAlwaysAccepted(boolean)
-
getDisplayName
public String 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.
-
-