package com.futurice.android.reservator.model;

public class TimeSpan {
	private DateTime start, end;

	public TimeSpan(DateTime start, DateTime end){
		this.start = start;
		this.end = end;
		if(start.after(end)){
			throw new IllegalArgumentException("No negative time allowed");
		}
	}
	public TimeSpan(DateTime start, int units, int count){
		if(count < 0){
			throw new IllegalArgumentException("No negative time allowed");
		}
		if(start == null){
			start = new DateTime();
		}
		this.start = start;
		this.end = start.later(units, count);
		if(this.start.after(this.end)){
			throw new IllegalArgumentException("No negative time allowed");
		}
	}
	public final DateTime getStart(){
		return start;
	}
	public void setStart(DateTime start){

		this.start = start;
		if(start.after(end)){
			throw new IllegalArgumentException("No negative time allowed");
		}
	}
	public final DateTime getEnd() {
		return end;
	}
	public void setEnd(DateTime end) {
		this.end = end;
		if(start.after(end)){
			throw new IllegalArgumentException("No negative time allowed");
		}
	}
	public long getLength(){
		long startMillis = start.getTimeInMillis();
		long endMillis = end.getTimeInMillis();
		return endMillis - startMillis;
	}

	@Override
	public TimeSpan clone(){
		return new TimeSpan(start, end);
	}
}

@@ -272,33 +272,87 @@
 ive time allowed
-%22
+ -- %22 + start.toGMTString() + %22 - %22 + end.toGMTString()
 );%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09pu
@@ -478,33 +478,52 @@
 ive time allowed
-%22
+ -- count: %22 + count
 );%0D%0A%09%09%7D%0D%0A%09%09if(st
@@ -948,32 +948,44 @@
 ive time allowed
+ -- setStart
 %22);%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09p
@@ -1109,32 +1109,32 @@
 t.after(end))%7B%0D%0A
-
 %09%09%09throw new Ill
@@ -1172,32 +1172,42 @@
 ive time allowed
+ -- setEnd
 %22);%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09p

add more verbose messages in exceptions thrown by timespan