Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/main/java/org/apache/commons/lang3/time/StopWatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public StopWatch(final String message) {
* @since 3.10
*/
public String formatSplitTime() {
return DurationFormatUtils.formatDurationHMS(DurationUtils.toMillisInt(getSplitDuration()));
return DurationFormatUtils.formatDurationHMS(DurationUtils.toMillisLong(getSplitDuration()));
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ void testFormatSplitTime() {
assertTrue(formatSplitTime.startsWith(ZERO_HOURS_PREFIX), "formatSplitTime");
}

@Test
void testFormatSplitTimeExceedingIntMillis() throws Exception {
final StopWatch watch = StopWatch.createStarted();
// Backdate the start so the split spans more than Integer.MAX_VALUE milliseconds (about 24.86 days).
FieldUtils.writeField(watch, "startTimeNanos", System.nanoTime() - TimeUnit.DAYS.toNanos(30), true);
watch.split();
final long splitMillis = watch.getSplitDuration().toMillis();
assertTrue(splitMillis > Integer.MAX_VALUE, "precondition: split must exceed Integer.MAX_VALUE millis");
assertEquals(DurationFormatUtils.formatDurationHMS(splitMillis), watch.formatSplitTime(), "formatSplitTime");
}

@Test
void testFormatSplitTimeWithMessage() {
final StopWatch watch = new StopWatch(MESSAGE);
Expand Down
Loading