Skip to content

Commit aa693f6

Browse files
authored
Javadoc improvements for JewishDate.java
There will be more to follow
1 parent c1b9a6e commit aa693f6

1 file changed

Lines changed: 62 additions & 19 deletions

File tree

src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.time.ZonedDateTime;
2323

2424
/**
25-
* The JewishDate is the base calendar class, that supports maintenance of a {@link java.util.GregorianCalendar}
25+
* The JewishDate is the base calendar class, that supports maintenance of a {@link LocalDate}
2626
* instance along with the corresponding Jewish date. This class can use the standard Java Date and Calendar
2727
* classes for setting and maintaining the dates, but it does not subclass these classes or use them internally
2828
* in any calculations. This class also does not have a concept of a time (which the Date class does). Please
@@ -296,7 +296,7 @@ public int getMoladChalakim() {
296296

297297
/** Returns the absolute date (days since January 1, 0001 of the Gregorian calendar).
298298
* @see #getAbsDate()
299-
* @see #setJewishDateFromAbsDate()
299+
* @see #setAbsDate(int)
300300
*/
301301
private int gregorianAbsDate;
302302

@@ -316,6 +316,7 @@ private static int getLastDayOfGregorianMonth(int month, int year) {
316316
/**
317317
* Computes the Gregorian date from the absolute date. ND+ER
318318
* @param absDate the absolute date
319+
* @return the <code>Localdate</code>.
319320
*/
320321
private static LocalDate absDateToDate(int absDate) {
321322
int year = absDate / 366; // Search forward year by year from approximate year
@@ -698,6 +699,7 @@ public int getDaysInJewishMonth() {
698699

699700
/**
700701
* Computes and sets the Jewish date fields based on the provided absolute (Gregorian) date.
702+
* @param gregorianAbsDate the Gregorian absolute date.
701703
*/
702704
private void setAbsDate(int gregorianAbsDate) {
703705
if (gregorianAbsDate <= 0) {
@@ -861,43 +863,37 @@ public JewishDate() {
861863
}
862864

863865
/**
864-
* A constructor that initializes the date to the {@link java.util.Calendar Calendar} parameter.
866+
* A constructor that initializes the date to the {@link ZonedDateTime} parameter.
865867
*
866868
* @param zonedDateTime
867869
* the <code>ZonedDateTime</code> to set the calendar to
868-
* @throws IllegalArgumentException
869-
* if the {@link Calendar#ERA} is {@link GregorianCalendar#BC}
870870
*/
871871
public JewishDate(ZonedDateTime zonedDateTime) {
872872
setGregorianDate(zonedDateTime);
873873
}
874874

875875
/**
876-
* A constructor that initializes the date to the {@link java.time.LocalDate LocalDate} parameter.
876+
* A constructor that initializes the date to the {@link LocalDate} parameter.
877877
*
878878
* @param localDate
879879
* the <code>LocalDate</code> to set the calendar to
880-
* @throws IllegalArgumentException
881-
* if the {@link Calendar#ERA} is {@link GregorianCalendar#BC}
882880
*/
883881
public JewishDate(LocalDate localDate) {
884882
setGregorianDate(localDate);
885883
}
886884

887885
/**
888-
* Sets the date based on a {@link java.util.Calendar Calendar} object. Modifies the Jewish date as well.
886+
* Sets the date based on a {@link ZonedDateTime} object. Modifies the Jewish date as well.
889887
*
890888
* @param zonedDateTime
891-
* the <code>ZonedDateTime</code> to set the calendar to
892-
* @throws IllegalArgumentException
893-
* if the {@link Calendar#ERA} is {@link GregorianCalendar#BC}
889+
* the {@link ZonedDateTime} to set the calendar to
894890
*/
895891
public void setGregorianDate(ZonedDateTime zonedDateTime) {
896892
setGregorianDate(zonedDateTime.toLocalDate());
897893
}
898894

899895
/**
900-
* Sets the date based on a {@link java.time.LocalDate LocalDate} object. Modifies the Jewish date as well.
896+
* Sets the date based on a {@link LocalDate} object. Modifies the Jewish date as well.
901897
*
902898
* @param localDate
903899
* the <code>LocalDate</code> to set the calendar to
@@ -906,9 +902,7 @@ public void setGregorianDate(ZonedDateTime zonedDateTime) {
906902
*/
907903
public void setGregorianDate(LocalDate localDate) {
908904
int absDate = gregorianDateToAbsDate(localDate.getYear(), localDate.getMonth().getValue(), localDate.getDayOfMonth());
909-
910-
// convert to Jewish date
911-
setAbsDate(absDate);
905+
setAbsDate(absDate); // convert to Jewish date
912906
}
913907

914908
/**
@@ -974,16 +968,38 @@ public void setJewishDate(int year, int month, int dayOfMonth, int hours, int mi
974968
dayOfWeek = Math.abs(gregorianAbsDate % 7) + 1; // reset day of week
975969
}
976970

971+
/**
972+
* Setter for the Jewish day of the month that will be <a href="https://en.wikipedia.org/wiki/Clamp_(function)"
973+
* >clamped</a> to the lesser of the number passed in or the max number of days in the month.
974+
* @param dayOfMonth the day of the month to set the date to.
975+
*/
977976
public void setJewishDayOfMonth(int dayOfMonth){
978977
setJewishDate(getJewishYear(), getJewishMonth(), dayOfMonth);
979978
}
980979

980+
/**
981+
* Setter for the Jewish month that is passed in. If the day of month is currently the 30th and the month is being set to
982+
* a month that only has 29 days, the day of month will be <a href="https://en.wikipedia.org/wiki/Clamp_(function)"
983+
* >clamped</a> to the 29th of the month.
984+
* @param month the month to be set
985+
*/
981986
public void setJewishMonth(int month){
982987
int year = getJewishYear();
983988
int day = Math.min(getDaysInJewishMonth(month,year),getJewishDayOfMonth());
984989
setJewishDate(year, month, day);
985990
}
986991

992+
/**
993+
* Setter for the Jewish year of the passed in that will <a href="https://en.wikipedia.org/wiki/Clamp_(function)"
994+
* >clamp</a> the day to the month to the lesser of the current day and the max number of days in the month (if set
995+
* to the 30th).
996+
*
997+
* Note that if you are using this for a yahrzeit (or any other reason)on the 30th of the month that will not always have
998+
* 30 days, such as {@link #CHESHVAN} or {@link #KISLEV} or {@link #ADAR ADAR I} on a leap year and the next year is a
999+
* non-leap year, you must clone your date or once it is set to the 29th, the next time you forward it to a year that has
1000+
* 30 days, the calendar will incorrectly be forwarded a year from the 29th to the 29th and not the 30th that you may expect.
1001+
* @param year teh year to set.
1002+
*/
9871003
public void setJewishYear(int year){
9881004
int month = Math.min(getJewishMonth(),getLastMonthOfJewishYear(year));
9891005
int day = Math.min(getJewishDayOfMonth(), getDaysInJewishMonth(month,year));
@@ -992,9 +1008,9 @@ public void setJewishYear(int year){
9921008

9931009

9941010
/**
995-
* Returns this object's date as a {@link java.time.LocalDate} object.
1011+
* Returns this object's date as a {@link LocalDate} object.
9961012
*
997-
* @return The {@link java.time.LocalDate}
1013+
* @return The {@link LocalDate}
9981014
*/
9991015
public LocalDate getLocalDate() {
10001016
return absDateToDate(getAbsDate());
@@ -1008,19 +1024,33 @@ public void resetDate() {
10081024
setGregorianDate(localDate);
10091025
}
10101026

1027+
/**
1028+
* Subtracts the number of days passed in from the currently set date.
1029+
* @param days the number of days to subtract.
1030+
*/
10111031
public void minusDays(int days){
10121032
if (days < 1) {
10131033
throw new IllegalArgumentException("the amount of days to subtract has to be greater than zero.");
10141034
}
10151035
setAbsDate(getAbsDate() - days);
10161036

10171037
}
1038+
1039+
/**
1040+
* Add the number of days passed in to the currently set date.
1041+
* @param days the number of days to add.
1042+
*/
10181043
public void addDays(int days){
10191044
if (days < 1) {
10201045
throw new IllegalArgumentException("the amount of days to add has to be greater than zero.");
10211046
}
10221047
setAbsDate(getAbsDate() + days);
10231048
}
1049+
1050+
/**
1051+
* Add the number of months passed in to the currently set date.
1052+
* @param months the number of months to add.
1053+
*/
10241054
public void addMonths(int months){
10251055
if (months < 1) {
10261056
throw new IllegalArgumentException("the amount of months to add has to be greater than zero.");
@@ -1041,9 +1071,22 @@ public void addMonths(int months){
10411071
int day = Math.min(getJewishDayOfMonth(), getDaysInJewishMonth(month,year));
10421072
setJewishDate(year, month, day);
10431073
}
1074+
1075+
/**
1076+
* Add the number of years passed in to the currently set date. If the current month is Adar on a non-leap year,
1077+
* passing <code>true</code> to the useAdarAlephForLeapYear parameter will set te month to Adar I, and passing
1078+
* <code>false</code> will forward it to Adar II. The useAdarAlephForLeapYear will be ignored if the current month
1079+
* is not Adar on a non-leap year. If the current year is a leap year and it is currently Adar I or Adar II and the
1080+
* year it is being increased to is also a leap year, the same Adar will be used. If it is being increased to a
1081+
* non-leap year, the month will be set to Adar.
1082+
* @param years the number of years to add
1083+
* @param useAdarAlephForLeapYear if set to true and the current month is Adar on a non-leap year and it is being moved
1084+
* 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
1085+
* ignored if the month is not set to Adar on a non-leap year.
1086+
*/
10441087
public void addYears(int years, boolean useAdarAlephForLeapYear){
10451088
if (years < 1) {
1046-
throw new IllegalArgumentException("the amount of years to add has to be greater than zero.");
1089+
throw new IllegalArgumentException("the amount of years to add has to be greater than zero. Use minusYears(int, boolean)");
10471090
}
10481091
int targetYear = getJewishYear() + years;
10491092
// If we are in the month of Adar in a non-leap year and we are skipping

0 commit comments

Comments
 (0)