< prev index next >

src/java.base/share/classes/java/time/chrono/JapaneseChronology.java

Print this page




  64 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
  65 import static java.time.temporal.ChronoUnit.DAYS;
  66 import static java.time.temporal.ChronoUnit.MONTHS;
  67 
  68 import java.io.InvalidObjectException;
  69 import java.io.ObjectInputStream;
  70 import java.io.Serializable;
  71 import java.time.Clock;
  72 import java.time.DateTimeException;
  73 import java.time.Instant;
  74 import java.time.LocalDate;
  75 import java.time.Year;
  76 import java.time.ZoneId;
  77 import java.time.format.ResolverStyle;
  78 import java.time.temporal.ChronoField;
  79 import java.time.temporal.TemporalAccessor;
  80 import java.time.temporal.TemporalAdjusters;
  81 import java.time.temporal.TemporalField;
  82 import java.time.temporal.UnsupportedTemporalTypeException;
  83 import java.time.temporal.ValueRange;
  84 import java.util.Arrays;
  85 import java.util.Calendar;
  86 import java.util.List;
  87 import java.util.Locale;
  88 import java.util.Map;
  89 
  90 import sun.util.calendar.CalendarSystem;
  91 import sun.util.calendar.LocalGregorianCalendar;
  92 
  93 /**
  94  * The Japanese Imperial calendar system.
  95  * <p>
  96  * This chronology defines the rules of the Japanese Imperial calendar system.
  97  * This calendar system is primarily used in Japan.
  98  * The Japanese Imperial calendar system is the same as the ISO calendar system
  99  * apart from the era-based year numbering.
 100  * <p>
 101  * Japan introduced the Gregorian calendar starting with Meiji 6.
 102  * Only Meiji and later eras are supported;
 103  * dates before Meiji 6, January 1 are not supported.
 104  * <p>


 362     }
 363 
 364     /**
 365      * Returns the calendar system era object from the given numeric value.
 366      *
 367      * See the description of each Era for the numeric values of:
 368      * {@link JapaneseEra#HEISEI}, {@link JapaneseEra#SHOWA},{@link JapaneseEra#TAISHO},
 369      * {@link JapaneseEra#MEIJI}), only Meiji and later eras are supported.
 370      *
 371      * @param eraValue  the era value
 372      * @return the Japanese {@code Era} for the given numeric era value
 373      * @throws DateTimeException if {@code eraValue} is invalid
 374      */
 375     @Override
 376     public JapaneseEra eraOf(int eraValue) {
 377         return JapaneseEra.of(eraValue);
 378     }
 379 
 380     @Override
 381     public List<Era> eras() {
 382         return Arrays.<Era>asList(JapaneseEra.values());
 383     }
 384 
 385     JapaneseEra getCurrentEra() {
 386         // Assume that the last JapaneseEra is the current one.
 387         JapaneseEra[] eras = JapaneseEra.values();
 388         return eras[eras.length - 1];
 389     }
 390 
 391     //-----------------------------------------------------------------------
 392     @Override
 393     public ValueRange range(ChronoField field) {
 394         switch (field) {
 395             case ALIGNED_DAY_OF_WEEK_IN_MONTH:
 396             case ALIGNED_DAY_OF_WEEK_IN_YEAR:
 397             case ALIGNED_WEEK_OF_MONTH:
 398             case ALIGNED_WEEK_OF_YEAR:
 399                 throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
 400             case YEAR_OF_ERA: {
 401                 Calendar jcal = Calendar.getInstance(LOCALE);
 402                 int startYear = getCurrentEra().getPrivateEra().getSinceDate().getYear();




  64 import static java.time.temporal.ChronoField.YEAR_OF_ERA;
  65 import static java.time.temporal.ChronoUnit.DAYS;
  66 import static java.time.temporal.ChronoUnit.MONTHS;
  67 
  68 import java.io.InvalidObjectException;
  69 import java.io.ObjectInputStream;
  70 import java.io.Serializable;
  71 import java.time.Clock;
  72 import java.time.DateTimeException;
  73 import java.time.Instant;
  74 import java.time.LocalDate;
  75 import java.time.Year;
  76 import java.time.ZoneId;
  77 import java.time.format.ResolverStyle;
  78 import java.time.temporal.ChronoField;
  79 import java.time.temporal.TemporalAccessor;
  80 import java.time.temporal.TemporalAdjusters;
  81 import java.time.temporal.TemporalField;
  82 import java.time.temporal.UnsupportedTemporalTypeException;
  83 import java.time.temporal.ValueRange;

  84 import java.util.Calendar;
  85 import java.util.List;
  86 import java.util.Locale;
  87 import java.util.Map;
  88 
  89 import sun.util.calendar.CalendarSystem;
  90 import sun.util.calendar.LocalGregorianCalendar;
  91 
  92 /**
  93  * The Japanese Imperial calendar system.
  94  * <p>
  95  * This chronology defines the rules of the Japanese Imperial calendar system.
  96  * This calendar system is primarily used in Japan.
  97  * The Japanese Imperial calendar system is the same as the ISO calendar system
  98  * apart from the era-based year numbering.
  99  * <p>
 100  * Japan introduced the Gregorian calendar starting with Meiji 6.
 101  * Only Meiji and later eras are supported;
 102  * dates before Meiji 6, January 1 are not supported.
 103  * <p>


 361     }
 362 
 363     /**
 364      * Returns the calendar system era object from the given numeric value.
 365      *
 366      * See the description of each Era for the numeric values of:
 367      * {@link JapaneseEra#HEISEI}, {@link JapaneseEra#SHOWA},{@link JapaneseEra#TAISHO},
 368      * {@link JapaneseEra#MEIJI}), only Meiji and later eras are supported.
 369      *
 370      * @param eraValue  the era value
 371      * @return the Japanese {@code Era} for the given numeric era value
 372      * @throws DateTimeException if {@code eraValue} is invalid
 373      */
 374     @Override
 375     public JapaneseEra eraOf(int eraValue) {
 376         return JapaneseEra.of(eraValue);
 377     }
 378 
 379     @Override
 380     public List<Era> eras() {
 381         return List.of(JapaneseEra.values());
 382     }
 383 
 384     JapaneseEra getCurrentEra() {
 385         // Assume that the last JapaneseEra is the current one.
 386         JapaneseEra[] eras = JapaneseEra.values();
 387         return eras[eras.length - 1];
 388     }
 389 
 390     //-----------------------------------------------------------------------
 391     @Override
 392     public ValueRange range(ChronoField field) {
 393         switch (field) {
 394             case ALIGNED_DAY_OF_WEEK_IN_MONTH:
 395             case ALIGNED_DAY_OF_WEEK_IN_YEAR:
 396             case ALIGNED_WEEK_OF_MONTH:
 397             case ALIGNED_WEEK_OF_YEAR:
 398                 throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
 399             case YEAR_OF_ERA: {
 400                 Calendar jcal = Calendar.getInstance(LOCALE);
 401                 int startYear = getCurrentEra().getPrivateEra().getSinceDate().getYear();


< prev index next >