How to get epoch limits of Java 8 chronology?

I am using the Java 8 Date and Time API in an application that uses both the Hijrah and Gregorian chronologies. The Hijrah calendar has a limited range support and will throw a "date out of range" exception if I attempt to create a date outside this range (for example using the zonedDateTime method of the Chronology class). I searched the documentation but I couldn't find any official method I could use to get the supported date range for a Chronology. I managed to figure out the maximum date in the past for the Hijrah chronology by testing when an exception is thrown but this is not ideal since I may be using different java versions and it seems that the supported date range may change in different java updates. Is there any official method to get the epoch limits of a Java 8 chronology such as the Hijrah chronology? I appreciate any help. Thank you.

Jon Skeet
people
quotationmark

You can use the Chronology.range() method. For example:

import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;

public class Test {
    public static void main(String[] args) {
        Chronology hijrah = HijrahChronology.INSTANCE;
        ValueRange range = hijrah.range(ChronoField.YEAR);
        System.out.println(range.getMinimum());
        System.out.println(range.getMaximum());
    }
}

This shows that the valid years are 1300-1600.

It's not clear to me whether that means that the whole of the year 1300 and the whole of the year 1600 is valid, but I suspect so - you can probably write some experimental tests for that.

people

See more on this question at Stackoverflow