Top Description Fields Constructors Methods
com.ibm.icu.impl.duration

public final Class Period

extends Object
Class Inheritance
Imports
com.ibm.icu.impl.duration.impl.DataRecord.ETimeLimit

Represents an approximate duration in multiple TimeUnits. Each unit, if set, has a count (which can be fractional and must be non-negative). In addition Period can either represent the duration as being into the past or future, and as being more or less than the defined value.

Use a PeriodFormatter to convert a Period to a String.

Periods are immutable. Mutating operations return the new result leaving the original unchanged.

Example:

Period p1 = Period.at(3, WEEK).and(2, DAY).inFuture();
Period p2 = p1.and(12, HOUR);

Field Summary

Modifier and TypeField and Description
pack-priv final int[]
pack-priv final boolean
pack-priv final byte

Constructor Summary

AccessConstructor and Description
private
Period(int limit, boolean future, float count, TimeUnit unit)

Private constructor used by static factory methods.

pack-priv
Period(int timeLimit, boolean inFuture, int[] counts)

Package private constructor used by setters and factory.

Method Summary

Modifier and TypeMethod and Description
public Period

Returns:

the new Period
and
(float
the number of units. must be non-negative
count
,
TimeUnit
the unit
unit
)

Set the given unit to have the given count.

public static Period

Returns:

the new Period
at
(float
the number of units, must be non-negative
count
,
TimeUnit
the unit
unit
)

Constructs a Period representing a duration of count units extending into the past.

public Period

Returns:

the new Period
at
()

Mark the duration as being at the defined duration.

private static void
checkCount(float count)

Validate count.

public boolean

Returns:

true if rhs is a Period and is equal to this
equals
(Object
the object to compare to
rhs
)

Overrides java.lang.Object.equals.

Returns true if rhs extends Period and the two Periods are equal.
public boolean

Returns:

true if the two periods are equal
equals
(Period
the period to compare to
rhs
)

Returns true if the same units are defined with the same counts, both extend into the future or both into the past, and if the limits (at, more than, less than) are the same.

public float

Returns:

the count
getCount
(TimeUnit
the unit to test
unit
)

Returns the count for the specified unit.

public int

Returns:

the hashCode
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hashCode.
public Period

Returns:

the new Period
inFuture
()

Mark the time as being in the future.

public Period

Returns:

the new Period
inFuture
(boolean
true if the time is in the future
future
)

Mark the duration as extending into the future if future is true, and into the past otherwise.

public Period

Returns:

the new Period
inPast
()

Mark the duration as extending into the past.

public Period

Returns:

the new Period
inPast
(boolean
true if the time is in the past
past
)

Mark the duration as extending into the past if past is true, and into the future otherwise.

public boolean

Returns:

true if this represents a duration into the future.
isInFuture
()

Returns true if this represents a duration into the future.

public boolean

Returns:

true if this represents a duration into the past
isInPast
()

Returns true if this represents a duration into the past

public boolean

Returns:

true if this represents a duration less than the defined duration.
isLessThan
()

Returns true if this represents a duration less than the defined duration.

public boolean

Returns:

true if this represents a duration in excess of the defined duration.
isMoreThan
()

Returns true if this represents a duration in excess of the defined duration.

public boolean

Returns:

true if any unit is set
isSet
()

Returns true if any unit is set.

public boolean

Returns:

true if the given unit is set.
isSet
(TimeUnit
the unit to test
unit
)

Returns true if the given unit is set.

public static Period

Returns:

the new Period
lessThan
(float
the number of units. must be non-negative
count
,
TimeUnit
the unit
unit
)

Constructs a Period representing a duration less than count units extending into the past.

public Period

Returns:

the new Period
lessThan
()

Mark the duration as being less than the defined duration.

public static Period

Returns:

the new Period
moreThan
(float
the number of units. must be non-negative
count
,
TimeUnit
the unit
unit
)

Constructs a Period representing a duration more than count units extending into the past.

public Period

Returns:

the new Period
moreThan
()

Mark the duration as being more than the defined duration.

public Period

Returns:

the new Period
omit
(TimeUnit
the unit to unset
unit
)

Mark the given unit as not being set.

private Period

Returns:

the new Period
setFuture
(boolean
true if the time is in the future
future
)

Sets whether this defines a future time.

private Period

Returns:

the new Period
setTimeLimit
(byte
the kind of limit
limit
)

Sets whether this is more than, less than, or 'about' the specified time.

private Period

Returns:

the new Period object.
setTimeUnitInternalValue
(TimeUnit
the period to change
unit
,
int
the int value as described above.
value
)

Sets the period to have the provided value, 1/1000 of the unit plus 1.

private Period
setTimeUnitValue(TimeUnit unit, float value)

Set the unit's internal value, converting from float to int.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

countsback to summary
pack-priv final int[] counts
inFutureback to summary
pack-priv final boolean inFuture
timeLimitback to summary
pack-priv final byte timeLimit

Constructor Detail

Periodback to summary
private Period(int limit, boolean future, float count, TimeUnit unit)

Private constructor used by static factory methods.

Periodback to summary
pack-priv Period(int timeLimit, boolean inFuture, int[] counts)

Package private constructor used by setters and factory.

Method Detail

andback to summary
public Period and(float count, TimeUnit unit)

Set the given unit to have the given count. Marks the unit as having been set. This can be used to set multiple units, or to reset a unit to have a new count. This does not add the count to an existing count for this unit.

Parameters
count:float

the number of units. must be non-negative

unit:TimeUnit

the unit

Returns:Period

the new Period

atback to summary
public static Period at(float count, TimeUnit unit)

Constructs a Period representing a duration of count units extending into the past.

Parameters
count:float

the number of units, must be non-negative

unit:TimeUnit

the unit

Returns:Period

the new Period

atback to summary
public Period at()

Mark the duration as being at the defined duration.

Returns:Period

the new Period

checkCountback to summary
private static void checkCount(float count)

Validate count.

equalsback to summary
public boolean equals(Object rhs)

Overrides java.lang.Object.equals.

Returns true if rhs extends Period and the two Periods are equal.

Parameters
rhs:Object

the object to compare to

Returns:boolean

true if rhs is a Period and is equal to this

Annotations
@Override
equalsback to summary
public boolean equals(Period rhs)

Returns true if the same units are defined with the same counts, both extend into the future or both into the past, and if the limits (at, more than, less than) are the same. Note that this means that a period of 1000ms and a period of 1sec will not compare equal.

Parameters
rhs:Period

the period to compare to

Returns:boolean

true if the two periods are equal

getCountback to summary
public float getCount(TimeUnit unit)

Returns the count for the specified unit. If the unit is not set, returns 0.

Parameters
unit:TimeUnit

the unit to test

Returns:float

the count

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hashCode.

Returns:int

the hashCode

Annotations
@Override
inFutureback to summary
public Period inFuture()

Mark the time as being in the future.

Returns:Period

the new Period

inFutureback to summary
public Period inFuture(boolean future)

Mark the duration as extending into the future if future is true, and into the past otherwise.

Parameters
future:boolean

true if the time is in the future

Returns:Period

the new Period

inPastback to summary
public Period inPast()

Mark the duration as extending into the past.

Returns:Period

the new Period

inPastback to summary
public Period inPast(boolean past)

Mark the duration as extending into the past if past is true, and into the future otherwise.

Parameters
past:boolean

true if the time is in the past

Returns:Period

the new Period

isInFutureback to summary
public boolean isInFuture()

Returns true if this represents a duration into the future.

Returns:boolean

true if this represents a duration into the future.

isInPastback to summary
public boolean isInPast()

Returns true if this represents a duration into the past

Returns:boolean

true if this represents a duration into the past

isLessThanback to summary
public boolean isLessThan()

Returns true if this represents a duration less than the defined duration.

Returns:boolean

true if this represents a duration less than the defined duration.

isMoreThanback to summary
public boolean isMoreThan()

Returns true if this represents a duration in excess of the defined duration.

Returns:boolean

true if this represents a duration in excess of the defined duration.

isSetback to summary
public boolean isSet()

Returns true if any unit is set.

Returns:boolean

true if any unit is set

isSetback to summary
public boolean isSet(TimeUnit unit)

Returns true if the given unit is set.

Parameters
unit:TimeUnit

the unit to test

Returns:boolean

true if the given unit is set.

lessThanback to summary
public static Period lessThan(float count, TimeUnit unit)

Constructs a Period representing a duration less than count units extending into the past.

Parameters
count:float

the number of units. must be non-negative

unit:TimeUnit

the unit

Returns:Period

the new Period

lessThanback to summary
public Period lessThan()

Mark the duration as being less than the defined duration.

Returns:Period

the new Period

moreThanback to summary
public static Period moreThan(float count, TimeUnit unit)

Constructs a Period representing a duration more than count units extending into the past.

Parameters
count:float

the number of units. must be non-negative

unit:TimeUnit

the unit

Returns:Period

the new Period

moreThanback to summary
public Period moreThan()

Mark the duration as being more than the defined duration.

Returns:Period

the new Period

omitback to summary
public Period omit(TimeUnit unit)

Mark the given unit as not being set.

Parameters
unit:TimeUnit

the unit to unset

Returns:Period

the new Period

setFutureback to summary
private Period setFuture(boolean future)

Sets whether this defines a future time.

Parameters
future:boolean

true if the time is in the future

Returns:Period

the new Period

setTimeLimitback to summary
private Period setTimeLimit(byte limit)

Sets whether this is more than, less than, or 'about' the specified time.

Parameters
limit:byte

the kind of limit

Returns:Period

the new Period

setTimeUnitInternalValueback to summary
private Period setTimeUnitInternalValue(TimeUnit unit, int value)

Sets the period to have the provided value, 1/1000 of the unit plus 1. Thus unset values are '0', 1' is the set value '0', 2 is the set value '1/1000', 3 is the set value '2/1000' etc.

Parameters
unit:TimeUnit

the period to change

value:int

the int value as described above.

Returns:Period

the new Period object.

setTimeUnitValueback to summary
private Period setTimeUnitValue(TimeUnit unit, float value)

Set the unit's internal value, converting from float to int.