Skip to content

Commit 04c56a9

Browse files
committed
Improve unpadded formatting
1 parent 48478b1 commit 04c56a9

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/instant/InstantPatternDynamicFormatter.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -726,15 +726,8 @@ private static ChronoUnit determinePrecision(int secondDigits, int digits) {
726726
return secondDigits > 0 ? ChronoUnit.SECONDS : ChronoUnit.FOREVER;
727727
}
728728

729-
private void formatSeconds(StringBuilder buffer, Instant instant) {
730-
switch (secondDigits) {
731-
case 1:
732-
buffer.append(instant.getEpochSecond() % 60L);
733-
break;
734-
case 2:
735-
formatPaddedSeconds(buffer, instant);
736-
break;
737-
}
729+
private static void formatUnpaddedSeconds(StringBuilder buffer, Instant instant) {
730+
buffer.append(instant.getEpochSecond() % 60L);
738731
}
739732

740733
private static void formatPaddedSeconds(StringBuilder buffer, Instant instant) {
@@ -768,8 +761,9 @@ private static void formatMillis(StringBuilder buffer, Instant instant) {
768761

769762
@Override
770763
InstantPatternFormatter createFormatter(Locale locale, TimeZone timeZone) {
771-
final BiConsumer<StringBuilder, Instant> secondDigitsFormatter =
772-
secondDigits == 2 ? SecondPatternSequence::formatPaddedSeconds : this::formatSeconds;
764+
final BiConsumer<StringBuilder, Instant> secondDigitsFormatter = secondDigits == 2
765+
? SecondPatternSequence::formatPaddedSeconds
766+
: SecondPatternSequence::formatUnpaddedSeconds;
773767
final BiConsumer<StringBuilder, Instant> fractionDigitsFormatter =
774768
fractionalDigits == 3 ? SecondPatternSequence::formatMillis : this::formatFractionalDigits;
775769
if (secondDigits == 0) {

0 commit comments

Comments
 (0)