src/share/classes/java/time/chrono/HijrahChronology.java

Print this page

        

*** 53,74 **** * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package java.time.calendar; import static java.time.temporal.ChronoField.EPOCH_DAY; import java.io.IOException; import java.io.Serializable; import java.text.ParseException; import java.time.DateTimeException; ! import java.time.temporal.Chrono; import java.time.temporal.ChronoField; - import java.time.temporal.ChronoLocalDate; - import java.time.temporal.Era; import java.time.temporal.TemporalAccessor; import java.time.temporal.ValueRange; import java.util.Arrays; import java.util.HashMap; import java.util.List; --- 53,75 ---- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package java.time.chrono; import static java.time.temporal.ChronoField.EPOCH_DAY; import java.io.IOException; import java.io.Serializable; import java.text.ParseException; + import java.time.Clock; import java.time.DateTimeException; ! import java.time.Instant; ! import java.time.LocalDate; ! import java.time.ZoneId; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; import java.time.temporal.ValueRange; import java.util.Arrays; import java.util.HashMap; import java.util.List;
*** 173,183 **** * <h3>Specification for implementors</h3> * This class is immutable and thread-safe. * * @since 1.8 */ ! public final class HijrahChrono extends Chrono<HijrahChrono> implements Serializable { /** * The Hijrah Calendar id. */ private final String typeId; --- 174,184 ---- * <h3>Specification for implementors</h3> * This class is immutable and thread-safe. * * @since 1.8 */ ! public final class HijrahChronology extends Chronology implements Serializable { /** * The Hijrah Calendar id. */ private final String typeId;
*** 189,203 **** /** * The singleton instance for the era before the current one - Before Hijrah - * which has the value 0. */ ! public static final Era<HijrahChrono> ERA_BEFORE_AH = HijrahEra.BEFORE_AH; /** * The singleton instance for the current era - Hijrah - which has the value 1. */ ! public static final Era<HijrahChrono> ERA_AH = HijrahEra.AH; /** * Serialization version. */ private static final long serialVersionUID = 3127340209035924785L; /** --- 190,204 ---- /** * The singleton instance for the era before the current one - Before Hijrah - * which has the value 0. */ ! public static final Era ERA_BEFORE_AH = HijrahEra.BEFORE_AH; /** * The singleton instance for the current era - Hijrah - which has the value 1. */ ! public static final Era ERA_AH = HijrahEra.AH; /** * Serialization version. */ private static final long serialVersionUID = 3127340209035924785L; /**
*** 417,427 **** /** * Singleton instance of the Hijrah chronology. * Must be initialized after the rest of the static initialization. */ ! public static final HijrahChrono INSTANCE; /** * Name data. */ static { --- 418,428 ---- /** * Singleton instance of the Hijrah chronology. * Must be initialized after the rest of the static initialization. */ ! public static final HijrahChronology INSTANCE; /** * Name data. */ static {
*** 437,459 **** DEFAULT_LEAP_MONTH_LENGTHS = Arrays.copyOf(LEAP_MONTH_LENGTH, LEAP_MONTH_LENGTH.length); DEFAULT_CYCLE_YEARS = Arrays.copyOf(CYCLEYEAR_START_DATE, CYCLEYEAR_START_DATE.length); ! INSTANCE = new HijrahChrono(); String extraCalendars = java.security.AccessController.doPrivileged( ! new sun.security.action.GetPropertyAction("java.time.calendar.HijrahCalendars")); if (extraCalendars != null) { try { // Split on whitespace String[] splits = extraCalendars.split("\\s"); for (String cal : splits) { if (!cal.isEmpty()) { // Split on the delimiter between typeId "-" calendarType String[] type = cal.split("-"); ! Chrono<?> cal2 = new HijrahChrono(type[0], type.length > 1 ? type[1] : type[0]); } } } catch (Exception ex) { // Log the error // ex.printStackTrace(); --- 438,460 ---- DEFAULT_LEAP_MONTH_LENGTHS = Arrays.copyOf(LEAP_MONTH_LENGTH, LEAP_MONTH_LENGTH.length); DEFAULT_CYCLE_YEARS = Arrays.copyOf(CYCLEYEAR_START_DATE, CYCLEYEAR_START_DATE.length); ! INSTANCE = new HijrahChronology(); String extraCalendars = java.security.AccessController.doPrivileged( ! new sun.security.action.GetPropertyAction("java.time.chrono.HijrahCalendars")); if (extraCalendars != null) { try { // Split on whitespace String[] splits = extraCalendars.split("\\s"); for (String cal : splits) { if (!cal.isEmpty()) { // Split on the delimiter between typeId "-" calendarType String[] type = cal.split("-"); ! Chronology cal2 = new HijrahChronology(type[0], type.length > 1 ? type[1] : type[0]); } } } catch (Exception ex) { // Log the error // ex.printStackTrace();
*** 462,480 **** } /** * Restricted constructor. */ ! private HijrahChrono() { this("Hijrah", "islamicc"); } /** ! * Constructor for name and type HijrahChrono. * @param id the id of the calendar * @param calendarType the calendar type */ ! private HijrahChrono(String id, String calendarType) { this.typeId = id; this.calendarType = calendarType; ADJUSTED_CYCLES = new long[MAX_ADJUSTED_CYCLE]; for (int i = 0; i < ADJUSTED_CYCLES.length; i++) { --- 463,481 ---- } /** * Restricted constructor. */ ! private HijrahChronology() { this("Hijrah", "islamicc"); } /** ! * Constructor for name and type HijrahChronology. * @param id the id of the calendar * @param calendarType the calendar type */ ! private HijrahChronology(String id, String calendarType) { this.typeId = id; this.calendarType = calendarType; ADJUSTED_CYCLES = new long[MAX_ADJUSTED_CYCLE]; for (int i = 0; i < ADJUSTED_CYCLES.length; i++) {
*** 505,516 **** //----------------------------------------------------------------------- /** * Gets the ID of the chronology - 'Hijrah'. * <p> ! * The ID uniquely identifies the {@code Chrono}. ! * It can be used to lookup the {@code Chrono} using {@link #of(String)}. * * @return the chronology ID - 'Hijrah' * @see #getCalendarType() */ @Override --- 506,517 ---- //----------------------------------------------------------------------- /** * Gets the ID of the chronology - 'Hijrah'. * <p> ! * The ID uniquely identifies the {@code Chronology}. ! * It can be used to lookup the {@code Chronology} using {@link #of(String)}. * * @return the chronology ID - 'Hijrah' * @see #getCalendarType() */ @Override
*** 521,531 **** /** * Gets the calendar type of the underlying calendar system - 'islamicc'. * <p> * The calendar type is an identifier defined by the * <em>Unicode Locale Data Markup Language (LDML)</em> specification. ! * It can be used to lookup the {@code Chrono} using {@link #of(String)}. * It can also be used as part of a locale, accessible via * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'. * * @return the calendar system type - 'islamicc' * @see #getId() --- 522,532 ---- /** * Gets the calendar type of the underlying calendar system - 'islamicc'. * <p> * The calendar type is an identifier defined by the * <em>Unicode Locale Data Markup Language (LDML)</em> specification. ! * It can be used to lookup the {@code Chronology} using {@link #of(String)}. * It can also be used as part of a locale, accessible via * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'. * * @return the calendar system type - 'islamicc' * @see #getId()
*** 535,561 **** return calendarType; } //----------------------------------------------------------------------- @Override ! public ChronoLocalDate<HijrahChrono> date(int prolepticYear, int month, int dayOfMonth) { return HijrahDate.of(this, prolepticYear, month, dayOfMonth); } @Override ! public ChronoLocalDate<HijrahChrono> dateYearDay(int prolepticYear, int dayOfYear) { return HijrahDate.of(this, prolepticYear, 1, 1).plusDays(dayOfYear - 1); // TODO better } @Override ! public ChronoLocalDate<HijrahChrono> date(TemporalAccessor temporal) { if (temporal instanceof HijrahDate) { return (HijrahDate) temporal; } return HijrahDate.ofEpochDay(this, temporal.getLong(EPOCH_DAY)); } //----------------------------------------------------------------------- @Override public boolean isLeapYear(long prolepticYear) { return isLeapYear0(prolepticYear); } --- 536,603 ---- return calendarType; } //----------------------------------------------------------------------- @Override ! public HijrahDate date(int prolepticYear, int month, int dayOfMonth) { return HijrahDate.of(this, prolepticYear, month, dayOfMonth); } @Override ! public HijrahDate dateYearDay(int prolepticYear, int dayOfYear) { return HijrahDate.of(this, prolepticYear, 1, 1).plusDays(dayOfYear - 1); // TODO better } @Override ! public HijrahDate date(TemporalAccessor temporal) { if (temporal instanceof HijrahDate) { return (HijrahDate) temporal; } return HijrahDate.ofEpochDay(this, temporal.getLong(EPOCH_DAY)); } + @Override + public HijrahDate date(Era era, int yearOfEra, int month, int dayOfMonth) { + return date(prolepticYear(era, yearOfEra), month, dayOfMonth); + + } + + @Override + public HijrahDate dateYearDay(Era era, int yearOfEra, int dayOfYear) { + return dateYearDay(prolepticYear(era, yearOfEra), dayOfYear); + } + + @Override + public HijrahDate dateNow() { + return dateNow(Clock.systemDefaultZone()); + } + + @Override + public HijrahDate dateNow(ZoneId zone) { + return dateNow(Clock.system(zone)); + } + + @Override + public HijrahDate dateNow(Clock clock) { + return date(LocalDate.now(clock)); + } + + @Override + public ChronoLocalDateTime<HijrahDate> localDateTime(TemporalAccessor temporal) { + return (ChronoLocalDateTime<HijrahDate>)super.localDateTime(temporal); + } + + @Override + public ChronoZonedDateTime<HijrahDate> zonedDateTime(TemporalAccessor temporal) { + return (ChronoZonedDateTime<HijrahDate>)super.zonedDateTime(temporal); + } + + @Override + public ChronoZonedDateTime<HijrahDate> zonedDateTime(Instant instant, ZoneId zone) { + return (ChronoZonedDateTime<HijrahDate>)super.zonedDateTime(instant, zone); + } + //----------------------------------------------------------------------- @Override public boolean isLeapYear(long prolepticYear) { return isLeapYear0(prolepticYear); }
*** 567,585 **** private static boolean isLeapYear0(long prolepticYear) { return (14 + 11 * (prolepticYear > 0 ? prolepticYear : -prolepticYear)) % 30 < 11; } @Override ! public int prolepticYear(Era<HijrahChrono> era, int yearOfEra) { if (era instanceof HijrahEra == false) { throw new DateTimeException("Era must be HijrahEra"); } return (era == HijrahEra.AH ? yearOfEra : 1 - yearOfEra); } @Override ! public Era<HijrahChrono> eraOf(int eraValue) { switch (eraValue) { case 0: return HijrahEra.BEFORE_AH; case 1: return HijrahEra.AH; --- 609,627 ---- private static boolean isLeapYear0(long prolepticYear) { return (14 + 11 * (prolepticYear > 0 ? prolepticYear : -prolepticYear)) % 30 < 11; } @Override ! public int prolepticYear(Era era, int yearOfEra) { if (era instanceof HijrahEra == false) { throw new DateTimeException("Era must be HijrahEra"); } return (era == HijrahEra.AH ? yearOfEra : 1 - yearOfEra); } @Override ! public Era eraOf(int eraValue) { switch (eraValue) { case 0: return HijrahEra.BEFORE_AH; case 1: return HijrahEra.AH;
*** 587,598 **** throw new DateTimeException("invalid Hijrah era"); } } @Override ! public List<Era<HijrahChrono>> eras() { ! return Arrays.<Era<HijrahChrono>>asList(HijrahEra.values()); } //----------------------------------------------------------------------- @Override public ValueRange range(ChronoField field) { --- 629,640 ---- throw new DateTimeException("invalid Hijrah era"); } } @Override ! public List<Era> eras() { ! return Arrays.<Era>asList(HijrahEra.values()); } //----------------------------------------------------------------------- @Override public ValueRange range(ChronoField field) {