Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b22f243
Generate benchmark results for JDK 8
MaxGekk Oct 24, 2019
c33710f
Generate benchmark results for JDK 11
MaxGekk Oct 24, 2019
ffa1bee
Initial implementation
MaxGekk Oct 25, 2019
a4c16a1
Add tests to IntervalUtilsSuite
MaxGekk Oct 25, 2019
f249f49
Optimize unit name matching
MaxGekk Oct 25, 2019
d077c87
Catch ArithmeticException
MaxGekk Oct 25, 2019
80f5a06
Generate benchmark results for JDK 8
MaxGekk Oct 25, 2019
479d5bd
Generate benchmark results for JDK 11
MaxGekk Oct 25, 2019
d68f41e
Merge remote-tracking branch 'remotes/origin/master' into string-to-i…
MaxGekk Oct 29, 2019
8e8e539
Merge remote-tracking branch 'remotes/origin/master' into string-to-i…
MaxGekk Nov 2, 2019
9dfb45d
Rebase on interval with days
MaxGekk Nov 2, 2019
8c3fb28
Merge remote-tracking branch 'remotes/origin/master' into string-to-i…
MaxGekk Nov 6, 2019
bc006a2
Refactor IntervalUtilsSuite to check fromString and stringToInterval
MaxGekk Nov 6, 2019
7515981
Bug fix: expect space after interval
MaxGekk Nov 6, 2019
78a2e8e
Use checkFromInvalidString
MaxGekk Nov 6, 2019
f61e6f8
Improve the multiple units test
MaxGekk Nov 6, 2019
dd8f2d1
Add a few units to the test
MaxGekk Nov 6, 2019
1204656
Return CalendarInterval from stringToInterval()
MaxGekk Nov 6, 2019
a2d91c3
Support fraction of seconds
MaxGekk Nov 6, 2019
94bd39b
Fix for negative values
MaxGekk Nov 6, 2019
98dd44f
Checks only second can have fractions
MaxGekk Nov 6, 2019
0cd7e88
Regen benchmark results for JDK 8
MaxGekk Nov 6, 2019
107d16c
Regen benchmark results for JDK 11
MaxGekk Nov 6, 2019
8dd9518
Address Wenchen's comments + change behavior for fractions
MaxGekk Nov 6, 2019
464eacc
Improve comments
MaxGekk Nov 6, 2019
dbad971
Unify structure
MaxGekk Nov 6, 2019
527b00e
Remove exact functions in fraction parsing
MaxGekk Nov 6, 2019
5e96a0e
Replace magic numbers
MaxGekk Nov 6, 2019
2222f13
Replace 100000000 by NANOS_PER_SECOND / 10
MaxGekk Nov 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Catch ArithmeticException
  • Loading branch information
MaxGekk committed Oct 25, 2019
commit d077c87ff94ba88e84cb1bbcdb6b1289f31e4470
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ object IntervalUtils {
currentValue = 0
case POSITIVE_VALUE_TO_LONG | NEGATIVE_VALUE_TO_LONG =>
if ('0' <= b && b <= '9') {
currentValue = Math.addExact(Math.multiplyExact(10, currentValue), (b - '0'))
try {
currentValue = Math.addExact(Math.multiplyExact(10, currentValue), (b - '0'))
} catch {
case _: ArithmeticException => return None
}
} else if (b == ' ') {
if (state == NEGATIVE_VALUE_TO_LONG) {
currentValue = -currentValue
Expand All @@ -204,45 +208,51 @@ object IntervalUtils {
if (b == ' ') {
i += 1
} else {
b match {
case 'y' if s.matchAt(yearStr, i) =>
months = Math.addExact(months, Math.multiplyExact(12, currentValue))
i += yearStr.numBytes()
case 'w' if s.matchAt(weekStr, i) =>
val daysUs = Math.multiplyExact(
Math.multiplyExact(7, currentValue),
DateTimeUtils.MICROS_PER_DAY)
microseconds = Math.addExact(microseconds, daysUs)
i += weekStr.numBytes()
case 'd' if s.matchAt(dayStr, i) =>
val daysUs = Math.multiplyExact(currentValue, DateTimeUtils.MICROS_PER_DAY)
microseconds = Math.addExact(microseconds, daysUs)
i += dayStr.numBytes()
case 'h' if s.matchAt(hourStr, i) =>
val hoursUs = Math.multiplyExact(currentValue, MICROS_PER_HOUR)
microseconds = Math.addExact(microseconds, hoursUs)
i += hourStr.numBytes()
case 's' if s.matchAt(secondStr, i) =>
val secondsUs = Math.multiplyExact(currentValue, DateTimeUtils.MICROS_PER_SECOND)
microseconds = Math.addExact(microseconds, secondsUs)
i += secondStr.numBytes()
case 'm' =>
if (s.matchAt(monthStr, i)) {
months = Math.addExact(months, currentValue)
i += monthStr.numBytes()
} else if (s.matchAt(minuteStr, i)) {
val minutesUs = Math.multiplyExact(currentValue, MICROS_PER_MINUTE)
microseconds = Math.addExact(microseconds, minutesUs)
i += minuteStr.numBytes()
} else if (s.matchAt(millisStr, i)) {
val millisUs = Math.multiplyExact(currentValue, DateTimeUtils.MICROS_PER_MILLIS)
microseconds = Math.addExact(microseconds, millisUs)
i += millisStr.numBytes()
} else if (s.matchAt(microsStr, i)) {
microseconds = Math.addExact(microseconds, currentValue)
i += microsStr.numBytes()
} else return None
case _ => return None
try {
b match {
case 'y' if s.matchAt(yearStr, i) =>
months = Math.addExact(months, Math.multiplyExact(12, currentValue))
i += yearStr.numBytes()
case 'w' if s.matchAt(weekStr, i) =>
val daysUs = Math.multiplyExact(
Math.multiplyExact(7, currentValue),
DateTimeUtils.MICROS_PER_DAY)
microseconds = Math.addExact(microseconds, daysUs)
i += weekStr.numBytes()
case 'd' if s.matchAt(dayStr, i) =>
val daysUs = Math.multiplyExact(currentValue, DateTimeUtils.MICROS_PER_DAY)
microseconds = Math.addExact(microseconds, daysUs)
i += dayStr.numBytes()
case 'h' if s.matchAt(hourStr, i) =>
val hoursUs = Math.multiplyExact(currentValue, MICROS_PER_HOUR)
microseconds = Math.addExact(microseconds, hoursUs)
i += hourStr.numBytes()
case 's' if s.matchAt(secondStr, i) =>
val secondsUs = Math.multiplyExact(currentValue, DateTimeUtils.MICROS_PER_SECOND)
microseconds = Math.addExact(microseconds, secondsUs)
i += secondStr.numBytes()
case 'm' =>
if (s.matchAt(monthStr, i)) {
months = Math.addExact(months, currentValue)
i += monthStr.numBytes()
} else if (s.matchAt(minuteStr, i)) {
val minutesUs = Math.multiplyExact(currentValue, MICROS_PER_MINUTE)
microseconds = Math.addExact(microseconds, minutesUs)
i += minuteStr.numBytes()
} else if (s.matchAt(millisStr, i)) {
val millisUs = Math.multiplyExact(
currentValue,
DateTimeUtils.MICROS_PER_MILLIS)
microseconds = Math.addExact(microseconds, millisUs)
i += millisStr.numBytes()
} else if (s.matchAt(microsStr, i)) {
microseconds = Math.addExact(microseconds, currentValue)
i += microsStr.numBytes()
} else return None
case _ => return None
}
} catch {
case _: ArithmeticException => return None
}
state = UNIT_NAME_SUFFIX
}
Expand Down