How to get the epoch-making limits of Java 8 timeline?

I am using the Java 8 Date and Time API in an application that uses the hijra and Gregorian chronology. The Hijrah calendar has limited range support and will throw a “date out of range” exception if I try to create a date outside this range (for example, using the zonedDateTime method of the Chronology class). I looked through the documentation, but could not find any official method that I could use to get the date range for the timeline. I managed to determine the maximum date in the past for the hijra chronology by checking when an exception is thrown, but this is not ideal, since I can use different versions of Java, and it seems that the supported date range may change in different java updates. Is there any official methodallowing you to get epoch-making restrictions in the chronology of Java 8, for example, hijra chronology? I appreciate any help. Thank.

+4
source share
1 answer

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

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 actual years are 1300-1600.

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

+4
source

All Articles