var resolutions = require('time-resolutions');

function get_date(d){
	if(typeof(d)==="number"){
		d = new Date(d);
	}
	return d;
}

module.exports = function timestamp_range(start, end){
	if(arguments.length<=0){
		throw new Error('start and/or end needed for timestamp range');
	}

	start = get_date(start);
	end = get_date(end || new Date());

	var starttime = start.getTime();
	var endtime = end.getTime();

	if(endtime<starttime){
		throw new Error('end time cannot be before start time')
	}

	var gap = endtime-starttime;
	var resolution = resolutions.resolve(gap);
	var unit = resolutions[resolution];

	return {
		ms:gap,
		resolution:resolution,
		length:gap / unit
	}
}

@@ -648,16 +648,29 @@
 lution,%0A
+%09%09unit:unit,%0A
 %09%09length

include unit in response