Top Description Fields Constructors Methods
net.fortuna.ical4j.model

public Class Dur

extends Object
implements Comparable<Dur>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable
Annotations
@Deprecated
Imports
net.fortuna.ical4j.util.Dates, org.apache.commons.lang3.builder.HashCodeBuilder, java.io.IOException, .Serializable, java.util.Calendar, .Date, .StringTokenizer

Deprecated

Replaced by java.time.temporal.TemporalAmount implementations such as java.time.Duration and Period in Java 8.

$Id$ Created on 20/06/2005 Represents a duration of time in iCalendar. Note that according to RFC2445 durations represented in weeks are mutually exclusive of other duration fields.
 4.3.6   Duration

    Value Name: DURATION

    Purpose: This value type is used to identify properties that contain
    a duration of time.

    Formal Definition: The value type is defined by the following
    notation:

      dur-value  = (["+"] / "-") "P" (dur-date / dur-time / dur-week)

      dur-date   = dur-day [dur-time]
      dur-time   = "T" (dur-hour / dur-minute / dur-second)
      dur-week   = 1*DIGIT "W"
      dur-hour   = 1*DIGIT "H" [dur-minute]
      dur-minute = 1*DIGIT "M" [dur-second]
      dur-second = 1*DIGIT "S"
      dur-day    = 1*DIGIT "D"
Author
Ben Fortuna

Field Summary

Modifier and TypeField and Description
private int
private static final int
private static final int
private int
private static final int
private int
private static final int
private boolean
private int
private static final int
private static final long
private int

Constructor Summary

AccessConstructor and Description
public
Dur(final String
a string representation of a duration
value
)

Constructs a new duration instance from a string representation.

public
Dur(final int
a duration in weeks.
weeks
)

Constructs a new duration from the specified weeks.

public
Dur(final int
duration in days
days
,
final int
duration in hours
hours
,
final int
duration in minutes
minutes
,
final int
duration in seconds
seconds
)

Constructs a new duration from the specified arguments.

public
Dur(final Date
the first date of the duration
date1
,
final Date
the second date of the duration
date2
)

Constructs a new duration representing the time between the two specified dates.

Method Summary

Modifier and TypeMethod and Description
public final Dur

Returns:

a new instance representing the sum of the two durations.
add
(final Dur
the duration to add to this duration
duration
)
References Deprecated Dur is deprecated or references (maybe indirectly) at least one deprecated element.

Add two durations.

public final int

Returns:

a postive value if this duration is longer, zero if the duration lengths are equal, otherwise a negative value
compareTo
(final Dur
another duration instance
arg0
)

Implements java.lang.Comparable.compareTo.

References Deprecated Dur is deprecated or references (maybe indirectly) at least one deprecated element.

Compares this duration with another, acording to their length.

public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public final int

Returns:

Returns the days.
getDays
()

public final int

Returns:

Returns the hours.
getHours
()

public final int

Returns:

Returns the minutes.
getMinutes
()

public final int

Returns:

Returns the seconds.
getSeconds
()

public final Date

Returns:

the end of the duration as a date
getTime
(final Date
the date to start the duration
start
)

Returns a date representing the end of this duration from the specified start date.

public final int

Returns:

Returns the weeks.
getWeeks
()

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public final boolean

Returns:

Returns the negative.
isNegative
()

public final Dur

Returns:

a Dur instance that represents a negation of this instance
negate
()
References Deprecated Dur is deprecated or references (maybe indirectly) at least one deprecated element.

Provides a negation of this instance.

private void
public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

daysback to summary
private int days
DAYS_PER_WEEKback to summary
private static final int DAYS_PER_WEEK
DAYS_PER_YEARback to summary
private static final int DAYS_PER_YEAR
hoursback to summary
private int hours
HOURS_PER_DAYback to summary
private static final int HOURS_PER_DAY
minutesback to summary
private int minutes
MINUTES_PER_HOURback to summary
private static final int MINUTES_PER_HOUR
negativeback to summary
private boolean negative
secondsback to summary
private int seconds
SECONDS_PER_MINUTEback to summary
private static final int SECONDS_PER_MINUTE
serialVersionUIDback to summary
private static final long serialVersionUID
weeksback to summary
private int weeks

Constructor Detail

Durback to summary
public Dur(final String value)

Constructs a new duration instance from a string representation.

Parameters
value:String

a string representation of a duration

Durback to summary
public Dur(final int weeks)

Constructs a new duration from the specified weeks.

Parameters
weeks:int

a duration in weeks.

Durback to summary
public Dur(final int days, final int hours, final int minutes, final int seconds)

Constructs a new duration from the specified arguments.

Parameters
days:int

duration in days

hours:int

duration in hours

minutes:int

duration in minutes

seconds:int

duration in seconds

Durback to summary
public Dur(final Date date1, final Date date2)

Constructs a new duration representing the time between the two specified dates. The end date may precede the start date in order to represent a negative duration.

Parameters
date1:Date

the first date of the duration

date2:Date

the second date of the duration

Method Detail

addback to summary
public final Dur add(final Dur duration)

References Deprecated

Dur is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Add two durations. Durations may only be added if they are both positive or both negative durations.

Parameters
duration:Dur

the duration to add to this duration

Returns:Dur

a new instance representing the sum of the two durations.

compareToback to summary
public final int compareTo(final Dur arg0)

Implements java.lang.Comparable.compareTo.

References Deprecated

Dur is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Compares this duration with another, acording to their length.

Parameters
arg0:Dur

another duration instance

Returns:int

a postive value if this duration is longer, zero if the duration lengths are equal, otherwise a negative value

Annotations
@Override
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getDaysback to summary
public final int getDays()
Returns:int

Returns the days.

getHoursback to summary
public final int getHours()
Returns:int

Returns the hours.

getMinutesback to summary
public final int getMinutes()
Returns:int

Returns the minutes.

getSecondsback to summary
public final int getSeconds()
Returns:int

Returns the seconds.

getTimeback to summary
public final Date getTime(final Date start)

Returns a date representing the end of this duration from the specified start date.

Parameters
start:Date

the date to start the duration

Returns:Date

the end of the duration as a date

getWeeksback to summary
public final int getWeeks()
Returns:int

Returns the weeks.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isNegativeback to summary
public final boolean isNegative()
Returns:boolean

Returns the negative.

negateback to summary
public final Dur negate()

References Deprecated

Dur is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Provides a negation of this instance.

Returns:Dur

a Dur instance that represents a negation of this instance

readObjectback to summary
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override