@Test public void testToLong() throws Exception { assertEquals(-1, TimeConv.toLong(null)); TimeConv.setTimeZone("GMT+1"); DateAndTime time = new DateAndTime("1970-01-08T16:33:35Z"); assertEquals(660815000, TimeConv.toLong(time)); TimeConv.setTimeZone("GMT+2"); time = new DateAndTime("1970-01-08T17:33:35Z"); assertEquals(660815000, TimeConv.toLong(time)); DateAndTime dateMock = mock(DateAndTime.class); when(dateMock.getValue()).thenReturn(null); assertEquals(-1, TimeConv.toLong(dateMock)); when(dateMock.getValue()).thenReturn(""); assertEquals(-1, TimeConv.toLong(dateMock)); time = mock(DateAndTime.class); when(time.getValue()).thenReturn("temp"); exception.expect(Exception.class); assertEquals(-1, TimeConv.toLong(time)); }
public static synchronized long toLong(DateAndTime dateAndTime) { if (dateAndTime == null || dateAndTime.getValue() == null || dateAndTime.getValue().isEmpty()) { return -1; } Calendar calendar = Calendar.getInstance(); try { calendar.setTime(DF.parse(dateAndTime.getValue())); } catch (ParseException e) { throw new IllegalArgumentException("Unrecognized date and time format: \"" + dateAndTime.getValue() + "\""); } return calendar.getTimeInMillis(); }
TimeConv { public static synchronized long toLong(DateAndTime dateAndTime) { if (dateAndTime == null || dateAndTime.getValue() == null || dateAndTime.getValue().isEmpty()) { return -1; } Calendar calendar = Calendar.getInstance(); try { calendar.setTime(DF.parse(dateAndTime.getValue())); } catch (ParseException e) { throw new IllegalArgumentException("Unrecognized date and time format: \"" + dateAndTime.getValue() + "\""); } return calendar.getTimeInMillis(); } }
TimeConv { public static synchronized long toLong(DateAndTime dateAndTime) { if (dateAndTime == null || dateAndTime.getValue() == null || dateAndTime.getValue().isEmpty()) { return -1; } Calendar calendar = Calendar.getInstance(); try { calendar.setTime(DF.parse(dateAndTime.getValue())); } catch (ParseException e) { throw new IllegalArgumentException("Unrecognized date and time format: \"" + dateAndTime.getValue() + "\""); } return calendar.getTimeInMillis(); } private  TimeConv(); }
TimeConv { public static synchronized long toLong(DateAndTime dateAndTime) { if (dateAndTime == null || dateAndTime.getValue() == null || dateAndTime.getValue().isEmpty()) { return -1; } Calendar calendar = Calendar.getInstance(); try { calendar.setTime(DF.parse(dateAndTime.getValue())); } catch (ParseException e) { throw new IllegalArgumentException("Unrecognized date and time format: \"" + dateAndTime.getValue() + "\""); } return calendar.getTimeInMillis(); } private  TimeConv(); static synchronized DateAndTime toDt(long currentTime); static synchronized void setTimeZone(String timeZone); static synchronized long toLong(DateAndTime dateAndTime); }
TimeConv { public static synchronized long toLong(DateAndTime dateAndTime) { if (dateAndTime == null || dateAndTime.getValue() == null || dateAndTime.getValue().isEmpty()) { return -1; } Calendar calendar = Calendar.getInstance(); try { calendar.setTime(DF.parse(dateAndTime.getValue())); } catch (ParseException e) { throw new IllegalArgumentException("Unrecognized date and time format: \"" + dateAndTime.getValue() + "\""); } return calendar.getTimeInMillis(); } private  TimeConv(); static synchronized DateAndTime toDt(long currentTime); static synchronized void setTimeZone(String timeZone); static synchronized long toLong(DateAndTime dateAndTime);  }