Skip to content

Commit

Permalink
TimeDuration JavaDocs.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@701251 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
adrian-crum committed Oct 2, 2008
1 parent b9a56b8 commit a2aa05e
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions framework/base/src/org/ofbiz/base/util/TimeDuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/** A representation of a period of time. */
@SuppressWarnings("serial")
public class TimeDuration implements Serializable {
/** A <code>TimeDuration</code> instance that represents a zero time duration. */
public static final TimeDuration ZeroTimeDuration = new NullDuration();

protected int millis = 0;
Expand All @@ -33,10 +34,18 @@ public class TimeDuration implements Serializable {
protected int days = 0;
protected int months = 0;
protected int years = 0;

protected TimeDuration() {}

public TimeDuration(int millis, int seconds, int minutes, int hours, int days, int months, int years) {
/**
* @param years The number of years in this duration
* @param months The number of months in this duration
* @param days The number of days in this duration
* @param hours The number of hours in this duration
* @param minutes The number of minutes in this duration
* @param seconds The number of years in this duration
* @param millis The number of milliseconds in this duration
*/
public TimeDuration(int years, int months, int days, int hours, int minutes, int seconds, int millis) {
this.millis = millis;
this.seconds = seconds;
this.minutes = minutes;
Expand All @@ -46,6 +55,11 @@ public TimeDuration(int millis, int seconds, int minutes, int hours, int days, i
this.years = years;
}

/** Elapsed time constructor. The time duration will be computed from the
* two <code>Calendar</code> instances.
* @param cal1
* @param cal2
*/
public TimeDuration(Calendar cal1, Calendar cal2) {
this.set(cal1, cal2);
}
Expand All @@ -67,38 +81,45 @@ public String toString() {
return this.years + ":" + this.months + ":" + this.days + ":" + this.hours + ":" + this.minutes + ":" + this.seconds + ":" + this.millis;
}

/** Returns the milliseconds in this time duration. */
public int millis() {
return this.millis;
}

/** Returns the seconds in this time duration. */
public int seconds() {
return this.seconds;
}

/** Returns the minutes in this time duration. */
public int minutes() {
return this.minutes;
}

/** Returns the hours in this time duration. */
public int hours() {
return this.hours;
}

/** Returns the days in this time duration. */
public int days() {
return this.days;
}

/** Returns the months in this time duration. */
public int months() {
return this.months;
}

/** Returns the years in this time duration. */
public int years() {
return this.years;
}

/** Add this time duration to a Calendar instance. Returns the original
* Calendar instance.
* @param cal
* @return The <code>cal</code> argument
* @return <code>cal</code>
*/
public Calendar addToCalendar(Calendar cal) {
cal.add(Calendar.MILLISECOND, this.millis);
Expand All @@ -114,7 +135,7 @@ public Calendar addToCalendar(Calendar cal) {
/** Subtract this time duration to a Calendar instance. Returns the original
* Calendar instance.
* @param cal
* @return The <code>cal</code> argument
* @return <code>cal</code>
*/
public Calendar subtractFromCalendar(Calendar cal) {
cal.add(Calendar.MILLISECOND, -this.millis);
Expand Down Expand Up @@ -196,6 +217,7 @@ protected int advanceCalendar(Calendar start, Calendar end, int units, int type)
}

protected static class NullDuration extends TimeDuration {
protected NullDuration() {}
public Calendar addToCalendar(Calendar cal) {
return cal;
}
Expand Down

0 comments on commit a2aa05e

Please sign in to comment.