You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/12/29 08:06:48 UTC

[GitHub] [cloudstack] DaanHoogland commented on a diff in pull request #7032: Allow users to inform timezones on APIs that have the date parameter

DaanHoogland commented on code in PR #7032:
URL: https://github.com/apache/cloudstack/pull/7032#discussion_r1058797856


##########
server/src/main/java/com/cloud/api/dispatch/ParamProcessWorker.java:
##########
@@ -335,13 +337,20 @@ private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object
             case DATE:
                 // This piece of code is for maintaining backward compatibility
                 // and support both the date formats(Bug 9724)
-                final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
-                if (isObjInNewDateFormat) {
+                try {
+                    field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));
+                    break;
+                } catch (ParseException parseException) {
+                    s_logger.debug(String.format("Could not parse date [%s] with timezone parser, trying to parse without timezone.", paramObj));
+                }

Review Comment:
   Can you put this, or even the full case DATE block in a separate method, please_



##########
server/src/main/java/com/cloud/api/dispatch/ParamProcessWorker.java:
##########
@@ -63,8 +63,10 @@
 public class ParamProcessWorker implements DispatchWorker {
 
     private static final Logger s_logger = Logger.getLogger(ParamProcessWorker.class.getName());
-    public final DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
-    public final DateFormat newInputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    private final String inputFormatString = "yyyy-MM-dd";
+    private final String newInputFormatString = "yyyy-MM-dd HH:mm:ss";
+    public final DateFormat inputFormat = new SimpleDateFormat(inputFormatString);
+    public final DateFormat newInputFormat = new SimpleDateFormat(newInputFormatString);

Review Comment:
   ```suggestion
       private final static String inputFormatString = "yyyy-MM-dd";
       private final static String newInputFormatString = "yyyy-MM-dd HH:mm:ss";
       public final static DateFormat inputFormat = new SimpleDateFormat(inputFormatString);
       public final static DateFormat newInputFormat = new SimpleDateFormat(newInputFormatString);
   ```



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org