Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ public class JewishDate implements Comparable<JewishDate>, Cloneable {
*/
public static final int ADAR_II = 13;

private static final int MONTH_JANUARY = 1;
private static final int MONTH_FEBRUARY = MONTH_JANUARY + 1;
private static final int MONTH_MARCH = MONTH_FEBRUARY + 1;
private static final int MONTH_APRIL = MONTH_MARCH + 1;
private static final int MONTH_MAY = MONTH_APRIL + 1;
private static final int MONTH_JUNE = MONTH_MAY + 1;
private static final int MONTH_JULY = MONTH_JUNE + 1;
private static final int MONTH_AUGUST = MONTH_JULY + 1;
private static final int MONTH_SEPTEMBER = MONTH_AUGUST + 1;
private static final int MONTH_OCTOBER = MONTH_SEPTEMBER + 1;
private static final int MONTH_NOVEMBER = MONTH_OCTOBER + 1;
private static final int MONTH_DECEMBER = MONTH_NOVEMBER + 1;

/**
* the Jewish epoch using the RD (Rata Die/Fixed Date or Reingold Dershowitz) day used in Calendrical Calculations.
* Day 1 is January 1, 0001 of the Gregorian calendar
Expand Down Expand Up @@ -320,11 +333,11 @@ private static int getLastDayOfGregorianMonth(int year, int month) {
*/
private static LocalDate absDateToDate(int absDate) {
int year = absDate / 366; // Search forward year by year from approximate year
while (absDate >= gregorianDateToAbsDate(year + 1, 1, 1)) {
while (absDate >= gregorianDateToAbsDate(year + 1, MONTH_JANUARY, 1)) {
year++;
}

int month = 1; // Search forward month by month from January
int month = MONTH_JANUARY; // Search forward month by month from January
while (absDate > gregorianDateToAbsDate(year, month, getLastDayOfGregorianMonth(year, month))) {
month++;
}
Expand Down Expand Up @@ -356,7 +369,7 @@ public int getAbsDate() {
*/
private static int gregorianDateToAbsDate(int year, int month, int dayOfMonth) {
int absDate = dayOfMonth;
for (int m = month - 1; m > 0; m--) {
for (int m = month - 1; m >= MONTH_JANUARY; m--) {
absDate += getLastDayOfGregorianMonth(year, m); // days in prior months of the year
}

Expand Down Expand Up @@ -1030,7 +1043,7 @@ public void resetDate() {
/**
* Subtracts the number of days passed in from the currently set date.
* @param days the number of days to subtract.
* @see plusDays(int)
* @see #plusDays(int)
*/
public void minusDays(int days){
if (days < 1) {
Expand All @@ -1044,7 +1057,7 @@ public void minusDays(int days){
* Add the number of days passed in to the currently set date.
* @param days the number of days to add.
*
* @see minusDays(int)
* @see #minusDays(int)
*/
public void plusDays(int days){
if (days < 1) {
Expand All @@ -1057,7 +1070,7 @@ public void plusDays(int days){
* Add the number of months passed in to the currently set date. If the day of the month prior to addition is the 30th, and
* the target month only has 29 days, the date will be clamped to the 29th.
* @param months the number of months to add.
* @see minusMonths(int)
* @see #plusMonths(int)
*/
public void plusMonths(int months){
if (months < 1) {
Expand All @@ -1084,7 +1097,7 @@ public void plusMonths(int months){
* Subtracts the number of months passed in to the currently set date. If the day of the month prior to subtraction
* is the 30th, and the target month only has 29 days, the date will be clamped to the 29th.
* @param months the number of months to add.
* @see plusMonths(int)
* @see #plusMonths(int)
*/
public void minusMonths(int months){
if (months < 1) {
Expand Down Expand Up @@ -1121,7 +1134,7 @@ public void minusMonths(int months){
* @param useAdarAlephForLeapYear if set to true and the current month is Adar on a non-leap year and it is being moved
* forward to a leap year, it will be set to Adar I, and if set to false it will set to Adar II. This will be
* ignored if the month is not set to Adar.
* @see minusYears(int, boolean)
* @see #minusYears(int, boolean)
*/
public void plusYears(int years, boolean useAdarAlephForLeapYear){
if (years < 1) {
Expand Down Expand Up @@ -1158,7 +1171,7 @@ public void plusYears(int years, boolean useAdarAlephForLeapYear){
* @param useAdarAlephForLeapYear if set to true and the current month is Adar on a non-leap year and it is being
* subtracted to a leap year, it will be set to Adar I, and if set to false it will set to Adar II. This will
* be ignored if the month is not set to Adar.
* @see plusYears(int, boolean)
* @see #plusYears(int, boolean)
*/
public void minusYears(int years, boolean useAdarAlephForLeapYear){
if (years < 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package com.kosherjava.zmanim.hebrewcalendar;

import org.junit.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
* Validate the days in a Hebrew month (in various types of years) are correct.
Expand Down Expand Up @@ -62,8 +65,8 @@ private void assertHaser(int year) {
JewishDate jewishDate = new JewishDate();
jewishDate.setJewishYear(year);

Assert.assertFalse(jewishDate.isCheshvanLong());
Assert.assertTrue(jewishDate.isKislevShort());
assertFalse(jewishDate.isCheshvanLong());
assertTrue(jewishDate.isKislevShort());
}


Expand All @@ -72,16 +75,16 @@ private void assertHaserLeap(int year) {
jewishDate.setJewishYear(year);

assertHaser(year);
Assert.assertTrue(jewishDate.isJewishLeapYear());
assertTrue(jewishDate.isJewishLeapYear());
}


private void assertQesidrah(int year) {
JewishDate jewishDate = new JewishDate();
jewishDate.setJewishYear(year);

Assert.assertFalse(jewishDate.isCheshvanLong( ));
Assert.assertFalse(jewishDate.isKislevShort( ));
assertFalse(jewishDate.isCheshvanLong());
assertFalse(jewishDate.isKislevShort());
}


Expand All @@ -90,16 +93,16 @@ private void assertQesidrahLeap(int year) {
jewishDate.setJewishYear(year);

assertQesidrah(year);
Assert.assertTrue(jewishDate.isJewishLeapYear( ));
assertTrue(jewishDate.isJewishLeapYear());
}


private void assertShalem(int year) {
JewishDate jewishDate = new JewishDate();
jewishDate.setJewishYear(year);

Assert.assertTrue(jewishDate.isCheshvanLong( ));
Assert.assertFalse(jewishDate.isKislevShort( ));
assertTrue(jewishDate.isCheshvanLong());
assertFalse(jewishDate.isKislevShort());
}


Expand All @@ -108,7 +111,7 @@ private void assertShalemLeap(int year) {
jewishDate.setJewishYear(year);

assertShalem(year);
Assert.assertTrue(jewishDate.isJewishLeapYear( ));
assertTrue(jewishDate.isJewishLeapYear());
}

} // End of UT_DaysInJewishMonth class
Loading
Loading