@Test public void getTimeFromDateStringTest() { SimpleDateFormat dateFormatter = new SimpleDateFormat(RestUtils.HTTP_DATE_FORMAT, Locale.ENGLISH); dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); long curTime = System.currentTimeMillis(); Date curDate = new Date(curTime); String dateStr = dateFormatter.format(curDate); long epochTime = RestUtils.getTimeFromDateString(dateStr); long actualExpectedTime = (curTime / 1000L) * 1000; assertEquals("Time mismatch ", actualExpectedTime, epochTime); dateFormatter = new SimpleDateFormat(RestUtils.HTTP_DATE_FORMAT, Locale.CHINA); curTime = System.currentTimeMillis(); curDate = new Date(curTime); dateStr = dateFormatter.format(curDate); assertEquals("Should have returned null", null, RestUtils.getTimeFromDateString(dateStr)); assertEquals("Should have returned null", null, RestUtils.getTimeFromDateString("abc")); }
public static Long getTimeFromDateString(String dateString) { try { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); return dateFormatter.parse(dateString).getTime(); } catch (ParseException e) { logger.warn("Could not parse milliseconds from an HTTP date header ({}).", dateString); return null; } }
RestUtils { public static Long getTimeFromDateString(String dateString) { try { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); return dateFormatter.parse(dateString).getTime(); } catch (ParseException e) { logger.warn("Could not parse milliseconds from an HTTP date header ({}).", dateString); return null; } } }
RestUtils { public static Long getTimeFromDateString(String dateString) { try { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); return dateFormatter.parse(dateString).getTime(); } catch (ParseException e) { logger.warn("Could not parse milliseconds from an HTTP date header ({}).", dateString); return null; } }  }
RestUtils { public static Long getTimeFromDateString(String dateString) { try { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); return dateFormatter.parse(dateString).getTime(); } catch (ParseException e) { logger.warn("Could not parse milliseconds from an HTTP date header ({}).", dateString); return null; } }  static BlobProperties buildBlobProperties(Map<String, Object> args); static byte[] buildUserMetadata(Map<String, Object> args); static Map<String, String> buildUserMetadata(byte[] userMetadata); static GetBlobOptions buildGetBlobOptions(Map<String, Object> args, SubResource subResource,
      GetOption getOption, int blobSegmentIdx); static Pair<String, Long> buildContentRangeAndLength(ByteRange range, long blobSize,
      boolean resolveRangeOnEmptyBlob); static RequestPath getRequestPath(RestRequest restRequest); static Long getTimeFromDateString(String dateString); static long toSecondsPrecisionInMs(long ms); static GetOption getGetOption(RestRequest restRequest, GetOption defaultGetOption); static boolean isPrivate(Map<String, Object> args); static boolean isChunkUpload(Map<String, Object> args); static void ensureRequiredHeadersOrThrow(RestRequest restRequest, Set<String> requiredHeaders); static String getHeader(Map<String, ?> args, String header, boolean required); static Long getLongHeader(Map<String, ?> args, String header, boolean required); static T getNumericalHeader(Map<String, ?> args, String header, boolean required,
      Function<String, T> converter); static boolean getBooleanHeader(Map<String, Object> args, String header, boolean required); static Account getAccountFromArgs(Map<String, Object> args); static Container getContainerFromArgs(Map<String, Object> args); static void accountAndContainerNamePreconditionCheck(RestRequest restRequest); static boolean setUserMetadataHeaders(byte[] userMetadata, RestResponseChannel restResponseChannel); }
RestUtils { public static Long getTimeFromDateString(String dateString) { try { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); return dateFormatter.parse(dateString).getTime(); } catch (ParseException e) { logger.warn("Could not parse milliseconds from an HTTP date header ({}).", dateString); return null; } }  static BlobProperties buildBlobProperties(Map<String, Object> args); static byte[] buildUserMetadata(Map<String, Object> args); static Map<String, String> buildUserMetadata(byte[] userMetadata); static GetBlobOptions buildGetBlobOptions(Map<String, Object> args, SubResource subResource,
      GetOption getOption, int blobSegmentIdx); static Pair<String, Long> buildContentRangeAndLength(ByteRange range, long blobSize,
      boolean resolveRangeOnEmptyBlob); static RequestPath getRequestPath(RestRequest restRequest); static Long getTimeFromDateString(String dateString); static long toSecondsPrecisionInMs(long ms); static GetOption getGetOption(RestRequest restRequest, GetOption defaultGetOption); static boolean isPrivate(Map<String, Object> args); static boolean isChunkUpload(Map<String, Object> args); static void ensureRequiredHeadersOrThrow(RestRequest restRequest, Set<String> requiredHeaders); static String getHeader(Map<String, ?> args, String header, boolean required); static Long getLongHeader(Map<String, ?> args, String header, boolean required); static T getNumericalHeader(Map<String, ?> args, String header, boolean required,
      Function<String, T> converter); static boolean getBooleanHeader(Map<String, Object> args, String header, boolean required); static Account getAccountFromArgs(Map<String, Object> args); static Container getContainerFromArgs(Map<String, Object> args); static void accountAndContainerNamePreconditionCheck(RestRequest restRequest); static boolean setUserMetadataHeaders(byte[] userMetadata, RestResponseChannel restResponseChannel); static final String HTTP_DATE_FORMAT; static final String BYTE_RANGE_UNITS; static final String SIGNED_ID_PREFIX; static final String JSON_CONTENT_TYPE; }