Last active
December 16, 2023 09:12
-
-
Save onacit/9386c3c805d7da9ebb7b7814daf688b3 to your computer and use it in GitHub Desktop.
java.time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package p_9386c3c805d7da9ebb7b7814daf688b3; | |
import java.io.IOException; | |
import java.time.DateTimeException; | |
import java.time.chrono.Chronology; | |
import java.time.temporal.ChronoField; | |
import java.time.temporal.ValueRange; | |
import java.util.function.BiConsumer; | |
public class ValueRanges { | |
private static void valueRanges(final Chronology chronology, | |
final BiConsumer<? super ChronoField, ? super ValueRange> consumer) { | |
for (final ChronoField chronoField : ChronoField.values()) { | |
try { | |
final ValueRange valueRange = chronology.range(chronoField); | |
consumer.accept(chronoField, valueRange); | |
} catch (final DateTimeException dte) { | |
consumer.accept(chronoField, null); | |
} | |
} | |
} | |
@SuppressWarnings({"java:S106"}) | |
public static void main(final String... args) throws IOException { | |
for (final Chronology chronology : Chronology.getAvailableChronologies()) { | |
System.out.printf("Chronology: %1$s%n", chronology); | |
valueRanges(chronology, (f, r) -> { | |
System.out.printf("\t%1$23s: %2$s%n", f, r); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment