You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/11/16 03:58:53 UTC

[GitHub] [iceberg] aokolnychyi commented on a diff in pull request #6199: API, Core: Move micros and days conversions to DateTimeUtil

aokolnychyi commented on code in PR #6199:
URL: https://github.com/apache/iceberg/pull/6199#discussion_r1023481066


##########
api/src/main/java/org/apache/iceberg/transforms/Dates.java:
##########
@@ -50,24 +48,19 @@ public Integer apply(Integer days) {
         return null;
       }
 
-      if (granularity == ChronoUnit.DAYS) {
-        return days;
-      }
-
-      if (days >= 0) {
-        LocalDate date = EPOCH.plusDays(days);
-        return (int) granularity.between(EPOCH, date);
-      } else {
-        // add 1 day to the value to account for the case where there is exactly 1 unit between the
-        // date and epoch because the result will always be decremented.
-        LocalDate date = EPOCH.plusDays(days + 1);
-        return (int) granularity.between(EPOCH, date) - 1;
+      switch (granularity) {
+        case YEARS:
+          return DateTimeUtil.daysToYears(days);
+        case MONTHS:
+          return DateTimeUtil.daysToMonths(days);
+        case DAYS:
+          return days;
+        default:
+          throw new UnsupportedOperationException("Unsupported time unit: " + granularity);

Review Comment:
   This block is now similar to `toHumanString` below.



-- 
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: issues-unsubscribe@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org