Skip to content

Commit

Permalink
Handle case where input duration overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyy-dev committed Sep 15, 2024
1 parent c210a5c commit d3911ac
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,25 @@ public final class DurationParser<C> implements ArgumentParser<C, Duration>, Blo
}

final char timeUnit = input.charAt(cursor);
switch (timeUnit) {
case 'd':
duration = duration.plusDays(timeValue);
break;
case 'h':
duration = duration.plusHours(timeValue);
break;
case 'm':
duration = duration.plusMinutes(timeValue);
break;
case 's':
duration = duration.plusSeconds(timeValue);
break;
default:
return ArgumentParseResult.failure(new DurationParseException(input, commandContext));
try {
switch (timeUnit) {
case 'd':
duration = duration.plusDays(timeValue);
break;
case 'h':
duration = duration.plusHours(timeValue);
break;
case 'm':
duration = duration.plusMinutes(timeValue);
break;
case 's':
duration = duration.plusSeconds(timeValue);
break;
default:
return ArgumentParseResult.failure(new DurationParseException(input, commandContext));
}
} catch (final ArithmeticException ex) {
return ArgumentParseResult.failure(new DurationParseException(ex, input, commandContext));
}

// skip unit, reset rangeStart to start of next segment
Expand Down

0 comments on commit d3911ac

Please sign in to comment.