int getYear(long instant) { long millisIslamic = instant - MILLIS_YEAR_1; long cycles = millisIslamic / MILLIS_PER_CYCLE; long cycleRemainder = millisIslamic % MILLIS_PER_CYCLE; int year = (int) ((cycles * CYCLE) + 1L); long yearMillis = (isLeapYear(year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); while (cycleRemainder >= yearMillis) { cycleRemainder -= yearMillis; yearMillis = (isLeapYear(++year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); } return year; }
int getDaysInYearMonth(int year, int month) { if (month == 12 && isLeapYear(year)) { return LONG_MONTH_LENGTH; } return (--month % 2 == 0 ? LONG_MONTH_LENGTH : SHORT_MONTH_LENGTH); }
int getYear(long instant) { long millisIslamic = instant - MILLIS_YEAR_1; long cycles = millisIslamic / MILLIS_PER_CYCLE; long cycleRemainder = millisIslamic % MILLIS_PER_CYCLE; int year = (int) ((cycles * CYCLE) + 1L); long yearMillis = (isLeapYear(year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); while (cycleRemainder >= yearMillis) { cycleRemainder -= yearMillis; yearMillis = (isLeapYear(++year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); } return year; }
int getDaysInYearMonth(int year, int month) { if (month == 12 && isLeapYear(year)) { return LONG_MONTH_LENGTH; } return (--month % 2 == 0 ? LONG_MONTH_LENGTH : SHORT_MONTH_LENGTH); }
int getDaysInYear(int year) { return isLeapYear(year) ? 355 : 354; }
int getDaysInYear(int year) { return isLeapYear(year) ? 355 : 354; }
long calculateFirstDayOfYearMillis(int year) { if (year > MAX_YEAR) { throw new ArithmeticException("Year is too large: " + year + " > " + MAX_YEAR); } if (year < MIN_YEAR) { throw new ArithmeticException("Year is too small: " + year + " < " + MIN_YEAR); } // Java epoch is 1970-01-01 Gregorian which is 0622-07-16 Islamic. // 0001-01-01 Islamic is -42520809600000L // would prefer to calculate against year zero, but leap year // can be in that year so it doesn't work year--; long cycle = year / CYCLE; long millis = MILLIS_YEAR_1 + cycle * MILLIS_PER_CYCLE; int cycleRemainder = (year % CYCLE) + 1; for (int i = 1; i < cycleRemainder; i++) { millis += (isLeapYear(i) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); } return millis; }
long calculateFirstDayOfYearMillis(int year) { if (year > MAX_YEAR) { throw new ArithmeticException("Year is too large: " + year + " > " + MAX_YEAR); } if (year < MIN_YEAR) { throw new ArithmeticException("Year is too small: " + year + " < " + MIN_YEAR); } // Java epoch is 1970-01-01 Gregorian which is 0622-07-16 Islamic. // 0001-01-01 Islamic is -42520809600000L // would prefer to calculate against year zero, but leap year // can be in that year so it doesn't work year--; long cycle = year / CYCLE; long millis = MILLIS_YEAR_1 + cycle * MILLIS_PER_CYCLE; int cycleRemainder = (year % CYCLE) + 1; for (int i = 1; i < cycleRemainder; i++) { millis += (isLeapYear(i) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); } return millis; }
long setYear(long instant, int year) { // optimsed implementation of set, due to fixed months int thisYear = getYear(instant); int dayOfYear = getDayOfYear(instant, thisYear); int millisOfDay = getMillisOfDay(instant); // Current year is leap, and day is leap. if (dayOfYear > 354 && !isLeapYear(year)) { // Moving to a non-leap year, leap day doesn't exist. dayOfYear--; } instant = getYearMonthDayMillis(year, 1, dayOfYear); instant += millisOfDay; return instant; }
long setYear(long instant, int year) { // optimsed implementation of set, due to fixed months int thisYear = getYear(instant); int dayOfYear = getDayOfYear(instant, thisYear); int millisOfDay = getMillisOfDay(instant); // Current year is leap, and day is leap. if (dayOfYear > 354 && !isLeapYear(year)) { // Moving to a non-leap year, leap day doesn't exist. dayOfYear--; } instant = getYearMonthDayMillis(year, 1, dayOfYear); instant += millisOfDay; return instant; }
int getDaysInYearMonth(int year, int month) { if (month == 12 && isLeapYear(year)) { return LONG_MONTH_LENGTH; } return (--month % 2 == 0 ? LONG_MONTH_LENGTH : SHORT_MONTH_LENGTH); }
int getYear(long instant) { long millisIslamic = instant - MILLIS_YEAR_1; long cycles = millisIslamic / MILLIS_PER_CYCLE; long cycleRemainder = millisIslamic % MILLIS_PER_CYCLE; int year = (int) ((cycles * CYCLE) + 1L); long yearMillis = (isLeapYear(year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); while (cycleRemainder >= yearMillis) { cycleRemainder -= yearMillis; yearMillis = (isLeapYear(++year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); } return year; }
int getDaysInYear(int year) { return isLeapYear(year) ? 355 : 354; }
long calculateFirstDayOfYearMillis(int year) { if (year > MAX_YEAR) { throw new ArithmeticException("Year is too large: " + year + " > " + MAX_YEAR); } if (year < MIN_YEAR) { throw new ArithmeticException("Year is too small: " + year + " < " + MIN_YEAR); } // Java epoch is 1970-01-01 Gregorian which is 0622-07-16 Islamic. // 0001-01-01 Islamic is -42520809600000L // would prefer to calculate against year zero, but leap year // can be in that year so it doesn't work year--; long cycle = year / CYCLE; long millis = MILLIS_YEAR_1 + cycle * MILLIS_PER_CYCLE; int cycleRemainder = (year % CYCLE) + 1; for (int i = 1; i < cycleRemainder; i++) { millis += (isLeapYear(i) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); } return millis; }
long setYear(long instant, int year) { // optimsed implementation of set, due to fixed months int thisYear = getYear(instant); int dayOfYear = getDayOfYear(instant, thisYear); int millisOfDay = getMillisOfDay(instant); if (dayOfYear > 354) { // Current year is leap, and day is leap. if (!isLeapYear(year)) { // Moving to a non-leap year, leap day doesn't exist. dayOfYear--; } } instant = getYearMonthDayMillis(year, 1, dayOfYear); instant += millisOfDay; return instant; }
int getYear(long instant) { long millisIslamic = instant - MILLIS_YEAR_1; long cycles = millisIslamic / MILLIS_PER_CYCLE; long cycleRemainder = millisIslamic % MILLIS_PER_CYCLE; int year = (int) ((cycles * CYCLE) + 1L); long yearMillis = (isLeapYear(year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); while (cycleRemainder >= yearMillis) { cycleRemainder -= yearMillis; yearMillis = (isLeapYear(++year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); } return year; }
int getYear(long instant) { long millisIslamic = instant - MILLIS_YEAR_1; long cycles = millisIslamic / MILLIS_PER_CYCLE; long cycleRemainder = millisIslamic % MILLIS_PER_CYCLE; int year = (int) ((cycles * CYCLE) + 1L); long yearMillis = (isLeapYear(year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); while (cycleRemainder >= yearMillis) { cycleRemainder -= yearMillis; yearMillis = (isLeapYear(++year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); } return year; }
int getDaysInYearMonth(int year, int month) { if (month == 12 && isLeapYear(year)) { return LONG_MONTH_LENGTH; } return (--month % 2 == 0 ? LONG_MONTH_LENGTH : SHORT_MONTH_LENGTH); }
int getYear(long instant) { long millisIslamic = instant - MILLIS_YEAR_1; long cycles = millisIslamic / MILLIS_PER_CYCLE; long cycleRemainder = millisIslamic % MILLIS_PER_CYCLE; int year = (int) ((cycles * CYCLE) + 1L); long yearMillis = (isLeapYear(year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); while (cycleRemainder >= yearMillis) { cycleRemainder -= yearMillis; yearMillis = (isLeapYear(++year) ? MILLIS_PER_LONG_YEAR : MILLIS_PER_SHORT_YEAR); } return year; }
int getDaysInYearMonth(int year, int month) { if (month == 12 && isLeapYear(year)) { return LONG_MONTH_LENGTH; } return (--month % 2 == 0 ? LONG_MONTH_LENGTH : SHORT_MONTH_LENGTH); }