saxenapranav commented on code in PR #5508:
URL: https://github.com/apache/hadoop/pull/5508#discussion_r1147315190


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/utils/CachedSASToken.java:
##########
@@ -114,8 +125,20 @@ private static OffsetDateTime getExpiry(String token) {
     OffsetDateTime seDate = OffsetDateTime.MIN;
     try {
       seDate = OffsetDateTime.parse(seValue, DateTimeFormatter.ISO_DATE_TIME);
-    } catch (DateTimeParseException ex) {
-      LOG.error("Error parsing se query parameter ({}) from SAS.", seValue, 
ex);
+    } catch (DateTimeParseException dateTimeException) {
+      try {
+        TemporalAccessor dt = ISO_DATE_MIDNIGHT.parseBest(seValue, 
OffsetDateTime::from, LocalDateTime::from);
+        if (dt instanceof OffsetDateTime) {
+          seDate = (OffsetDateTime) dt;
+        } else if (dt instanceof LocalDateTime) {
+          seDate = ((LocalDateTime) dt).atOffset(ZoneOffset.UTC);
+        } else {
+          throw dateTimeException;
+        }
+      } catch (DateTimeParseException dateOnlyException) {

Review Comment:
   Can we have something like:
   
   `private static final DateTimeFormatter[] formatters;`
   
   ```
   private OffsetDateTime  getParsedDateTime(String dateTime) {
       for(DateTimeFormatter formatter : formatters) {
         try {
           TemporalAccessor temporalAccessor = formatter.parseBest(dateTime);
           if(temporalAccessor instanceof OffsetDateTime) {
             return (OffsetDateTime) temporalAccessor; 
           }
           if(temporalAccessor instanceof LocalDateTime) {
             return ((LocalDateTime) temporalAccessor).atOffset(ZoneOffset.UTC);
           }
         } catch (DateTimeParseException e) {
           
         }
       }
       return null;
     }
   ```
   
   And from this method we will just call `seDate = getParsedDateTime(seValue);`
   
   This way I feel we can prevent nested code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to