srowen commented on a change in pull request #26177: [SPARK-29520][SS] Fix
checks of negative intervals
URL: https://github.com/apache/spark/pull/26177#discussion_r337091806
##########
File path:
common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java
##########
@@ -409,4 +410,25 @@ private void appendUnit(StringBuilder sb, long value,
String unit) {
sb.append(' ').append(value).append(' ').append(unit).append('s');
}
}
+
+ /**
+ * Gets interval duration
+ * @param daysPerMonth the number of days per one month
+ * @param targetUnit time units of the result
+ * @return duration in the specified time units
+ */
+ public long getDuration(int daysPerMonth, TimeUnit targetUnit) {
+ long monthsDuration = Math.multiplyExact(daysPerMonth * MICROS_PER_DAY,
months);
+ long result = Math.addExact(microseconds, monthsDuration);
+ return targetUnit.convert(result, TimeUnit.MICROSECONDS);
+ }
+
+ /**
+ * Checks the interval is negative
+ * @param daysPerMonth the number of days per one month
+ * @return true if duration of the given interval is less than 0 otherwise
false
+ */
+ public boolean isNegative(int daysPerMonth) {
Review comment:
I wouldn't bother with a big refactoring here. Whatever is consistent. But
yeah you can make it static at least?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]