AppUtils { public static Date getLocalDateForOffset(String timezoneOffset) { long currentTime = System.currentTimeMillis(); int myOffset = TimeZone.getDefault().getOffset(currentTime); int theirOffset = TimeZone.getTimeZone("GMT" + timezoneOffset).getOffset(currentTime); return new Date(currentTime - myOffset + theirOffset); }  static String getSymHome(); static String getCanonicalSymHome(String dirName); static String getHostName(); static String getPortNumber(); static String getProtocol(); static String getIpAddress(); static String getTimezoneOffset(); static Date getLocalDateForOffset(String timezoneOffset); static void sleep(long ms); static boolean isSystemPropertySet(String propName, boolean defaultValue); static boolean isPortAvailable(int port); static void unzip(InputStream in, File toDir); static String formatStackTrace(StackTraceElement[] stackTrace); static String formatStackTrace(StackTraceElement[] stackTrace, int indentSpaces, boolean indentFirst); final static String SYSPROP_HOST_NAME; final static String SYSPROP_PORT_NUMBER; final static String SYSPROP_IP_ADDRESS; }
@Test public void testGetLocalDateForOffset() { Date gmt = AppUtils.getLocalDateForOffset("+00:00"); Date plusFour = AppUtils.getLocalDateForOffset("+04:00"); Date minusFour = AppUtils.getLocalDateForOffset("-04:00"); long nearZero = plusFour.getTime() - gmt.getTime() - DateUtils.MILLIS_PER_HOUR * 4; assertTrue(nearZero + " was the left over ms", Math.abs(nearZero) < 1000); nearZero = plusFour.getTime() - minusFour.getTime() - DateUtils.MILLIS_PER_HOUR * 8; assertTrue(nearZero + " was the left over ms", Math.abs(nearZero) < 1000); }