Added elapsedSeconds().

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5764 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2009-05-01 19:34:38 +00:00
parent 34a99c26c0
commit bafb7f78c0
@@ -46,6 +46,19 @@ public class TimeUtil
// TODO: Weeks?, months?
protected static final byte MAX_UNIT = DAY;
/**
* Returns (in seconds) the time elapsed between the supplied start and end timestamps (which
* must be in milliseconds). Partial seconds are truncated, not rounded.
*/
public static int elapsedSeconds (long startStamp, long endStamp)
{
if (endStamp < startStamp) {
throw new IllegalArgumentException("End time must be after start time " +
"[start=" + startStamp + ", end=" + endStamp + "]");
}
return (int)((endStamp - startStamp)/1000L);
}
/**
* Get a translatable string specifying the magnitude of the specified duration. Results will
* be between "1 second" and "X hours", with all times rounded to the nearest unit. "0 units"