Package org.jfree.chart.util
Class RelativeDateFormat
- java.lang.Object
-
- java.text.Format
-
- java.text.DateFormat
-
- org.jfree.chart.util.RelativeDateFormat
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class RelativeDateFormat extends java.text.DateFormatA formatter that formats dates to show the elapsed time relative to some base date.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private longbaseMillisThe base milliseconds for the elapsed time calculation.private java.text.NumberFormatdayFormatterA formatter for the day count (most likely not critical until the day count exceeds 999).private java.lang.StringdaySuffixA string appended after the day count.private java.text.NumberFormathourFormatterA formatter for the hours.private java.lang.StringhourSuffixA string appended after the hours.private static longMILLISECONDS_IN_ONE_DAYA constant for the number of milliseconds in one day.private static longMILLISECONDS_IN_ONE_HOURA constant for the number of milliseconds in one hour.private java.text.NumberFormatminuteFormatterA formatter for the minutes.private java.lang.StringminuteSuffixA string appended after the minutes.private java.lang.StringpositivePrefixA prefix prepended to the start of the format if the relative date is positive.private java.text.NumberFormatsecondFormatterA formatter for the seconds (and milliseconds).private java.lang.StringsecondSuffixA string appended after the seconds.private booleanshowZeroDaysA flag that controls whether or not a zero day count is displayed.private booleanshowZeroHoursA 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
Constructors Constructor Description RelativeDateFormat()Creates a new instance with base milliseconds set to zero.RelativeDateFormat(long baseMillis)Creates a new instance.RelativeDateFormat(java.util.Date time)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Returns a clone of this instance.booleanequals(java.lang.Object obj)Tests this formatter for equality with an arbitrary object.java.lang.StringBufferformat(java.util.Date date, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)Formats the given date as the amount of elapsed time (relative to the base date specified in the constructor).longgetBaseMillis()Returns the base date/time used to calculate the elapsed time for display.java.lang.StringgetDaySuffix()Returns the string that is appended to the day count.java.lang.StringgetHourSuffix()Returns the string that is appended to the hour count.java.lang.StringgetMinuteSuffix()Returns the string that is appended to the minute count.java.lang.StringgetPositivePrefix()Returns the string that is prepended to the format if the relative time is positive.java.lang.StringgetSecondSuffix()Returns the string that is appended to the second count.booleangetShowZeroDays()Returns the flag that controls whether or not zero day counts are shown in the formatted output.booleangetShowZeroHours()Returns the flag that controls whether or not zero hour counts are shown in the formatted output.inthashCode()Returns a hash code for this instance.java.util.Dateparse(java.lang.String source, java.text.ParsePosition pos)Parses the given string (not implemented).voidsetBaseMillis(long baseMillis)Sets the base date/time used to calculate the elapsed time for display.voidsetDayFormatter(java.text.NumberFormat formatter)Sets the formatter for the days.voidsetDaySuffix(java.lang.String suffix)Sets the string that is appended to the day count.voidsetHourFormatter(java.text.NumberFormat formatter)Sets the formatter for the hours.voidsetHourSuffix(java.lang.String suffix)Sets the string that is appended to the hour count.voidsetMinuteFormatter(java.text.NumberFormat formatter)Sets the formatter for the minutes.voidsetMinuteSuffix(java.lang.String suffix)Sets the string that is appended to the minute count.voidsetPositivePrefix(java.lang.String prefix)Sets the string that is prepended to the format if the relative time is positive.voidsetSecondFormatter(java.text.NumberFormat formatter)Sets the formatter for the seconds and milliseconds.voidsetSecondSuffix(java.lang.String suffix)Sets the string that is appended to the second count.voidsetShowZeroDays(boolean show)Sets the flag that controls whether or not zero day counts are shown in the formatted output.voidsetShowZeroHours(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
-
-
-
-
Field Detail
-
baseMillis
private long baseMillis
The base milliseconds for the elapsed time calculation.
-
showZeroDays
private boolean showZeroDays
A flag that controls whether or not a zero day count is displayed.
-
showZeroHours
private boolean showZeroHours
A flag that controls whether or not a zero hour count is displayed.
-
dayFormatter
private java.text.NumberFormat dayFormatter
A formatter for the day count (most likely not critical until the day count exceeds 999).
-
positivePrefix
private java.lang.String positivePrefix
A prefix prepended to the start of the format if the relative date is positive.
-
daySuffix
private java.lang.String daySuffix
A string appended after the day count.
-
hourFormatter
private java.text.NumberFormat hourFormatter
A formatter for the hours.
-
hourSuffix
private java.lang.String hourSuffix
A string appended after the hours.
-
minuteFormatter
private java.text.NumberFormat minuteFormatter
A formatter for the minutes.
-
minuteSuffix
private java.lang.String minuteSuffix
A string appended after the minutes.
-
secondFormatter
private java.text.NumberFormat secondFormatter
A formatter for the seconds (and milliseconds).
-
secondSuffix
private java.lang.String secondSuffix
A string appended after the seconds.
-
MILLISECONDS_IN_ONE_HOUR
private static final long MILLISECONDS_IN_ONE_HOUR
A constant for the number of milliseconds in one hour.- See Also:
- Constant Field Values
-
MILLISECONDS_IN_ONE_DAY
private static final long MILLISECONDS_IN_ONE_DAY
A constant for the number of milliseconds in one day.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RelativeDateFormat
public RelativeDateFormat()
Creates a new instance with base milliseconds set to zero.
-
RelativeDateFormat
public RelativeDateFormat(java.util.Date time)
Creates a new instance.- Parameters:
time- the date/time (nullnot permitted).
-
RelativeDateFormat
public RelativeDateFormat(long baseMillis)
Creates a new instance.- Parameters:
baseMillis- the time zone (nullnot permitted).
-
-
Method Detail
-
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(long)
-
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:
getBaseMillis()
-
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(boolean)
-
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:
getShowZeroDays()
-
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(boolean)
-
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:
getShowZeroHours()
-
getPositivePrefix
public java.lang.String getPositivePrefix()
Returns the string that is prepended to the format if the relative time is positive.- Returns:
- The string (never
null). - See Also:
setPositivePrefix(String)
-
setPositivePrefix
public void setPositivePrefix(java.lang.String prefix)
Sets the string that is prepended to the format if the relative time is positive.- Parameters:
prefix- the prefix (nullnot permitted).- See Also:
getPositivePrefix()
-
setDayFormatter
public void setDayFormatter(java.text.NumberFormat formatter)
Sets the formatter for the days.- Parameters:
formatter- the formatter (nullnot permitted).
-
getDaySuffix
public java.lang.String getDaySuffix()
Returns the string that is appended to the day count.- Returns:
- The string.
- See Also:
setDaySuffix(String)
-
setDaySuffix
public void setDaySuffix(java.lang.String suffix)
Sets the string that is appended to the day count.- Parameters:
suffix- the suffix (nullnot permitted).- See Also:
getDaySuffix()
-
setHourFormatter
public void setHourFormatter(java.text.NumberFormat formatter)
Sets the formatter for the hours.- Parameters:
formatter- the formatter (nullnot permitted).
-
getHourSuffix
public java.lang.String getHourSuffix()
Returns the string that is appended to the hour count.- Returns:
- The string.
- See Also:
setHourSuffix(String)
-
setHourSuffix
public void setHourSuffix(java.lang.String suffix)
Sets the string that is appended to the hour count.- Parameters:
suffix- the suffix (nullnot permitted).- See Also:
getHourSuffix()
-
setMinuteFormatter
public void setMinuteFormatter(java.text.NumberFormat formatter)
Sets the formatter for the minutes.- Parameters:
formatter- the formatter (nullnot permitted).
-
getMinuteSuffix
public java.lang.String getMinuteSuffix()
Returns the string that is appended to the minute count.- Returns:
- The string.
- See Also:
setMinuteSuffix(String)
-
setMinuteSuffix
public void setMinuteSuffix(java.lang.String suffix)
Sets the string that is appended to the minute count.- Parameters:
suffix- the suffix (nullnot permitted).- See Also:
getMinuteSuffix()
-
getSecondSuffix
public java.lang.String getSecondSuffix()
Returns the string that is appended to the second count.- Returns:
- The string.
- See Also:
setSecondSuffix(String)
-
setSecondSuffix
public void setSecondSuffix(java.lang.String suffix)
Sets the string that is appended to the second count.- Parameters:
suffix- the suffix (nullnot permitted).- See Also:
getSecondSuffix()
-
setSecondFormatter
public void setSecondFormatter(java.text.NumberFormat formatter)
Sets the formatter for the seconds and milliseconds.- Parameters:
formatter- the formatter (nullnot permitted).
-
format
public java.lang.StringBuffer format(java.util.Date date, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)Formats the given date as the amount of elapsed time (relative to the base date specified in the constructor).- Specified by:
formatin classjava.text.DateFormat- Parameters:
date- the date.toAppendTo- the string buffer.fieldPosition- the field position.- Returns:
- The formatted date.
-
parse
public java.util.Date parse(java.lang.String source, java.text.ParsePosition pos)Parses the given string (not implemented).- Specified by:
parsein classjava.text.DateFormat- Parameters:
source- the date string.pos- the parse position.- Returns:
null, as this method has not been implemented.
-
equals
public boolean equals(java.lang.Object obj)
Tests this formatter for equality with an arbitrary object.- Overrides:
equalsin classjava.text.DateFormat- Parameters:
obj- the object (nullpermitted).- Returns:
- A boolean.
-
hashCode
public int hashCode()
Returns a hash code for this instance.- Overrides:
hashCodein classjava.text.DateFormat- Returns:
- A hash code.
-
clone
public java.lang.Object clone()
Returns a clone of this instance.- Overrides:
clonein classjava.text.DateFormat- Returns:
- A clone.
-
-