Util { public static Date parseUtcTimestamp(final String timestampStr) { Calendar calendar = Calendar.getInstance(UTC_TZ); calendar.clear(); calendar.setTimeZone(UTC_TZ); int year = Integer.parseInt(timestampStr.substring(0, 4)); int month = Integer.parseInt(timestampStr.substring(5, 7)); int day = Integer.parseInt(timestampStr.substring(8, 10)); int hour = Integer.parseInt(timestampStr.substring(11, 13)); int minute = Integer.parseInt(timestampStr.substring(14, 16)); int second = Integer.parseInt(timestampStr.substring(17)); calendar.set(year, month - 1, day, hour, minute, second); return calendar.getTime(); }  static Date parseUtcTimestamp(final String timestampStr); static Long parseUtcTimestampAsLong(final String timestampStr); static String formatUtcTimestamp(final Date timestamp); static String formatUtcTimestamp(final Long timestamp); static final String MYNAME; static final String UTF8; }
@Test (enabled = false) public void testParseUtcTimestamp() { fail("Not yet implemented"); }
@Test public void testParseUtcTimestampNew() throws ParseException { String timeStamp = "1984-03-22 12:34:56"; Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); calendar.setTime(dateFormat.parse(timeStamp)); for (int i = 0; i < 100000; i++) { calendar.roll(Calendar.SECOND, true); if (calendar.get(Calendar.SECOND) == 0) { calendar.roll(Calendar.MINUTE, true); } if (calendar.get(Calendar.MINUTE) == 0) { calendar.roll(Calendar.HOUR_OF_DAY, true); } if (calendar.get(Calendar.HOUR_OF_DAY) == 0) { calendar.roll(Calendar.DAY_OF_YEAR, true); } String tmpTime = dateFormat.format(calendar.getTime()); Date orgDate = UtilOld.parseUtcTimestamp(tmpTime); Date newDate = Util.parseUtcTimestamp(tmpTime); assertEquals(orgDate, newDate); } for (int i = 0; i < 100000; i++) { calendar.roll(Calendar.DAY_OF_YEAR, true); if (calendar.get(Calendar.DAY_OF_YEAR) == 1) { calendar.roll(Calendar.YEAR, true); } String tmpTime = dateFormat.format(calendar.getTime()); Date orgDate = UtilOld.parseUtcTimestamp(tmpTime); Date newDate = Util.parseUtcTimestamp(tmpTime); assertEquals(orgDate, newDate); } }