66package io .opentelemetry .opamp .client .internal .connectivity .http ;
77
88import io .opentelemetry .opamp .client .internal .tools .SystemTime ;
9- import java .text .ParseException ;
10- import java .text .SimpleDateFormat ;
119import java .time .Duration ;
10+ import java .time .ZonedDateTime ;
11+ import java .time .format .DateTimeFormatter ;
1212import java .util .Locale ;
1313import java .util .regex .Pattern ;
1414
@@ -18,8 +18,8 @@ public final class RetryAfterParser {
1818 public static final Pattern DATE_PATTERN =
1919 Pattern .compile (
2020 "^([A-Za-z]{3}, [0-3][0-9] [A-Za-z]{3} [0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] GMT)$" );
21- private static final SimpleDateFormat dateFormat =
22- new SimpleDateFormat ("EEE, dd MMM yyyy HH:mm:ss z" , Locale .US );
21+ private static final DateTimeFormatter DATE_FORMAT =
22+ DateTimeFormatter . ofPattern ("EEE, dd MMM yyyy HH:mm:ss z" , Locale .US );
2323
2424 public static RetryAfterParser getInstance () {
2525 return new RetryAfterParser (SystemTime .getInstance ());
@@ -38,12 +38,7 @@ public Duration parse(String value) {
3838 throw new IllegalArgumentException ("Invalid Retry-After value: " + value );
3939 }
4040
41- @ SuppressWarnings ({"JavaUtilDate" , "ThrowSpecificExceptions" })
4241 private static long toMilliseconds (String value ) {
43- try {
44- return dateFormat .parse (value ).getTime ();
45- } catch (ParseException e ) {
46- throw new RuntimeException (e );
47- }
42+ return ZonedDateTime .parse (value , DATE_FORMAT ).toInstant ().toEpochMilli ();
4843 }
4944}
0 commit comments