55 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 */
57 package java.time.chrono;
58
59 import java.io.InvalidObjectException;
60 import static java.time.temporal.ChronoField.PROLEPTIC_MONTH;
61 import static java.time.temporal.ChronoField.YEAR;
62
63 import java.io.ObjectInputStream;
64 import java.io.Serializable;
65 import java.time.Clock;
66 import java.time.DateTimeException;
67 import java.time.Instant;
68 import java.time.LocalDate;
69 import java.time.ZoneId;
70 import java.time.format.ResolverStyle;
71 import java.time.temporal.ChronoField;
72 import java.time.temporal.TemporalAccessor;
73 import java.time.temporal.TemporalField;
74 import java.time.temporal.ValueRange;
75 import java.util.Arrays;
76 import java.util.List;
77 import java.util.Locale;
78 import java.util.Map;
79
80 /**
81 * The Minguo calendar system.
82 * <p>
83 * This chronology defines the rules of the Minguo calendar system.
84 * This calendar system is primarily used in the Republic of China, often known as Taiwan.
85 * Dates are aligned such that {@code 0001-01-01 (Minguo)} is {@code 1912-01-01 (ISO)}.
86 * <p>
87 * The fields are defined as follows:
88 * <ul>
89 * <li>era - There are two eras, the current 'Republic' (ERA_ROC) and the previous era (ERA_BEFORE_ROC).
90 * <li>year-of-era - The year-of-era for the current era increases uniformly from the epoch at year one.
91 * For the previous era the year increases from one as time goes backwards.
92 * The value for the current era is equal to the ISO proleptic-year minus 1911.
93 * <li>proleptic-year - The proleptic year is the same as the year-of-era for the
94 * current era. For the previous era, years have zero, then negative values.
95 * The value is equal to the ISO proleptic-year minus 1911.
289 @Override
290 public boolean isLeapYear(long prolepticYear) {
291 return IsoChronology.INSTANCE.isLeapYear(prolepticYear + YEARS_DIFFERENCE);
292 }
293
294 @Override
295 public int prolepticYear(Era era, int yearOfEra) {
296 if (era instanceof MinguoEra == false) {
297 throw new ClassCastException("Era must be MinguoEra");
298 }
299 return (era == MinguoEra.ROC ? yearOfEra : 1 - yearOfEra);
300 }
301
302 @Override
303 public MinguoEra eraOf(int eraValue) {
304 return MinguoEra.of(eraValue);
305 }
306
307 @Override
308 public List<Era> eras() {
309 return Arrays.<Era>asList(MinguoEra.values());
310 }
311
312 //-----------------------------------------------------------------------
313 @Override
314 public ValueRange range(ChronoField field) {
315 switch (field) {
316 case PROLEPTIC_MONTH: {
317 ValueRange range = PROLEPTIC_MONTH.range();
318 return ValueRange.of(range.getMinimum() - YEARS_DIFFERENCE * 12L, range.getMaximum() - YEARS_DIFFERENCE * 12L);
319 }
320 case YEAR_OF_ERA: {
321 ValueRange range = YEAR.range();
322 return ValueRange.of(1, range.getMaximum() - YEARS_DIFFERENCE, -range.getMinimum() + 1 + YEARS_DIFFERENCE);
323 }
324 case YEAR: {
325 ValueRange range = YEAR.range();
326 return ValueRange.of(range.getMinimum() - YEARS_DIFFERENCE, range.getMaximum() - YEARS_DIFFERENCE);
327 }
328 }
329 return field.range();
|
55 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 */
57 package java.time.chrono;
58
59 import java.io.InvalidObjectException;
60 import static java.time.temporal.ChronoField.PROLEPTIC_MONTH;
61 import static java.time.temporal.ChronoField.YEAR;
62
63 import java.io.ObjectInputStream;
64 import java.io.Serializable;
65 import java.time.Clock;
66 import java.time.DateTimeException;
67 import java.time.Instant;
68 import java.time.LocalDate;
69 import java.time.ZoneId;
70 import java.time.format.ResolverStyle;
71 import java.time.temporal.ChronoField;
72 import java.time.temporal.TemporalAccessor;
73 import java.time.temporal.TemporalField;
74 import java.time.temporal.ValueRange;
75 import java.util.List;
76 import java.util.Locale;
77 import java.util.Map;
78
79 /**
80 * The Minguo calendar system.
81 * <p>
82 * This chronology defines the rules of the Minguo calendar system.
83 * This calendar system is primarily used in the Republic of China, often known as Taiwan.
84 * Dates are aligned such that {@code 0001-01-01 (Minguo)} is {@code 1912-01-01 (ISO)}.
85 * <p>
86 * The fields are defined as follows:
87 * <ul>
88 * <li>era - There are two eras, the current 'Republic' (ERA_ROC) and the previous era (ERA_BEFORE_ROC).
89 * <li>year-of-era - The year-of-era for the current era increases uniformly from the epoch at year one.
90 * For the previous era the year increases from one as time goes backwards.
91 * The value for the current era is equal to the ISO proleptic-year minus 1911.
92 * <li>proleptic-year - The proleptic year is the same as the year-of-era for the
93 * current era. For the previous era, years have zero, then negative values.
94 * The value is equal to the ISO proleptic-year minus 1911.
288 @Override
289 public boolean isLeapYear(long prolepticYear) {
290 return IsoChronology.INSTANCE.isLeapYear(prolepticYear + YEARS_DIFFERENCE);
291 }
292
293 @Override
294 public int prolepticYear(Era era, int yearOfEra) {
295 if (era instanceof MinguoEra == false) {
296 throw new ClassCastException("Era must be MinguoEra");
297 }
298 return (era == MinguoEra.ROC ? yearOfEra : 1 - yearOfEra);
299 }
300
301 @Override
302 public MinguoEra eraOf(int eraValue) {
303 return MinguoEra.of(eraValue);
304 }
305
306 @Override
307 public List<Era> eras() {
308 return List.of(MinguoEra.values());
309 }
310
311 //-----------------------------------------------------------------------
312 @Override
313 public ValueRange range(ChronoField field) {
314 switch (field) {
315 case PROLEPTIC_MONTH: {
316 ValueRange range = PROLEPTIC_MONTH.range();
317 return ValueRange.of(range.getMinimum() - YEARS_DIFFERENCE * 12L, range.getMaximum() - YEARS_DIFFERENCE * 12L);
318 }
319 case YEAR_OF_ERA: {
320 ValueRange range = YEAR.range();
321 return ValueRange.of(1, range.getMaximum() - YEARS_DIFFERENCE, -range.getMinimum() + 1 + YEARS_DIFFERENCE);
322 }
323 case YEAR: {
324 ValueRange range = YEAR.range();
325 return ValueRange.of(range.getMinimum() - YEARS_DIFFERENCE, range.getMaximum() - YEARS_DIFFERENCE);
326 }
327 }
328 return field.range();
|