drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paul-rogers <...@git.apache.org>
Subject [GitHub] drill pull request #739: DRILL-5230: Translation of millisecond duration int...
Date Fri, 03 Feb 2017 17:44:23 GMT
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/739#discussion_r99385390
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/TableBuilder.java
---
    @@ -56,6 +47,30 @@ public TableBuilder(final String[] columns) {
         sb.append("</tr>\n");
       }
     
    +  /**
    +   * Representation of a millisecond duration in a short readable text
    +   * @param millis  Duration in milliseconds
    +   * @return        Human-Readable Duration Time
    +   */
    +  public String shortDurationFormat(long millis) {
    +    long days = TimeUnit.MILLISECONDS.toDays(millis);
    +    long hours = TimeUnit.MILLISECONDS.toHours(millis) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(millis));
    +    long minutes = TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis));
    +    long seconds = TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis));
    +    long milliSeconds = millis - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(millis));
    +    String formattedDuration = "";
    +    if (days >= 1) {
    +      formattedDuration = days + "d" + hours + "h" + minutes + "m";
    +    } else if (hours >= 1) {
    +      formattedDuration = hours + "h" + minutes + "m";
    +    } else if (minutes >= 1) {
    +      formattedDuration = minutes + "m" + seconds + "s";
    +    } else {
    +      formattedDuration = seconds + "." + milliSeconds + "s";
    +    }
    +    return formattedDuration;
    --- End diff --
    
    A nit, but the code is clearer if you do:
    
    ```
    if (cond1) {
        return expr1;
    } else if (cond2) {
        return expr2;
    } else {
        return expr3;
    }
    ```
    
    The above eliminates the temp variable and makes it very clear what is happening.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message