Author: rhauch
Date: 2008-08-15 16:24:19 -0400 (Fri, 15 Aug 2008)
New Revision: 431
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
Log:
DNA-202 - DateTime interface in SPI should have methods that return offsets into the
future or past
http://jira.jboss.com/jira/browse/DNA-202
Added "plus" and "minus" methods to allow offseting by number of
weeks, days, years, months, seconds, minutes, hours, milliseconds, etc.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-08-14 21:41:37
UTC (rev 430)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/DateTime.java 2008-08-15 20:24:19
UTC (rev 431)
@@ -23,6 +23,7 @@
import java.io.Serializable;
import java.util.Locale;
+import java.util.concurrent.TimeUnit;
import net.jcip.annotations.Immutable;
/**
@@ -270,4 +271,152 @@
*/
boolean isSameAs( DateTime other );
+ /**
+ * Subtract the specified about of time in the supplied units.
+ *
+ * @param timeAmount the amount of time to subtract
+ * @param unit the units of the amount of time; may not be null
+ * @return the instance in time the specified number of time before this instant
+ */
+ DateTime minus( long timeAmount,
+ TimeUnit unit );
+
+ /**
+ * Subtract the specified number of days from this time instant.
+ *
+ * @param days the number of days to subtract
+ * @return the instance in time the specified number of days before this instant
+ */
+ DateTime minusDays( int days );
+
+ /**
+ * Subtract the specified number of hours from this time instant.
+ *
+ * @param hours the number of hours to subtract
+ * @return the instance in time the specified number of hours before this instant
+ */
+ DateTime minusHours( int hours );
+
+ /**
+ * Subtract the specified number of milliseconds from this time instant.
+ *
+ * @param milliseconds the number of milliseconds to subtract
+ * @return the instance in time the specified number of milliseconds before this
instant
+ */
+ DateTime minusMillis( int milliseconds );
+
+ /**
+ * Subtract the specified number of minutes from this time instant.
+ *
+ * @param minutes the number of minutes to subtract
+ * @return the instance in time the specified number of minutes before this instant
+ */
+ DateTime minusMinutes( int minutes );
+
+ /**
+ * Subtract the specified number of months from this time instant.
+ *
+ * @param months the number of months to subtract
+ * @return the instance in time the specified number of months before this instant
+ */
+ DateTime minusMonths( int months );
+
+ /**
+ * Subtract the specified number of seconds from this time instant.
+ *
+ * @param seconds the number of seconds to subtract
+ * @return the instance in time the specified number of seconds before this instant
+ */
+ DateTime minusSeconds( int seconds );
+
+ /**
+ * Subtract the specified number of weeks from this time instant.
+ *
+ * @param weeks the number of weeks to subtract
+ * @return the instance in time the specified number of weeks before this instant
+ */
+ DateTime minusWeeks( int weeks );
+
+ /**
+ * Subtract the specified number of years from this time instant.
+ *
+ * @param years the number of years to subtract
+ * @return the instance in time the specified number of years before this instant
+ */
+ DateTime minusYears( int years );
+
+ /**
+ * Add the specified about of time in the supplied units.
+ *
+ * @param timeAmount the amount of time to add
+ * @param unit the units of the amount of time; may not be null
+ * @return the instance in time the specified number of time after this instant
+ */
+ DateTime plus( long timeAmount,
+ TimeUnit unit );
+
+ /**
+ * Add the specified number of days from this time instant.
+ *
+ * @param days the number of days to add
+ * @return the instance in time the specified number of days after this instant
+ */
+ DateTime plusDays( int days );
+
+ /**
+ * Add the specified number of hours from this time instant.
+ *
+ * @param hours the number of hours to add
+ * @return the instance in time the specified number of hours after this instant
+ */
+ DateTime plusHours( int hours );
+
+ /**
+ * Add the specified number of milliseconds from this time instant.
+ *
+ * @param milliseconds the number of milliseconds to add
+ * @return the instance in time the specified number of milliseconds after this
instant
+ */
+ DateTime plusMillis( int milliseconds );
+
+ /**
+ * Add the specified number of minutes from this time instant.
+ *
+ * @param minutes the number of minutes to add
+ * @return the instance in time the specified number of minutes after this instant
+ */
+ DateTime plusMinutes( int minutes );
+
+ /**
+ * Add the specified number of months from this time instant.
+ *
+ * @param months the number of months to add
+ * @return the instance in time the specified number of months after this instant
+ */
+ DateTime plusMonths( int months );
+
+ /**
+ * Add the specified number of seconds from this time instant.
+ *
+ * @param seconds the number of seconds to add
+ * @return the instance in time the specified number of seconds after this instant
+ */
+ DateTime plusSeconds( int seconds );
+
+ /**
+ * Add the specified number of weeks from this time instant.
+ *
+ * @param weeks the number of weeks to add
+ * @return the instance in time the specified number of weeks after this instant
+ */
+ DateTime plusWeeks( int weeks );
+
+ /**
+ * Add the specified number of years from this time instant.
+ *
+ * @param years the number of years to add
+ * @return the instance in time the specified number of years after this instant
+ */
+ DateTime plusYears( int years );
+
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-08-14
21:41:37 UTC (rev 430)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/JodaDateTime.java 2008-08-15
20:24:19 UTC (rev 431)
@@ -25,6 +25,7 @@
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
+import java.util.concurrent.TimeUnit;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.ArgCheck;
import org.joda.time.Chronology;
@@ -403,4 +404,170 @@
return this.compareTo(other) > 0;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#minus(long, java.util.concurrent.TimeUnit)
+ */
+ public org.jboss.dna.spi.graph.DateTime minus( long timeAmount,
+ TimeUnit unit ) {
+ ArgCheck.isNotNull(unit, "unit");
+ return new
JodaDateTime(this.instance.minus(TimeUnit.MILLISECONDS.convert(timeAmount, unit)));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#minusDays(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime minusDays( int days ) {
+ return new JodaDateTime(this.instance.minusDays(days));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#minusHours(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime minusHours( int hours ) {
+ return new JodaDateTime(this.instance.minusHours(hours));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#minusMillis(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime minusMillis( int milliseconds ) {
+ return new JodaDateTime(this.instance.minusMillis(milliseconds));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#minusMinutes(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime minusMinutes( int minutes ) {
+ return new JodaDateTime(this.instance.minusMinutes(minutes));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#minusMonths(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime minusMonths( int months ) {
+ return new JodaDateTime(this.instance.minusMonths(months));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#minusSeconds(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime minusSeconds( int seconds ) {
+ return new JodaDateTime(this.instance.minusSeconds(seconds));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#minusWeeks(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime minusWeeks( int weeks ) {
+ return new JodaDateTime(this.instance.minusWeeks(weeks));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#minusYears(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime minusYears( int years ) {
+ return new JodaDateTime(this.instance.minusYears(years));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#plus(long, java.util.concurrent.TimeUnit)
+ */
+ public org.jboss.dna.spi.graph.DateTime plus( long timeAmount,
+ TimeUnit unit ) {
+ ArgCheck.isNotNull(unit, "unit");
+ return new
JodaDateTime(this.instance.plus(TimeUnit.MILLISECONDS.convert(timeAmount, unit)));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#plusDays(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime plusDays( int days ) {
+ return new JodaDateTime(this.instance.plusDays(days));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#plusHours(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime plusHours( int hours ) {
+ return new JodaDateTime(this.instance.plusHours(hours));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#plusMillis(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime plusMillis( int milliseconds ) {
+ return new JodaDateTime(this.instance.plusMillis(milliseconds));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#plusMinutes(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime plusMinutes( int minutes ) {
+ return new JodaDateTime(this.instance.plusMinutes(minutes));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#plusMonths(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime plusMonths( int months ) {
+ return new JodaDateTime(this.instance.plusMonths(months));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#plusSeconds(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime plusSeconds( int seconds ) {
+ return new JodaDateTime(this.instance.plusSeconds(seconds));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#plusWeeks(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime plusWeeks( int weeks ) {
+ return new JodaDateTime(this.instance.plusWeeks(weeks));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.graph.DateTime#plusYears(int)
+ */
+ public org.jboss.dna.spi.graph.DateTime plusYears( int years ) {
+ return new JodaDateTime(this.instance.plusYears(years));
+ }
+
}