Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
View
38 asx/src/asx/datetime/Interval.as
@@ -52,13 +52,23 @@ package asx.datetime
// Creates a new interval with the specified duration after the start instant.
public function withDurationAfterStart(duration:IReadableDuration):Interval
{
- return null;
+ if (duration && duration.millis < 0)
+ {
+ throw new ArgumentError("Interval#withDurationAfterStart() received negative Duration: " + duration);
+ }
+
+ return new Interval(startMillis, startMillis + (duration ? duration.millis : 0));
}
// Creates a new interval with the specified duration before the end instant.
public function withDurationBeforeEnd(duration:IReadableDuration):Interval
{
- return null;
+ if (duration && duration.millis < 0)
+ {
+ throw new ArgumentError("Interval#withDurationBeforeEnd() received negative Duration: " + duration);
+ }
+
+ return new Interval(endMillis - (duration ? duration.millis : 0), endMillis);
}
// public function withPeriodAfterStart(start:IReadablePeriod):Interval
@@ -72,23 +82,35 @@ package asx.datetime
// Creates a new interval with the specified start instant.
public function withStart(start:IReadableInstant):Interval
{
- return null;
+ if (!start)
+ {
+ // TODO sets start to now.
+ return null;
+ }
+
+ return withStartMillis(start.millis);
}
// Creates a new interval with the specified end instant.
public function withEnd(end:IReadableInstant):Interval
{
- return null;
+ if (!end)
+ {
+ // TODO sets start to now.
+ return null;
+ }
+
+ return withEndMillis(end.millis);
}
- public function withStartMillis(startMillis:Number):Interval
+ public function withStartMillis(millis:Number):Interval
{
- return null;
+ return new Interval(millis, endMillis);
}
- public function withEndMillis(endMillis:Number):Interval
+ public function withEndMillis(millis:Number):Interval
{
- return null;
+ return new Interval(startMillis, millis);
}
override public function toString():String
View
97 asx_test/src/asx/datetime/IntervalTest.as
@@ -5,6 +5,7 @@ package asx.datetime
import org.flexunit.assertThat;
import org.flexunit.asserts.fail;
+ import org.hamcrest.core.not;
import org.hamcrest.core.throws;
import org.hamcrest.object.equalTo;
import org.hamcrest.object.instanceOf;
@@ -17,6 +18,7 @@ package asx.datetime
{
private const START_MILLIS:Number = 100;
private const END_MILLIS:Number = 200;
+ private const DURATION_MILLIS:Number = 500;
[Test]
public function abuts_with_zero_duration():void
@@ -60,6 +62,7 @@ package asx.datetime
assertThat(".abuts(after)", interval.abuts(after), isFalse());
}
+ [Ignore(description="requires a millis provider")]
[Test]
public function gap_with_null_should_return_interval_to_now():void
{
@@ -107,39 +110,123 @@ package asx.datetime
}
[Test]
- public function withDurationAfterStart():void
+ public function withDurationAfterStart_with_null():void
{
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var zero:Interval = interval.withDurationAfterStart(null);
+ assertThat(".startMillis", zero.startMillis, equalTo(START_MILLIS));
+ assertThat(".endMillis", zero.endMillis, equalTo(START_MILLIS));
}
[Test]
- public function withDurationBeforeEnd():void
+ public function withDurationAfterStart_with_positive_duration():void
{
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var duration:Duration = new Duration(DURATION_MILLIS);
+ var after:Interval = interval.withDurationAfterStart(duration);
+ assertThat(".startMillis", after.startMillis, equalTo(START_MILLIS));
+ assertThat(".endMillis", after.endMillis, equalTo(START_MILLIS + DURATION_MILLIS));
+ }
+
+ [Test(expected="ArgumentError")]
+ public function withDurationAfterStart_with_negative_duration():void
+ {
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var duration:Duration = new Duration(-DURATION_MILLIS);
+
+ interval.withDurationAfterStart(duration);
}
[Test]
- public function withStart():void
+ public function withDurationBeforeEnd_with_null():void
{
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var zero:Interval = interval.withDurationBeforeEnd(null);
+ assertThat(".startMillis", zero.startMillis, equalTo(END_MILLIS));
+ assertThat(".endMillis", zero.endMillis, equalTo(END_MILLIS));
}
[Test]
- public function withEnd():void
+ public function withDurationBeforeEnd_with_positive_duration():void
{
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var duration:Duration = new Duration(DURATION_MILLIS);
+ var after:Interval = interval.withDurationBeforeEnd(duration);
+
+ assertThat(".startMillis", after.startMillis, equalTo(END_MILLIS - DURATION_MILLIS));
+ assertThat(".endMillis", after.endMillis, equalTo(END_MILLIS));
+ }
+ [Test(expected="ArgumentError")]
+ public function withDurationBeforeEnd_with_negative_duration():void
+ {
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var duration:Duration = new Duration(-DURATION_MILLIS);
+
+ interval.withDurationBeforeEnd(duration);
}
[Test]
public function withStartMillis():void
{
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var result:Interval = interval.withStartMillis(START_MILLIS - 1);
+
+ assertThat(".startMillis", result.startMillis, equalTo(START_MILLIS - 1));
+ assertThat(".endMillis", result.endMillis, equalTo(END_MILLIS));
+ assertThat("returns new Interval", result, not(equalTo(interval)));
+ }
+
+ [Test]
+ public function withEndMillis():void
+ {
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var result:Interval = interval.withEndMillis(END_MILLIS - 1);
+
+ assertThat(".startMillis", result.startMillis, equalTo(START_MILLIS));
+ assertThat(".endMillis", result.endMillis, equalTo(END_MILLIS - 1));
+ assertThat("returns new Interval", result, not(equalTo(interval)));
+ }
+
+ [Ignore(description="requires a millis provider")]
+ [Test]
+ public function withStart_with_null():void
+ {
+
+ }
+
+ [Test]
+ public function withStart_with_instant():void
+ {
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var instant:Instant = new Instant(START_MILLIS - 1);
+ var result:Interval = interval.withStart(instant);
+ assertThat(".startMillis", result.startMillis, equalTo(START_MILLIS - 1))
+ assertThat(".endMillis", result.endMillis, equalTo(END_MILLIS));
+ assertThat("returns new Interval", result, not(equalTo(interval)));
}
+ [Ignore(description="requires a millis provider")]
[Test]
- public function withEndMillis():void
+ public function withEnd_with_null():void
{
}
+
+ [Test]
+ public function withEnd_with_instant():void
+ {
+ var interval:Interval = new Interval(START_MILLIS, END_MILLIS);
+ var instant:Instant = new Instant(END_MILLIS + 1);
+ var result:Interval = interval.withEnd(instant);
+
+ assertThat(".startMillis", result.startMillis, equalTo(START_MILLIS))
+ assertThat(".endMillis", result.endMillis, equalTo(END_MILLIS + 1));
+ assertThat("returns new Interval", result, not(equalTo(interval)));
+ }
}
}

No commit comments for this range

Something went wrong with that request. Please try again.