< prev index next >

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

Print this page




  42  *    may be used to endorse or promote products derived from this software
  43  *    without specific prior written permission.
  44  *
  45  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  46  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  47  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  48  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  49  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  50  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  51  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  52  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  53  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  54  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  55  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  56  */
  57 
  58 package java.time.chrono;
  59 
  60 import static java.time.temporal.ChronoField.EPOCH_DAY;
  61 
  62 import java.io.File;
  63 import java.io.FileInputStream;
  64 import java.io.FilePermission;
  65 import java.io.IOException;
  66 import java.io.InputStream;
  67 import java.io.InvalidObjectException;
  68 import java.io.ObjectInputStream;
  69 import java.io.Serializable;
  70 import java.security.AccessController;
  71 import java.security.PrivilegedAction;
  72 import java.time.Clock;
  73 import java.time.DateTimeException;
  74 import java.time.Instant;
  75 import java.time.LocalDate;
  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.TemporalField;
  81 import java.time.temporal.ValueRange;
  82 import java.util.Arrays;
  83 import java.util.HashMap;
  84 import java.util.List;
  85 import java.util.Map;
  86 import java.util.Objects;
  87 import java.util.Properties;
  88 
  89 import sun.util.logging.PlatformLogger;
  90 
  91 /**
  92  * The Hijrah calendar is a lunar calendar supporting Islamic calendars.
  93  * <p>
  94  * The HijrahChronology follows the rules of the Hijrah calendar system. The Hijrah
  95  * calendar has several variants based on differences in when the new moon is
  96  * determined to have occurred and where the observation is made.
  97  * In some variants the length of each month is
  98  * computed algorithmically from the astronomical data for the moon and earth and
  99  * in others the length of the month is determined by an authorized sighting
 100  * of the new moon. For the algorithmically based calendars the calendar
 101  * can project into the future.
 102  * For sighting based calendars only historical data from past
 103  * sightings is available.
 104  * <p>
 105  * The length of each month is 29 or 30 days.
 106  * Ordinary years have 354 days; leap years have 355 days.


 495      * The Hijrah calendar system has only one era covering the
 496      * proleptic years greater than zero.
 497      * This method returns the singleton HijrahEra for the value 1.
 498      *
 499      * @param eraValue  the era value
 500      * @return the calendar system era, not null
 501      * @throws DateTimeException if unable to create the era
 502      */
 503     @Override
 504     public HijrahEra eraOf(int eraValue) {
 505         switch (eraValue) {
 506             case 1:
 507                 return HijrahEra.AH;
 508             default:
 509                 throw new DateTimeException("invalid Hijrah era");
 510         }
 511     }
 512 
 513     @Override
 514     public List<Era> eras() {
 515         return Arrays.<Era>asList(HijrahEra.values());
 516     }
 517 
 518     //-----------------------------------------------------------------------
 519     @Override
 520     public ValueRange range(ChronoField field) {
 521         checkCalendarInit();
 522         if (field instanceof ChronoField) {
 523             ChronoField f = field;
 524             switch (f) {
 525                 case DAY_OF_MONTH:
 526                     return ValueRange.of(1, 1, getMinimumMonthLength(), getMaximumMonthLength());
 527                 case DAY_OF_YEAR:
 528                     return ValueRange.of(1, getMaximumDayOfYear());
 529                 case ALIGNED_WEEK_OF_MONTH:
 530                     return ValueRange.of(1, 5);
 531                 case YEAR:
 532                 case YEAR_OF_ERA:
 533                     return ValueRange.of(getMinimumYear(), getMaximumYear());
 534                 case ERA:
 535                     return ValueRange.of(1, 1);




  42  *    may be used to endorse or promote products derived from this software
  43  *    without specific prior written permission.
  44  *
  45  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  46  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  47  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  48  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  49  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  50  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  51  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  52  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  53  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  54  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  55  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  56  */
  57 
  58 package java.time.chrono;
  59 
  60 import static java.time.temporal.ChronoField.EPOCH_DAY;
  61 


  62 import java.io.FilePermission;

  63 import java.io.InputStream;
  64 import java.io.InvalidObjectException;
  65 import java.io.ObjectInputStream;
  66 import java.io.Serializable;
  67 import java.security.AccessController;
  68 import java.security.PrivilegedAction;
  69 import java.time.Clock;
  70 import java.time.DateTimeException;
  71 import java.time.Instant;
  72 import java.time.LocalDate;
  73 import java.time.ZoneId;
  74 import java.time.format.ResolverStyle;
  75 import java.time.temporal.ChronoField;
  76 import java.time.temporal.TemporalAccessor;
  77 import java.time.temporal.TemporalField;
  78 import java.time.temporal.ValueRange;
  79 import java.util.Arrays;
  80 import java.util.HashMap;
  81 import java.util.List;
  82 import java.util.Map;

  83 import java.util.Properties;
  84 
  85 import sun.util.logging.PlatformLogger;
  86 
  87 /**
  88  * The Hijrah calendar is a lunar calendar supporting Islamic calendars.
  89  * <p>
  90  * The HijrahChronology follows the rules of the Hijrah calendar system. The Hijrah
  91  * calendar has several variants based on differences in when the new moon is
  92  * determined to have occurred and where the observation is made.
  93  * In some variants the length of each month is
  94  * computed algorithmically from the astronomical data for the moon and earth and
  95  * in others the length of the month is determined by an authorized sighting
  96  * of the new moon. For the algorithmically based calendars the calendar
  97  * can project into the future.
  98  * For sighting based calendars only historical data from past
  99  * sightings is available.
 100  * <p>
 101  * The length of each month is 29 or 30 days.
 102  * Ordinary years have 354 days; leap years have 355 days.


 491      * The Hijrah calendar system has only one era covering the
 492      * proleptic years greater than zero.
 493      * This method returns the singleton HijrahEra for the value 1.
 494      *
 495      * @param eraValue  the era value
 496      * @return the calendar system era, not null
 497      * @throws DateTimeException if unable to create the era
 498      */
 499     @Override
 500     public HijrahEra eraOf(int eraValue) {
 501         switch (eraValue) {
 502             case 1:
 503                 return HijrahEra.AH;
 504             default:
 505                 throw new DateTimeException("invalid Hijrah era");
 506         }
 507     }
 508 
 509     @Override
 510     public List<Era> eras() {
 511         return List.of(HijrahEra.values());
 512     }
 513 
 514     //-----------------------------------------------------------------------
 515     @Override
 516     public ValueRange range(ChronoField field) {
 517         checkCalendarInit();
 518         if (field instanceof ChronoField) {
 519             ChronoField f = field;
 520             switch (f) {
 521                 case DAY_OF_MONTH:
 522                     return ValueRange.of(1, 1, getMinimumMonthLength(), getMaximumMonthLength());
 523                 case DAY_OF_YEAR:
 524                     return ValueRange.of(1, getMaximumDayOfYear());
 525                 case ALIGNED_WEEK_OF_MONTH:
 526                     return ValueRange.of(1, 5);
 527                 case YEAR:
 528                 case YEAR_OF_ERA:
 529                     return ValueRange.of(getMinimumYear(), getMaximumYear());
 530                 case ERA:
 531                     return ValueRange.of(1, 1);


< prev index next >