+ /**
+ * Convert the given timestamp parameters into a number of seconds
+ * @param inYear year
+ * @param inMonth month, beginning with 1
+ * @param inDay day of month, beginning with 1
+ * @param inHour hour of day, 0-24
+ * @param inMinute minute
+ * @param inSecond seconds
+ * @return number of seconds
+ */
+ private static long getSeconds(int inYear, int inMonth, int inDay, int inHour, int inMinute, int inSecond)
+ {
+ Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.YEAR, inYear);
+ cal.set(Calendar.MONTH, inMonth - 1);
+ cal.set(Calendar.DAY_OF_MONTH, inDay);
+ cal.set(Calendar.HOUR_OF_DAY, inHour);
+ cal.set(Calendar.MINUTE, inMinute);
+ cal.set(Calendar.SECOND, inSecond);
+ cal.set(Calendar.MILLISECOND, 0);
+ return cal.getTimeInMillis() / 1000;
+ }
+
+ /**
+ * Convert the given long parameters into a number of seconds
+ * @param inRawValue long value representing seconds / milliseconds
+ * @return number of seconds
+ */
+ private static long getSeconds(long inRawValue)
+ {
+ // check for each format possibility and pick nearest
+ long diff1 = Math.abs(SECS_SINCE_1970 - inRawValue);
+ long diff2 = Math.abs(MSECS_SINCE_1970 - inRawValue);
+ long diff3 = Math.abs(MSECS_SINCE_1990 - inRawValue);
+ long diff4 = Math.abs(SECS_SINCE_GARTRIP - inRawValue);
+
+ // Start off with "seconds since 1970" format
+ long smallestDiff = diff1;
+ long seconds = inRawValue;
+ // Now check millis since 1970
+ if (diff2 < smallestDiff)
+ {
+ // milliseconds since 1970
+ seconds = inRawValue / 1000L;
+ smallestDiff = diff2;
+ }
+ // Now millis since 1990
+ if (diff3 < smallestDiff)
+ {
+ // milliseconds since 1990
+ seconds = inRawValue / 1000L + TWENTY_YEARS_IN_SECS;
+ smallestDiff = diff3;
+ }
+ // Lastly, check gartrip offset
+ if (diff4 < smallestDiff)
+ {
+ // seconds since gartrip offset
+ seconds = inRawValue + GARTRIP_OFFSET;
+ }
+ return seconds;
+ }
+