From bafb7f78c097bc3f815095050150476d35322c14 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 1 May 2009 19:34:38 +0000 Subject: [PATCH] Added elapsedSeconds(). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5764 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/java/com/threerings/util/TimeUtil.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/java/com/threerings/util/TimeUtil.java b/src/java/com/threerings/util/TimeUtil.java index 779834b63..2674b4213 100644 --- a/src/java/com/threerings/util/TimeUtil.java +++ b/src/java/com/threerings/util/TimeUtil.java @@ -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"