< prev index next >

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

Print this page




  73 
  74 import java.io.InvalidObjectException;
  75 import java.io.ObjectInputStream;
  76 import java.io.Serializable;
  77 import java.time.Clock;
  78 import java.time.DateTimeException;
  79 import java.time.Instant;
  80 import java.time.LocalDate;
  81 import java.time.LocalDateTime;
  82 import java.time.Month;
  83 import java.time.Period;
  84 import java.time.Year;
  85 import java.time.ZonedDateTime;
  86 import java.time.ZoneId;
  87 import java.time.ZoneOffset;
  88 import java.time.format.ResolverStyle;
  89 import java.time.temporal.ChronoField;
  90 import java.time.temporal.TemporalAccessor;
  91 import java.time.temporal.TemporalField;
  92 import java.time.temporal.ValueRange;
  93 import java.util.Arrays;
  94 import java.util.List;
  95 import java.util.Locale;
  96 import java.util.Map;
  97 import java.util.Objects;
  98 
  99 /**
 100  * The ISO calendar system.
 101  * <p>
 102  * This chronology defines the rules of the ISO calendar system.
 103  * This calendar system is based on the ISO-8601 standard, which is the
 104  * <i>de facto</i> world calendar.
 105  * <p>
 106  * The fields are defined as follows:
 107  * <ul>
 108  * <li>era - There are two eras, 'Current Era' (CE) and 'Before Current Era' (BCE).
 109  * <li>year-of-era - The year-of-era is the same as the proleptic-year for the current CE era.
 110  *  For the BCE era before the ISO epoch the year increases from 1 upwards as time goes backwards.
 111  * <li>proleptic-year - The proleptic year is the same as the year-of-era for the
 112  *  current era. For the previous era, years have zero, then negative values.
 113  * <li>month-of-year - There are 12 months in an ISO year, numbered from 1 to 12.


 475     @Override
 476     public boolean isLeapYear(long prolepticYear) {
 477         return ((prolepticYear & 3) == 0) && ((prolepticYear % 100) != 0 || (prolepticYear % 400) == 0);
 478     }
 479 
 480     @Override
 481     public int prolepticYear(Era era, int yearOfEra) {
 482         if (era instanceof IsoEra == false) {
 483             throw new ClassCastException("Era must be IsoEra");
 484         }
 485         return (era == IsoEra.CE ? yearOfEra : 1 - yearOfEra);
 486     }
 487 
 488     @Override
 489     public IsoEra eraOf(int eraValue) {
 490         return IsoEra.of(eraValue);
 491     }
 492 
 493     @Override
 494     public List<Era> eras() {
 495         return Arrays.<Era>asList(IsoEra.values());
 496     }
 497 
 498     //-----------------------------------------------------------------------
 499     /**
 500      * Resolves parsed {@code ChronoField} values into a date during parsing.
 501      * <p>
 502      * Most {@code TemporalField} implementations are resolved using the
 503      * resolve method on the field. By contrast, the {@code ChronoField} class
 504      * defines fields that only have meaning relative to the chronology.
 505      * As such, {@code ChronoField} date fields are resolved here in the
 506      * context of a specific chronology.
 507      * <p>
 508      * {@code ChronoField} instances on the ISO calendar system are resolved
 509      * as follows.
 510      * <ul>
 511      * <li>{@code EPOCH_DAY} - If present, this is converted to a {@code LocalDate}
 512      *  and all other date fields are then cross-checked against the date.
 513      * <li>{@code PROLEPTIC_MONTH} - If present, then it is split into the
 514      *  {@code YEAR} and {@code MONTH_OF_YEAR}. If the mode is strict or smart
 515      *  then the field is validated.




  73 
  74 import java.io.InvalidObjectException;
  75 import java.io.ObjectInputStream;
  76 import java.io.Serializable;
  77 import java.time.Clock;
  78 import java.time.DateTimeException;
  79 import java.time.Instant;
  80 import java.time.LocalDate;
  81 import java.time.LocalDateTime;
  82 import java.time.Month;
  83 import java.time.Period;
  84 import java.time.Year;
  85 import java.time.ZonedDateTime;
  86 import java.time.ZoneId;
  87 import java.time.ZoneOffset;
  88 import java.time.format.ResolverStyle;
  89 import java.time.temporal.ChronoField;
  90 import java.time.temporal.TemporalAccessor;
  91 import java.time.temporal.TemporalField;
  92 import java.time.temporal.ValueRange;

  93 import java.util.List;
  94 import java.util.Locale;
  95 import java.util.Map;
  96 import java.util.Objects;
  97 
  98 /**
  99  * The ISO calendar system.
 100  * <p>
 101  * This chronology defines the rules of the ISO calendar system.
 102  * This calendar system is based on the ISO-8601 standard, which is the
 103  * <i>de facto</i> world calendar.
 104  * <p>
 105  * The fields are defined as follows:
 106  * <ul>
 107  * <li>era - There are two eras, 'Current Era' (CE) and 'Before Current Era' (BCE).
 108  * <li>year-of-era - The year-of-era is the same as the proleptic-year for the current CE era.
 109  *  For the BCE era before the ISO epoch the year increases from 1 upwards as time goes backwards.
 110  * <li>proleptic-year - The proleptic year is the same as the year-of-era for the
 111  *  current era. For the previous era, years have zero, then negative values.
 112  * <li>month-of-year - There are 12 months in an ISO year, numbered from 1 to 12.


 474     @Override
 475     public boolean isLeapYear(long prolepticYear) {
 476         return ((prolepticYear & 3) == 0) && ((prolepticYear % 100) != 0 || (prolepticYear % 400) == 0);
 477     }
 478 
 479     @Override
 480     public int prolepticYear(Era era, int yearOfEra) {
 481         if (era instanceof IsoEra == false) {
 482             throw new ClassCastException("Era must be IsoEra");
 483         }
 484         return (era == IsoEra.CE ? yearOfEra : 1 - yearOfEra);
 485     }
 486 
 487     @Override
 488     public IsoEra eraOf(int eraValue) {
 489         return IsoEra.of(eraValue);
 490     }
 491 
 492     @Override
 493     public List<Era> eras() {
 494         return List.of(IsoEra.values());
 495     }
 496 
 497     //-----------------------------------------------------------------------
 498     /**
 499      * Resolves parsed {@code ChronoField} values into a date during parsing.
 500      * <p>
 501      * Most {@code TemporalField} implementations are resolved using the
 502      * resolve method on the field. By contrast, the {@code ChronoField} class
 503      * defines fields that only have meaning relative to the chronology.
 504      * As such, {@code ChronoField} date fields are resolved here in the
 505      * context of a specific chronology.
 506      * <p>
 507      * {@code ChronoField} instances on the ISO calendar system are resolved
 508      * as follows.
 509      * <ul>
 510      * <li>{@code EPOCH_DAY} - If present, this is converted to a {@code LocalDate}
 511      *  and all other date fields are then cross-checked against the date.
 512      * <li>{@code PROLEPTIC_MONTH} - If present, then it is split into the
 513      *  {@code YEAR} and {@code MONTH_OF_YEAR}. If the mode is strict or smart
 514      *  then the field is validated.


< prev index next >