Package org.jfree.chart.util
Class RelativeDateFormat
java.lang.Object
java.text.Format
java.text.DateFormat
org.jfree.chart.util.RelativeDateFormat
- All Implemented Interfaces:
Serializable
,Cloneable
A formatter that formats dates to show the elapsed time relative to some
base date.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.DateFormat
DateFormat.Field
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
The base milliseconds for the elapsed time calculation.private NumberFormat
A formatter for the day count (most likely not critical until the day count exceeds 999).private String
A string appended after the day count.private NumberFormat
A formatter for the hours.private String
A string appended after the hours.private static final long
A constant for the number of milliseconds in one day.private static final long
A constant for the number of milliseconds in one hour.private NumberFormat
A formatter for the minutes.private String
A string appended after the minutes.private String
A prefix prepended to the start of the format if the relative date is positive.private NumberFormat
A formatter for the seconds (and milliseconds).private String
A string appended after the seconds.private boolean
A flag that controls whether or not a zero day count is displayed.private boolean
A flag that controls whether or not a zero hour count is displayed.Fields inherited from class java.text.DateFormat
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with base milliseconds set to zero.RelativeDateFormat
(long baseMillis) Creates a new instance.RelativeDateFormat
(Date time) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this instance.boolean
Tests this formatter for equality with an arbitrary object.format
(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) Formats the given date as the amount of elapsed time (relative to the base date specified in the constructor).long
Returns the base date/time used to calculate the elapsed time for display.Returns the string that is appended to the day count.Returns the string that is appended to the hour count.Returns the string that is appended to the minute count.Returns the string that is prepended to the format if the relative time is positive.Returns the string that is appended to the second count.boolean
Returns the flag that controls whether or not zero day counts are shown in the formatted output.boolean
Returns the flag that controls whether or not zero hour counts are shown in the formatted output.int
hashCode()
Returns a hash code for this instance.parse
(String source, ParsePosition pos) Parses the given string (not implemented).void
setBaseMillis
(long baseMillis) Sets the base date/time used to calculate the elapsed time for display.void
setDayFormatter
(NumberFormat formatter) Sets the formatter for the days.void
setDaySuffix
(String suffix) Sets the string that is appended to the day count.void
setHourFormatter
(NumberFormat formatter) Sets the formatter for the hours.void
setHourSuffix
(String suffix) Sets the string that is appended to the hour count.void
setMinuteFormatter
(NumberFormat formatter) Sets the formatter for the minutes.void
setMinuteSuffix
(String suffix) Sets the string that is appended to the minute count.void
setPositivePrefix
(String prefix) Sets the string that is prepended to the format if the relative time is positive.void
setSecondFormatter
(NumberFormat formatter) Sets the formatter for the seconds and milliseconds.void
setSecondSuffix
(String suffix) Sets the string that is appended to the second count.void
setShowZeroDays
(boolean show) Sets the flag that controls whether or not zero day counts are shown in the formatted output.void
setShowZeroHours
(boolean show) Sets the flag that controls whether or not zero hour counts are shown in the formatted output.Methods inherited from class java.text.DateFormat
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
Methods inherited from class java.text.Format
format, formatToCharacterIterator, parseObject
-
Field Details
-
baseMillis
private long baseMillisThe base milliseconds for the elapsed time calculation. -
showZeroDays
private boolean showZeroDaysA flag that controls whether or not a zero day count is displayed. -
showZeroHours
private boolean showZeroHoursA flag that controls whether or not a zero hour count is displayed. -
dayFormatter
A formatter for the day count (most likely not critical until the day count exceeds 999). -
positivePrefix
A prefix prepended to the start of the format if the relative date is positive. -
daySuffix
A string appended after the day count. -
hourFormatter
A formatter for the hours. -
hourSuffix
A string appended after the hours. -
minuteFormatter
A formatter for the minutes. -
minuteSuffix
A string appended after the minutes. -
secondFormatter
A formatter for the seconds (and milliseconds). -
secondSuffix
A string appended after the seconds. -
MILLISECONDS_IN_ONE_HOUR
private static final long MILLISECONDS_IN_ONE_HOURA constant for the number of milliseconds in one hour.- See Also:
-
MILLISECONDS_IN_ONE_DAY
private static final long MILLISECONDS_IN_ONE_DAYA constant for the number of milliseconds in one day.- See Also:
-
-
Constructor Details
-
RelativeDateFormat
public RelativeDateFormat()Creates a new instance with base milliseconds set to zero. -
RelativeDateFormat
Creates a new instance.- Parameters:
time
- the date/time (null
not permitted).
-
RelativeDateFormat
public RelativeDateFormat(long baseMillis) Creates a new instance.- Parameters:
baseMillis
- the time zone (null
not permitted).
-
-
Method Details
-
getBaseMillis
public long getBaseMillis()Returns the base date/time used to calculate the elapsed time for display.- Returns:
- The base date/time in milliseconds since 1-Jan-1970.
- See Also:
-
setBaseMillis
public void setBaseMillis(long baseMillis) Sets the base date/time used to calculate the elapsed time for display. This should be specified in milliseconds using the same encoding asjava.util.Date
.- Parameters:
baseMillis
- the base date/time in milliseconds.- See Also:
-
getShowZeroDays
public boolean getShowZeroDays()Returns the flag that controls whether or not zero day counts are shown in the formatted output.- Returns:
- The flag.
- See Also:
-
setShowZeroDays
public void setShowZeroDays(boolean show) Sets the flag that controls whether or not zero day counts are shown in the formatted output.- Parameters:
show
- the flag.- See Also:
-
getShowZeroHours
public boolean getShowZeroHours()Returns the flag that controls whether or not zero hour counts are shown in the formatted output.- Returns:
- The flag.
- See Also:
-
setShowZeroHours
public void setShowZeroHours(boolean show) Sets the flag that controls whether or not zero hour counts are shown in the formatted output.- Parameters:
show
- the flag.- See Also:
-
getPositivePrefix
Returns the string that is prepended to the format if the relative time is positive.- Returns:
- The string (never
null
). - See Also:
-
setPositivePrefix
Sets the string that is prepended to the format if the relative time is positive.- Parameters:
prefix
- the prefix (null
not permitted).- See Also:
-
setDayFormatter
Sets the formatter for the days.- Parameters:
formatter
- the formatter (null
not permitted).
-
getDaySuffix
Returns the string that is appended to the day count.- Returns:
- The string.
- See Also:
-
setDaySuffix
Sets the string that is appended to the day count.- Parameters:
suffix
- the suffix (null
not permitted).- See Also:
-
setHourFormatter
Sets the formatter for the hours.- Parameters:
formatter
- the formatter (null
not permitted).
-
getHourSuffix
Returns the string that is appended to the hour count.- Returns:
- The string.
- See Also:
-
setHourSuffix
Sets the string that is appended to the hour count.- Parameters:
suffix
- the suffix (null
not permitted).- See Also:
-
setMinuteFormatter
Sets the formatter for the minutes.- Parameters:
formatter
- the formatter (null
not permitted).
-
getMinuteSuffix
Returns the string that is appended to the minute count.- Returns:
- The string.
- See Also:
-
setMinuteSuffix
Sets the string that is appended to the minute count.- Parameters:
suffix
- the suffix (null
not permitted).- See Also:
-
getSecondSuffix
Returns the string that is appended to the second count.- Returns:
- The string.
- See Also:
-
setSecondSuffix
Sets the string that is appended to the second count.- Parameters:
suffix
- the suffix (null
not permitted).- See Also:
-
setSecondFormatter
Sets the formatter for the seconds and milliseconds.- Parameters:
formatter
- the formatter (null
not permitted).
-
format
Formats the given date as the amount of elapsed time (relative to the base date specified in the constructor).- Specified by:
format
in classDateFormat
- Parameters:
date
- the date.toAppendTo
- the string buffer.fieldPosition
- the field position.- Returns:
- The formatted date.
-
parse
Parses the given string (not implemented).- Specified by:
parse
in classDateFormat
- Parameters:
source
- the date string.pos
- the parse position.- Returns:
null
, as this method has not been implemented.
-
equals
Tests this formatter for equality with an arbitrary object.- Overrides:
equals
in classDateFormat
- Parameters:
obj
- the object (null
permitted).- Returns:
- A boolean.
-
hashCode
public int hashCode()Returns a hash code for this instance.- Overrides:
hashCode
in classDateFormat
- Returns:
- A hash code.
-
clone
Returns a clone of this instance.- Overrides:
clone
in classDateFormat
- Returns:
- A clone.
-