2 *******************************************************************************
3 * Copyright (C) 1996-2013, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
7 package com.ibm.icu.util;
9 import java.util.Locale;
11 import com.ibm.icu.impl.CalendarCache;
12 import com.ibm.icu.util.ULocale.Category;
15 * <code>HebrewCalendar</code> is a subclass of <code>Calendar</code>
16 * that that implements the traditional Hebrew calendar.
17 * This is the civil calendar in Israel and the liturgical calendar
18 * of the Jewish faith worldwide.
20 * The Hebrew calendar is lunisolar and thus has a number of interesting
21 * properties that distinguish it from the Gregorian. Months start
22 * on the day of (an arithmetic approximation of) each new moon. Since the
23 * solar year (approximately 365.24 days) is not an even multiple of
24 * the lunar month (approximately 29.53 days) an extra "leap month" is
25 * inserted in 7 out of every 19 years. To make matters even more
26 * interesting, the start of a year can be delayed by up to three days
27 * in order to prevent certain holidays from falling on the Sabbath and
28 * to prevent certain illegal year lengths. Finally, the lengths of certain
29 * months can vary depending on the number of days in the year.
31 * The leap month is known as "Adar 1" and is inserted between the
32 * months of Shevat and Adar in leap years. Since the leap month does
33 * not come at the end of the year, calculations involving
34 * month numbers are particularly complex. Users of this class should
35 * make sure to use the {@link #roll roll} and {@link #add add} methods
36 * rather than attempting to perform date arithmetic by manipulating
37 * the fields directly.
39 * <b>Note:</b> In the traditional Hebrew calendar, days start at sunset.
40 * However, in order to keep the time fields in this class
41 * synchronized with those of the other calendars and with local clock time,
42 * we treat days and months as beginning at midnight,
43 * roughly 6 hours after the corresponding sunset.
45 * If you are interested in more information on the rules behind the Hebrew
46 * calendar, see one of the following references:
48 * <li>"<a href="http://www.amazon.com/exec/obidos/ASIN/0521564743">Calendrical Calculations</a>",
49 * by Nachum Dershowitz & Edward Reingold, Cambridge University Press, 1997, pages 85-91.
51 * <li>Hebrew Calendar Science and Myths,
52 * <a href="http://web.archive.org/web/20090423084613/http://www.geocities.com/Athens/1584/">
53 * http://web.archive.org/web/20090423084613/http://www.geocities.com/Athens/1584/</a>
55 * <li>The Calendar FAQ,
56 * <a href="http://www.faqs.org/faqs/calendars/faq/">
57 * http://www.faqs.org/faqs/calendars/faq/</a>
61 * This class should not be subclassed.</p>
63 * HebrewCalendar usually should be instantiated using
64 * {@link com.ibm.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
65 * with the tag <code>"@calendar=hebrew"</code>.</p>
67 * @see com.ibm.icu.util.GregorianCalendar
68 * @see com.ibm.icu.util.Calendar
70 * @author Laura Werner
74 public class HebrewCalendar extends Calendar {
76 private static final long serialVersionUID = -1952524560588825816L;
78 //-------------------------------------------------------------------------
79 // Tons o' Constants...
80 //-------------------------------------------------------------------------
84 * Constant for Tishri, the 1st month of the Hebrew year.
87 public static final int TISHRI = 0;
90 * Constant for Heshvan, the 2nd month of the Hebrew year.
93 public static final int HESHVAN = 1;
96 * Constant for Kislev, the 3rd month of the Hebrew year.
99 public static final int KISLEV = 2;
102 * Constant for Tevet, the 4th month of the Hebrew year.
105 public static final int TEVET = 3;
108 * Constant for Shevat, the 5th month of the Hebrew year.
111 public static final int SHEVAT = 4;
114 * Constant for Adar I, the 6th month of the Hebrew year
115 * (present in leap years only). In non-leap years, the calendar
116 * jumps from Shevat (5th month) to Adar (7th month).
119 public static final int ADAR_1 = 5;
122 * Constant for the Adar, the 7th month of the Hebrew year.
125 public static final int ADAR = 6;
128 * Constant for Nisan, the 8th month of the Hebrew year.
131 public static final int NISAN = 7;
134 * Constant for Iyar, the 9th month of the Hebrew year.
137 public static final int IYAR = 8;
140 * Constant for Sivan, the 10th month of the Hebrew year.
143 public static final int SIVAN = 9;
146 * Constant for Tammuz, the 11th month of the Hebrew year.
149 public static final int TAMUZ = 10;
152 * Constant for Av, the 12th month of the Hebrew year.
155 public static final int AV = 11;
158 * Constant for Elul, the 13th month of the Hebrew year.
161 public static final int ELUL = 12;
164 * The absolute date, in milliseconds since 1/1/1970 AD, Gregorian,
165 * of the start of the Hebrew calendar. In order to keep this calendar's
166 * time of day in sync with that of the Gregorian calendar, we use
167 * midnight, rather than sunset the day before.
169 //private static final long EPOCH_MILLIS = -180799862400000L; // 1/1/1 HY
171 private static final int LIMITS[][] = {
172 // Minimum Greatest Least Maximum
174 { 0, 0, 0, 0 }, // ERA
175 { -5000000, -5000000, 5000000, 5000000 }, // YEAR
176 { 0, 0, 12, 12 }, // MONTH
177 { 1, 1, 51, 56 }, // WEEK_OF_YEAR
178 {/* */}, // WEEK_OF_MONTH
179 { 1, 1, 29, 30 }, // DAY_OF_MONTH
180 { 1, 1, 353, 385 }, // DAY_OF_YEAR
181 {/* */}, // DAY_OF_WEEK
182 { -1, -1, 5, 5 }, // DAY_OF_WEEK_IN_MONTH
185 {/* */}, // HOUR_OF_DAY
188 {/* */}, // MILLISECOND
189 {/* */}, // ZONE_OFFSET
190 {/* */}, // DST_OFFSET
191 { -5000000, -5000000, 5000000, 5000000 }, // YEAR_WOY
192 {/* */}, // DOW_LOCAL
193 { -5000000, -5000000, 5000000, 5000000 }, // EXTENDED_YEAR
194 {/* */}, // JULIAN_DAY
195 {/* */}, // MILLISECONDS_IN_DAY
199 * The lengths of the Hebrew months. This is complicated, because there
200 * are three different types of years, or six if you count leap years.
201 * Due to the rules for postponing the start of the year to avoid having
202 * certain holidays fall on the sabbath, the year can end up being three
203 * different lengths, called "deficient", "normal", and "complete".
205 private static final int MONTH_LENGTH[][] = {
206 // Deficient Normal Complete
207 { 30, 30, 30 }, //Tishri
208 { 29, 29, 30 }, //Heshvan
209 { 29, 30, 30 }, //Kislev
210 { 29, 29, 29 }, //Tevet
211 { 30, 30, 30 }, //Shevat
212 { 30, 30, 30 }, //Adar I (leap years only)
213 { 29, 29, 29 }, //Adar
214 { 30, 30, 30 }, //Nisan
215 { 29, 29, 29 }, //Iyar
216 { 30, 30, 30 }, //Sivan
217 { 29, 29, 29 }, //Tammuz
219 { 29, 29, 29 }, //Elul
223 * The cumulative # of days to the end of each month in a non-leap year
224 * Although this can be calculated from the MONTH_LENGTH table,
225 * keeping it around separately makes some calculations a lot faster
227 private static final int MONTH_START[][] = {
228 // Deficient Normal Complete
229 { 0, 0, 0 }, // (placeholder)
230 { 30, 30, 30 }, // Tishri
231 { 59, 59, 60 }, // Heshvan
232 { 88, 89, 90 }, // Kislev
233 { 117, 118, 119 }, // Tevet
234 { 147, 148, 149 }, // Shevat
235 { 147, 148, 149 }, // (Adar I placeholder)
236 { 176, 177, 178 }, // Adar
237 { 206, 207, 208 }, // Nisan
238 { 235, 236, 237 }, // Iyar
239 { 265, 266, 267 }, // Sivan
240 { 294, 295, 296 }, // Tammuz
241 { 324, 325, 326 }, // Av
242 { 353, 354, 355 }, // Elul
246 * The cumulative # of days to the end of each month in a leap year
248 private static final int LEAP_MONTH_START[][] = {
249 // Deficient Normal Complete
250 { 0, 0, 0 }, // (placeholder)
251 { 30, 30, 30 }, // Tishri
252 { 59, 59, 60 }, // Heshvan
253 { 88, 89, 90 }, // Kislev
254 { 117, 118, 119 }, // Tevet
255 { 147, 148, 149 }, // Shevat
256 { 177, 178, 179 }, // Adar I
257 { 206, 207, 208 }, // Adar II
258 { 236, 237, 238 }, // Nisan
259 { 265, 266, 267 }, // Iyar
260 { 295, 296, 297 }, // Sivan
261 { 324, 325, 326 }, // Tammuz
262 { 354, 355, 356 }, // Av
263 { 383, 384, 385 }, // Elul
266 //-------------------------------------------------------------------------
268 //-------------------------------------------------------------------------
270 private static CalendarCache cache = new CalendarCache();
272 //-------------------------------------------------------------------------
274 //-------------------------------------------------------------------------
277 * Constructs a default <code>HebrewCalendar</code> using the current time
278 * in the default time zone with the default <code>FORMAT</code> locale.
279 * @see Category#FORMAT
282 public HebrewCalendar() {
283 this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
287 * Constructs a <code>HebrewCalendar</code> based on the current time
288 * in the given time zone with the default <code>FORMAT</code> locale.
290 * @param zone The time zone for the new calendar.
291 * @see Category#FORMAT
294 public HebrewCalendar(TimeZone zone) {
295 this(zone, ULocale.getDefault(Category.FORMAT));
299 * Constructs a <code>HebrewCalendar</code> based on the current time
300 * in the default time zone with the given locale.
302 * @param aLocale The locale for the new calendar.
305 public HebrewCalendar(Locale aLocale) {
306 this(TimeZone.getDefault(), aLocale);
310 * Constructs a <code>HebrewCalendar</code> based on the current time
311 * in the default time zone with the given locale.
313 * @param locale The locale for the new calendar.
316 public HebrewCalendar(ULocale locale) {
317 this(TimeZone.getDefault(), locale);
321 * Constructs a <code>HebrewCalendar</code> based on the current time
322 * in the given time zone with the given locale.
324 * @param zone The time zone for the new calendar.
326 * @param aLocale The locale for the new calendar.
329 public HebrewCalendar(TimeZone zone, Locale aLocale) {
330 super(zone, aLocale);
331 setTimeInMillis(System.currentTimeMillis());
335 * Constructs a <code>HebrewCalendar</code> based on the current time
336 * in the given time zone with the given locale.
338 * @param zone The time zone for the new calendar.
340 * @param locale The locale for the new calendar.
343 public HebrewCalendar(TimeZone zone, ULocale locale) {
345 setTimeInMillis(System.currentTimeMillis());
349 * Constructs a <code>HebrewCalendar</code> with the given date set
350 * in the default time zone with the default <code>FORMAT</code> locale.
352 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
354 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
355 * The value is 0-based. e.g., 0 for Tishri.
357 * @param date The value used to set the calendar's {@link #DATE DATE} time field.
358 * @see Category#FORMAT
361 public HebrewCalendar(int year, int month, int date) {
362 super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
363 this.set(YEAR, year);
364 this.set(MONTH, month);
365 this.set(DATE, date);
369 * Constructs a <code>HebrewCalendar</code> with the given date set
370 * in the default time zone with the default <code>FORMAT</code> locale.
372 * @param date The date to which the new calendar is set.
373 * @see Category#FORMAT
376 public HebrewCalendar(Date date) {
377 super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
382 * Constructs a <code>HebrewCalendar</code> with the given date
383 * and time set for the default time zone with the default <code>FORMAT</code> locale.
385 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
387 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
388 * The value is 0-based. e.g., 0 for Tishri.
390 * @param date The value used to set the calendar's {@link #DATE DATE} time field.
392 * @param hour The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
394 * @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field.
396 * @param second The value used to set the calendar's {@link #SECOND SECOND} time field.
397 * @see Category#FORMAT
400 public HebrewCalendar(int year, int month, int date, int hour,
401 int minute, int second)
403 super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
404 this.set(YEAR, year);
405 this.set(MONTH, month);
406 this.set(DATE, date);
407 this.set(HOUR_OF_DAY, hour);
408 this.set(MINUTE, minute);
409 this.set(SECOND, second);
412 //-------------------------------------------------------------------------
413 // Rolling and adding functions overridden from Calendar
415 // These methods call through to the default implementation in IBMCalendar
416 // for most of the fields and only handle the unusual ones themselves.
417 //-------------------------------------------------------------------------
420 * Add a signed amount to a specified field, using this calendar's rules.
421 * For example, to add three days to the current date, you can call
422 * <code>add(Calendar.DATE, 3)</code>.
424 * When adding to certain fields, the values of other fields may conflict and
425 * need to be changed. For example, when adding one to the {@link #MONTH MONTH} field
426 * for the date "30 Av 5758", the {@link #DAY_OF_MONTH DAY_OF_MONTH} field
427 * must be adjusted so that the result is "29 Elul 5758" rather than the invalid
430 * This method is able to add to
431 * all fields except for {@link #ERA ERA}, {@link #DST_OFFSET DST_OFFSET},
432 * and {@link #ZONE_OFFSET ZONE_OFFSET}.
434 * <b>Note:</b> You should always use {@link #roll roll} and add rather
435 * than attempting to perform arithmetic operations directly on the fields
436 * of a <tt>HebrewCalendar</tt>. Since the {@link #MONTH MONTH} field behaves
437 * discontinuously in non-leap years, simple arithmetic can give invalid results.
439 * @param field the time field.
440 * @param amount the amount to add to the field.
442 * @exception IllegalArgumentException if the field is invalid or refers
443 * to a field that cannot be handled by this method.
446 public void add(int field, int amount)
451 // We can't just do a set(MONTH, get(MONTH) + amount). The
452 // reason is ADAR_1. Suppose amount is +2 and we land in
453 // ADAR_1 -- then we have to bump to ADAR_2 aka ADAR. But
454 // if amount is -2 and we land in ADAR_1, then we have to
455 // bump the other way -- down to SHEVAT. - Alan 11/00
456 int month = get(MONTH);
457 int year = get(YEAR);
460 acrossAdar1 = (month < ADAR_1); // started before ADAR_1?
463 if (acrossAdar1 && month>=ADAR_1 && !isLeapYear(year)) {
474 acrossAdar1 = (month > ADAR_1); // started after ADAR_1?
477 if (acrossAdar1 && month<=ADAR_1 && !isLeapYear(year)) {
490 pinField(DAY_OF_MONTH);
495 super.add(field, amount);
501 * Rolls (up/down) a specified amount time on the given field. For
502 * example, to roll the current date up by three days, you can call
503 * <code>roll(Calendar.DATE, 3)</code>. If the
504 * field is rolled past its maximum allowable value, it will "wrap" back
505 * to its minimum and continue rolling.
506 * For example, calling <code>roll(Calendar.DATE, 10)</code>
507 * on a Hebrew calendar set to "25 Av 5758" will result in the date "5 Av 5758".
509 * When rolling certain fields, the values of other fields may conflict and
510 * need to be changed. For example, when rolling the {@link #MONTH MONTH} field
511 * upward by one for the date "30 Av 5758", the {@link #DAY_OF_MONTH DAY_OF_MONTH} field
512 * must be adjusted so that the result is "29 Elul 5758" rather than the invalid
515 * This method is able to roll
516 * all fields except for {@link #ERA ERA}, {@link #DST_OFFSET DST_OFFSET},
517 * and {@link #ZONE_OFFSET ZONE_OFFSET}. Subclasses may, of course, add support for
518 * additional fields in their overrides of <code>roll</code>.
520 * <b>Note:</b> You should always use roll and {@link #add add} rather
521 * than attempting to perform arithmetic operations directly on the fields
522 * of a <tt>HebrewCalendar</tt>. Since the {@link #MONTH MONTH} field behaves
523 * discontinuously in non-leap years, simple arithmetic can give invalid results.
525 * @param field the time field.
526 * @param amount the amount by which the field should be rolled.
528 * @exception IllegalArgumentException if the field is invalid or refers
529 * to a field that cannot be handled by this method.
532 public void roll(int field, int amount)
537 int month = get(MONTH);
538 int year = get(YEAR);
540 boolean leapYear = isLeapYear(year);
541 int yearLength = monthsInYear(year);
542 int newMonth = month + (amount % yearLength);
544 // If it's not a leap year and we're rolling past the missing month
545 // of ADAR_1, we need to roll an extra month to make up for it.
548 if (amount > 0 && month < ADAR_1 && newMonth >= ADAR_1) {
550 } else if (amount < 0 && month > ADAR_1 && newMonth <= ADAR_1) {
554 set(MONTH, (newMonth + 13) % 13);
555 pinField(DAY_OF_MONTH);
559 super.roll(field, amount);
563 //-------------------------------------------------------------------------
565 //-------------------------------------------------------------------------
567 // Hebrew date calculations are performed in terms of days, hours, and
568 // "parts" (or halakim), which are 1/1080 of an hour, or 3 1/3 seconds.
569 private static final long HOUR_PARTS = 1080;
570 private static final long DAY_PARTS = 24*HOUR_PARTS;
572 // An approximate value for the length of a lunar month.
573 // It is used to calculate the approximate year and month of a given
575 static private final int MONTH_DAYS = 29;
576 static private final long MONTH_FRACT = 12*HOUR_PARTS + 793;
577 static private final long MONTH_PARTS = MONTH_DAYS*DAY_PARTS + MONTH_FRACT;
579 // The time of the new moon (in parts) on 1 Tishri, year 1 (the epoch)
580 // counting from noon on the day before. BAHARAD is an abbreviation of
581 // Bet (Monday), Hey (5 hours from sunset), Resh-Daled (204).
582 static private final long BAHARAD = 11*HOUR_PARTS + 204;
585 * Finds the day # of the first day in the given Hebrew year.
586 * To do this, we want to calculate the time of the Tishri 1 new moon
589 * The algorithm here is similar to ones described in a number of
590 * references, including:
592 * <li>"Calendrical Calculations", by Nachum Dershowitz & Edward Reingold,
593 * Cambridge University Press, 1997, pages 85-91.
595 * <li>Hebrew Calendar Science and Myths,
596 * <a href="http://www.geocities.com/Athens/1584/">
597 * http://www.geocities.com/Athens/1584/</a>
599 * <li>The Calendar FAQ,
600 * <a href="http://www.faqs.org/faqs/calendars/faq/">
601 * http://www.faqs.org/faqs/calendars/faq/</a>
604 private static long startOfYear(int year)
606 long day = cache.get(year);
608 if (day == CalendarCache.EMPTY) {
609 int months = (235 * year - 234) / 19; // # of months before year
611 long frac = months * MONTH_FRACT + BAHARAD; // Fractional part of day #
612 day = months * 29 + (frac / DAY_PARTS); // Whole # part of calculation
613 frac = frac % DAY_PARTS; // Time of day
615 int wd = (int)(day % 7); // Day of week (0 == Monday)
617 if (wd == 2 || wd == 4 || wd == 6) {
618 // If the 1st is on Sun, Wed, or Fri, postpone to the next day
622 if (wd == 1 && frac > 15*HOUR_PARTS+204 && !isLeapYear(year) ) {
623 // If the new moon falls after 3:11:20am (15h204p from the previous noon)
624 // on a Tuesday and it is not a leap year, postpone by 2 days.
625 // This prevents 356-day years.
628 else if (wd == 0 && frac > 21*HOUR_PARTS+589 && isLeapYear(year-1) ) {
629 // If the new moon falls after 9:32:43 1/3am (21h589p from yesterday noon)
630 // on a Monday and *last* year was a leap year, postpone by 1 day.
631 // Prevents 382-day years.
634 cache.put(year, day);
640 * Find the day of the week for a given day
642 * @param day The # of days since the start of the Hebrew calendar,
643 * 1-based (i.e. 1/1/1 AM is day 1).
645 /*private static int absoluteDayToDayOfWeek(long day)
647 // We know that 1/1/1 AM is a Monday, which makes the math easy...
648 return (int)(day % 7) + 1;
652 * Returns the the type of a given year.
653 * 0 "Deficient" year with 353 or 383 days
654 * 1 "Normal" year with 354 or 384 days
655 * 2 "Complete" year with 355 or 385 days
657 private final int yearType(int year)
659 int yearLength = handleGetYearLength(year);
661 if (yearLength > 380) {
662 yearLength -= 30; // Subtract length of leap month.
667 switch (yearLength) {
675 throw new IllegalArgumentException("Illegal year length " + yearLength + " in year " + year);
682 * Determine whether a given Hebrew year is a leap year
684 * The rule here is that if (year % 19) == 0, 3, 6, 8, 11, 14, or 17.
685 * The formula below performs the same test, believe it or not.
687 * @deprecated This API is ICU internal only.
689 public static boolean isLeapYear(int year) {
690 //return (year * 12 + 17) % 19 >= 12;
691 int x = (year*12 + 17) % 19;
692 return x >= ((x < 0) ? -7 : 12);
695 private static int monthsInYear(int year) {
696 return isLeapYear(year) ? 13 : 12;
699 //-------------------------------------------------------------------------
700 // Calendar framework
701 //-------------------------------------------------------------------------
706 protected int handleGetLimit(int field, int limitType) {
707 return LIMITS[field][limitType];
711 * Returns the length of the given month in the given year
714 protected int handleGetMonthLength(int extendedYear, int month) {
715 // Resolve out-of-range months. This is necessary in order to
716 // obtain the correct year. We correct to
717 // a 12- or 13-month year (add/subtract 12 or 13, depending
718 // on the year) but since we _always_ number from 0..12, and
719 // the leap year determines whether or not month 5 (Adar 1)
720 // is present, we allow 0..12 in any given year.
722 month += monthsInYear(--extendedYear);
724 // Careful: allow 0..12 in all years
726 month -= monthsInYear(extendedYear++);
732 // These two month lengths can vary
733 return MONTH_LENGTH[month][yearType(extendedYear)];
736 // The rest are a fixed length
737 return MONTH_LENGTH[month][0];
742 * Returns the number of days in the given Hebrew year
745 protected int handleGetYearLength(int eyear) {
746 return (int)(startOfYear(eyear+1) - startOfYear(eyear));
749 //-------------------------------------------------------------------------
750 // Functions for converting from milliseconds to field values
751 //-------------------------------------------------------------------------
754 * Subclasses may override this method to compute several fields
755 * specific to each calendar system. These are:
762 * <li>EXTENDED_YEAR</ul>
764 * Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields,
765 * which will be set when this method is called. Subclasses can
766 * also call the getGregorianXxx() methods to obtain Gregorian
767 * calendar equivalents for the given Julian day.
769 * <p>In addition, subclasses should compute any subclass-specific
770 * fields, that is, fields from BASE_FIELD_COUNT to
771 * getFieldCount() - 1.
774 protected void handleComputeFields(int julianDay) {
775 long d = julianDay - 347997;
776 long m = (d * DAY_PARTS) / MONTH_PARTS; // Months (approx)
777 int year = (int)((19 * m + 234) / 235) + 1; // Years (approx)
778 long ys = startOfYear(year); // 1st day of year
779 int dayOfYear = (int)(d - ys);
781 // Because of the postponement rules, it's possible to guess wrong. Fix it.
782 while (dayOfYear < 1) {
784 ys = startOfYear(year);
785 dayOfYear = (int)(d - ys);
788 // Now figure out which month we're in, and the date within that month
789 int yearType = yearType(year);
790 int monthStart[][] = isLeapYear(year) ? LEAP_MONTH_START : MONTH_START;
793 while (dayOfYear > monthStart[month][yearType]) {
797 int dayOfMonth = dayOfYear - monthStart[month][yearType];
800 internalSet(YEAR, year);
801 internalSet(EXTENDED_YEAR, year);
802 internalSet(MONTH, month);
803 internalSet(DAY_OF_MONTH, dayOfMonth);
804 internalSet(DAY_OF_YEAR, dayOfYear);
807 //-------------------------------------------------------------------------
808 // Functions for converting from field values to milliseconds
809 //-------------------------------------------------------------------------
814 protected int handleGetExtendedYear() {
816 if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {
817 year = internalGet(EXTENDED_YEAR, 1); // Default to year 1
819 year = internalGet(YEAR, 1); // Default to year 1
825 * Return JD of start of given month/year.
828 protected int handleComputeMonthStart(int eyear, int month, boolean useMonth) {
830 // Resolve out-of-range months. This is necessary in order to
831 // obtain the correct year. We correct to
832 // a 12- or 13-month year (add/subtract 12 or 13, depending
833 // on the year) but since we _always_ number from 0..12, and
834 // the leap year determines whether or not month 5 (Adar 1)
835 // is present, we allow 0..12 in any given year.
837 month += monthsInYear(--eyear);
839 // Careful: allow 0..12 in all years
841 month -= monthsInYear(eyear++);
844 long day = startOfYear(eyear);
847 if (isLeapYear(eyear)) {
848 day += LEAP_MONTH_START[month][yearType(eyear)];
850 day += MONTH_START[month][yearType(eyear)];
854 return (int) (day + 347997);
861 public String getType() {
866 private static CalendarFactory factory;
867 public static CalendarFactory factory() {
868 if (factory == null) {
869 factory = new CalendarFactory() {
870 public Calendar create(TimeZone tz, ULocale loc) {
871 return new HebrewCalendar(tz, loc);
874 public String factoryName() {