DateTimeUtils { public static DateTime getDateTimeFromParameter(String dateTimeStr, DateTimeZone dtZone) { Preconditions.checkNotNull(dateTimeStr, "Both start and end time date parameters cannot be null"); Preconditions.checkArgument(dateTimeStr.length() == PARAMETER_WITH_DAY_DTF_STR.length() || dateTimeStr.length() == PARAMETER_WITH_HOUR_DTF_STR.length(), String.format("Time parameters have to be of the form %s or %s", PARAMETER_WITH_DAY_DTF_STR, PARAMETER_WITH_HOUR_DTF_STR)); DateTimeFormatter zoneAdjustedDtf; if (dateTimeStr.length() == PARAMETER_WITH_DAY_DTF_STR.length()) { zoneAdjustedDtf = PARAMETER_WITH_DAY_DTF.withZone(dtZone); } else { zoneAdjustedDtf = PARAMETER_WITH_HOUR_DTF.withZone(dtZone); } return zoneAdjustedDtf.parseDateTime(dateTimeStr).toDateTime(DateTimeZone.UTC); }  static DateTime getDateTimeFromParameter(String dateTimeStr, DateTimeZone dtZone); static Interval getIntervalFromParameters(String startTimeStr, String endTimeStr,
                                                     DateTimeZone dtZone); static final DateTimeFormatter PARAMETER_WITH_DAY_DTF; static final DateTimeFormatter PARAMETER_WITH_HOUR_DTF; }
@Test public void testGetDateTimeFromParameter() { DateTimeZone dtZone = DateTimeZone.forID(new ChatAlyticsConfig().timeZone); DateTime dateTime = DateTimeUtils.getDateTimeFromParameter("2015-01-01", dtZone); DateTime expectedDateTime = new DateTime(2015, 1, 1, 0, 0, dtZone).toDateTime(DateTimeZone.UTC); assertEquals(expectedDateTime, dateTime); }