Package adams.core.base
Class BaseDate
- java.lang.Object
-
- adams.core.base.BaseObject
-
- adams.core.base.BaseDate
-
- All Implemented Interfaces:
CloneHandler<BaseObject>,DateValueSupporter,GrammarSupplier,Serializable,Comparable
public class BaseDate extends BaseObject implements GrammarSupplier, DateValueSupporter
Wrapper for a Date string to be editable in the GOE. Dates have to be of format "yyyy-MM-dd".parses expressions as follows: (<date>|NOW|-INF|+INF|START|END) [(+<int>|-<int>) (DAY|BUSINESSDAY|WEEK|MONTH|YEAR)] Examples: 1999-12-31 1999-12-31 +1 DAY NOW +INF NOW +1 YEAR NOW +14 DAY Amounts can be chained as well: NOW -1 MONTH +1 DAY START and END can only be set programmatically; by default they equal to -INF and +INF.
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
FORMAT,setStart(Date),setEnd(Date), Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringENDthe placeholder for "end".static StringFORMATthe date format.static StringINF_FUTUREthe placeholder for "+INF" (infinity in the future).static StringINF_FUTURE_DATEthe "+INF" date.static StringINF_PASTthe placeholder for "-INF" (infinity in the past).static StringINF_PAST_DATEthe "-INF" date.protected BusinessDaysm_BusinessDayshow to interpret business days.protected Datem_Endthe end date to use.protected static DateFormatm_Formatfor formatting/parsing the dates.protected Datem_Startthe start date to use.static StringNOWthe placeholder for "now".static StringSTARTthe placeholder for "start".static StringTODAYthe placeholder for "today".static StringTOMORROWthe placeholder for "tomorrow".static StringYESTERDAYthe placeholder for "yesterday".-
Fields inherited from class adams.core.base.BaseObject
m_Internal, m_Properties, SUFFIX_DISPLAY, SUFFIX_VALUE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DatedateValue()Returns the Date value.StringformatDateValue(String format)Returns the Date value formatted as a string.BusinessDaysgetBusinessDays()Returns what business days to use.DategetEnd()Returns the optional end date.protected static DateFormatgetFormat()Returns the formatter.StringgetGrammar()Returns a string representation of the grammar.DategetStart()Returns the optional start date.StringgetTipText()Returns a tool tip for the GUI editor (ignored if null is returned).StringgetValue()Returns the current string value.static BaseDateinfinityFuture()Returns a new BaseDate object initialized with the INF_FUTURE placeholder.static BaseDateinfinityPast()Returns a new BaseDate object initialized with the INF_PAST placeholder.protected voidinitialize()Initializes the internal object.booleanisInfinity()Checks whether the date/time is -INF or +INF.booleanisInfinityFuture()Checks whether the date/time is +INF.booleanisInfinityPast()Checks whether the date/time is -INF.booleanisValid(String value)Checks whether the string value is a valid presentation for this class.static BaseDatenow()Returns a new BaseDate object initialized with the NOW placeholder.protected Dateparse(String s, boolean quiet)Parses the given date string.voidsetBusinessDays(BusinessDays value)Sets what business days to use.voidsetEnd(Date value)Sets the optional end date.voidsetStart(Date value)Sets the optional start date.voidsetValue(String value)Sets the string value.StringstringValue()Returns the actual Date as string.-
Methods inherited from class adams.core.base.BaseObject
compareTo, equals, getClone, getInternal, getTemplates, getUnicode, hasFavoritesSupport, hashCode, isValidUnicode, newInstance, setUnicode, toObjectArray, toObjectArray, toString, toStringArray, toStringList
-
-
-
-
Field Detail
-
INF_PAST
public static final String INF_PAST
the placeholder for "-INF" (infinity in the past).- See Also:
- Constant Field Values
-
INF_PAST_DATE
public static final String INF_PAST_DATE
the "-INF" date.- See Also:
- Constant Field Values
-
INF_FUTURE
public static final String INF_FUTURE
the placeholder for "+INF" (infinity in the future).- See Also:
- Constant Field Values
-
INF_FUTURE_DATE
public static final String INF_FUTURE_DATE
the "+INF" date.- See Also:
- Constant Field Values
-
NOW
public static final String NOW
the placeholder for "now".- See Also:
- Constant Field Values
-
TODAY
public static final String TODAY
the placeholder for "today".- See Also:
- Constant Field Values
-
TOMORROW
public static final String TOMORROW
the placeholder for "tomorrow".- See Also:
- Constant Field Values
-
YESTERDAY
public static final String YESTERDAY
the placeholder for "yesterday".- See Also:
- Constant Field Values
-
START
public static final String START
the placeholder for "start".- See Also:
- Constant Field Values
-
END
public static final String END
the placeholder for "end".- See Also:
- Constant Field Values
-
FORMAT
public static final String FORMAT
the date format.- See Also:
- Constant Field Values
-
m_Format
protected static DateFormat m_Format
for formatting/parsing the dates.
-
m_Start
protected Date m_Start
the start date to use.
-
m_End
protected Date m_End
the end date to use.
-
m_BusinessDays
protected BusinessDays m_BusinessDays
how to interpret business days.
-
-
Constructor Detail
-
BaseDate
public BaseDate()
Initializes the date as NOW.- See Also:
NOW
-
BaseDate
public BaseDate(String s)
Initializes the object with the date to parse.- Parameters:
s- the date to parse
-
BaseDate
public BaseDate(Date date)
Initializes the object with the specified date.- Parameters:
date- the date to use
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the internal object.- Overrides:
initializein classBaseObject
-
getFormat
protected static DateFormat getFormat()
Returns the formatter.- Returns:
- the formatter
-
setStart
public void setStart(Date value)
Sets the optional start date.- Parameters:
value- the start date
-
getStart
public Date getStart()
Returns the optional start date.- Returns:
- the start date
-
setEnd
public void setEnd(Date value)
Sets the optional end date.- Parameters:
value- the end date
-
getEnd
public Date getEnd()
Returns the optional end date.- Returns:
- the end date
-
setBusinessDays
public void setBusinessDays(BusinessDays value)
Sets what business days to use.- Parameters:
value- the type
-
getBusinessDays
public BusinessDays getBusinessDays()
Returns what business days to use.- Returns:
- the type
-
parse
protected Date parse(String s, boolean quiet)
Parses the given date string.- Parameters:
s- the date string to parsequiet- whether to print exceptions or not- Returns:
- the parsed date, null in case of an error
-
isValid
public boolean isValid(String value)
Checks whether the string value is a valid presentation for this class.- Specified by:
isValidin classBaseObject- Parameters:
value- the string value to check- Returns:
- true if parseable date
-
setValue
public void setValue(String value)
Sets the string value.- Specified by:
setValuein classBaseObject- Parameters:
value- the string value
-
getValue
public String getValue()
Returns the current string value.- Specified by:
getValuein classBaseObject- Returns:
- the string value
-
dateValue
public Date dateValue()
Returns the Date value.- Specified by:
dateValuein interfaceDateValueSupporter- Returns:
- the Date value
-
stringValue
public String stringValue()
Returns the actual Date as string.- Returns:
- the actual date as string
-
formatDateValue
public String formatDateValue(String format)
Returns the Date value formatted as a string.- Specified by:
formatDateValuein interfaceDateValueSupporter- Returns:
- the formatted string
-
getTipText
public String getTipText()
Returns a tool tip for the GUI editor (ignored if null is returned).- Specified by:
getTipTextin classBaseObject- Returns:
- the tool tip
-
getGrammar
public String getGrammar()
Returns a string representation of the grammar.- Specified by:
getGrammarin interfaceGrammarSupplier- Returns:
- the grammar, null if not available
-
isInfinityFuture
public boolean isInfinityFuture()
Checks whether the date/time is +INF.- Returns:
- true if infinity future
-
isInfinityPast
public boolean isInfinityPast()
Checks whether the date/time is -INF.- Returns:
- true if infinity future
-
isInfinity
public boolean isInfinity()
Checks whether the date/time is -INF or +INF.- Returns:
- true if any infinity
-
now
public static BaseDate now()
Returns a new BaseDate object initialized with the NOW placeholder.- Returns:
- the BaseDate object
- See Also:
NOW
-
infinityFuture
public static BaseDate infinityFuture()
Returns a new BaseDate object initialized with the INF_FUTURE placeholder.- Returns:
- the BaseDate object
- See Also:
INF_FUTURE
-
-