org.apache.velocity.tools.generic

## Class ComparisonDateTool.Comparison

- java.lang.Object
- - org.apache.velocity.tools.generic.ComparisonDateTool.Comparison

Enclosing class:
  ComparisonDateTool

    public class ComparisonDateTool.Comparison
    extends Object

### Constructor Summary

Constructors
Constructor and Description
`Comparison(Calendar now, Calendar then, int type, int depth, boolean abbr, Locale loc)` Comparison object constructor

### Method Summary

All Methods Instance Methods Concrete Methods
`ComparisonDateTool.Comparison` `abbr(boolean abbr)` Sets whether or not this comparison is to be rendered in abbreviated form or not.
`ComparisonDateTool.Comparison` `depth(int depth)` Set the maximum number of units to render for this comparison.
`ComparisonDateTool.Comparison` `getAbbr()` This is equivalent to calling `abbr(boolean abbr)` with `true` as the argument, thus setting this comparison to be rendered in abbreviated form.
`long` `getDays()` Return the number of days between the dates being compared.
`ComparisonDateTool.Comparison` `getDifference()` Sets this comparison to be rendered as a `ComparisonDateTool.difference(java.lang.Object, java.lang.Object)`.
`ComparisonDateTool.Comparison` `getExact()` Sets this comparison to be rendered as if it where generated using the `ComparisonDateTool.timespan(Object now, Object then)` method.
`protected int[]` `getExactDifference()` Internal helper returning a cached map of all exact bygone time units per field.
`ComparisonDateTool.Comparison` `getFull()` Sets the `depth(int depth)` to which this comparison is rendered to the maximum number of time units available to the tool.
`long` `getHours()` Return the number of hours between the dates being compared.
`long` `getMilliseconds()` Return the number of milliseconds between the dates being compared.
`long` `getMinutes()` Return the number of minutes between the dates being compared.
`long` `getMonths()` Return the approximate number of months between the dates being compared, or the bygone number of months after the bygone number of years in exact mode.
`ComparisonDateTool.Comparison` `getRelative()` Sets this comparison to be rendered as if it where generated using the `ComparisonDateTool.whenIs(Object now, Object then)` method.
`long` `getSeconds()` Return the number of seconds between the dates being compared.
`long` `getWeeks()` Return the number of weeks between the dates being compared.
`long` `getYears()` Return the approximate number of years between the dates being compared, or the bygone number of years in exact mode.
`ComparisonDateTool.Comparison` `locale(Locale loc)` Sets the locale used to look up the textual portions of the rendering.
`String` `toString()` Renders this comparison to a String.
`protected String` `toString(long diff, int maxUnitDepth)` Converts the specified positive duration of milliseconds into larger units up to the specified number of positive units, beginning with the largest positive unit.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### Comparison

    public Comparison(Calendar now,
                      Calendar then,
                      int type,
                      int depth,
                      boolean abbr,
                      Locale loc)

Comparison object constructor

Parameters:
  `now` - The date to use as representative of "now"
  `then` - The secondary date
  `type` - comparison type
  `depth` - units depth
  `abbr` - whether to abbreviate units
  `loc` - locale to use

### Method Detail

#### abbr

    public ComparisonDateTool.Comparison abbr(boolean abbr)

Sets whether or not this comparison is to be rendered in abbreviated form or not. By default, it is not abbreviated.

Parameters:
  `abbr` - flag value
Returns:
  new Comparison object

#### depth

    public ComparisonDateTool.Comparison depth(int depth)

Set the maximum number of units to render for this comparison. By default, this is set to 1 unit.

Parameters:
  `depth` - max units depth
Returns:
  new Comparison object

#### locale

    public ComparisonDateTool.Comparison locale(Locale loc)

Sets the locale used to look up the textual portions of the rendering. This defaults to the Locale configured for this tool, if any. If no locale was configured, this defaults to the system default.

Parameters:
  `loc` - locale to use
Returns:
  new Comparison object

#### getExactDifference

    protected final int[] getExactDifference()

Internal helper returning a cached map of all exact bygone time units per field.

Returns:
  cached exact difference holder, as a calendar object

#### getYears

    public long getYears()

Return the approximate number of years between the dates being compared, or the bygone number of years in exact mode.

Returns:
  years

#### getMonths

    public long getMonths()

Return the approximate number of months between the dates being compared, or the bygone number of months after the bygone number of years in exact mode.

Returns:
  months

#### getWeeks

    public long getWeeks()

Return the number of weeks between the dates being compared.

Returns:
  weeks

#### getDays

    public long getDays()

Return the number of days between the dates being compared.

Returns:
  days

#### getHours

    public long getHours()

Return the number of hours between the dates being compared.

Returns:
  hours

#### getMinutes

    public long getMinutes()

Return the number of minutes between the dates being compared.

Returns:
  minutes

#### getSeconds

    public long getSeconds()

Return the number of seconds between the dates being compared.

Returns:
  seconds

#### getMilliseconds

    public long getMilliseconds()

Return the number of milliseconds between the dates being compared.

Returns:
  milliseconds

#### getFull

    public ComparisonDateTool.Comparison getFull()

Sets the `depth(int depth)` to which this comparison is rendered to the maximum number of time units available to the tool. By default, there are 8 units available, but the tool may be configured to "skip" any of the standard units, thus shortening the maximum depth.

Returns:
  new Comparison object

#### getDifference

    public ComparisonDateTool.Comparison getDifference()

Sets this comparison to be rendered as a `ComparisonDateTool.difference(java.lang.Object, java.lang.Object)`. This effectively means that the comparison will render as a period of time, without any suffix to describe the relative position of the dates being compared (e.g. "later" or "ago").

Returns:
  new Comparison object

#### getRelative

    public ComparisonDateTool.Comparison getRelative()

Sets this comparison to be rendered as if it where generated using the `ComparisonDateTool.whenIs(Object now, Object then)` method. This effectively means that the comparison will render with a suffix to describe the relative position of the dates being compared (e.g. "later" or "ago").

Returns:
  new Comparison object

#### getExact

    public ComparisonDateTool.Comparison getExact()

Sets this comparison to be rendered as if it where generated using the `ComparisonDateTool.timespan(Object now, Object then)` method. This effectively means that the comparison will render with a suffix to describe the relative position of the dates being compared (e.g. "later" or "ago").

Returns:
  new Comparison object

#### getAbbr

    public ComparisonDateTool.Comparison getAbbr()

This is equivalent to calling `abbr(boolean abbr)` with `true` as the argument, thus setting this comparison to be rendered in abbreviated form.

Returns:
  new Comparison object

#### toString

    protected String toString(long diff,
                              int maxUnitDepth)

Converts the specified positive duration of milliseconds into larger units up to the specified number of positive units, beginning with the largest positive unit. e.g. `toString(181453, 3, false, null)` will return "3 minutes 1 second 453 milliseconds", `toString(181453, 2, false, null)` will return "3 minutes 1 second", and `toString(180000, 2, true, null)` will return "3 min".

Parameters:
  `diff` - milliseconds, or, in exact mode, time unit index
  `maxUnitDepth` - maximum unit depth
Returns:
  string representation of the difference

#### toString

    public String toString()

Renders this comparison to a String.

Overrides:
  `toString` in class `Object`
Returns:
  string representation