Skip to content
Merged
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
92 changes: 44 additions & 48 deletions anniversary.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,35 @@ package hdate
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import (
"errors"
"strconv"
"fmt"
)

/*
GetYahrzeit calculates yahrzeit.
hyear must be after original date of death.
Returns an error when requested year precedes or is same as original year.

Hebcal uses the algorithm defined in "Calendrical Calculations"
by Edward M. Reingold and Nachum Dershowitz.

The customary anniversary date of a death is more complicated and depends
also on the character of the year in which the first anniversary occurs.
There are several cases:
- If the date of death is Marcheshvan 30, the anniversary in general depends
on the first anniversary; if that first anniversary was not Marcheshvan 30,
use the day before Kislev 1.
- If the date of death is Kislev 30, the anniversary in general again depends
on the first anniversary — if that was not Kislev 30, use the day before
Tevet 1.
- If the date of death is Adar II, the anniversary is the same day in the
last month of the Hebrew year (Adar or Adar II).
- If the date of death is Adar I 30, the anniversary in a Hebrew year that
is not a leap year (in which Adar only has 29 days) is the last day in
Shevat.
- In all other cases, use the normal (that is, same month number) anniversary
of the date of death. [Calendrical Calculations p. 113]
*/
// GetYahrzeit calculates yahrzeit.
// hyear must be after original date of death.
// Returns an error when requested year precedes or is same as original year.
//
// Hebcal uses the algorithm defined in "Calendrical Calculations"
// by Edward M. Reingold and Nachum Dershowitz.
//
// The customary anniversary date of a death is more complicated and depends
// also on the character of the year in which the first anniversary occurs.
// There are several cases:
// - If the date of death is Marcheshvan 30, the anniversary in general depends
// on the first anniversary; if that first anniversary was not Marcheshvan 30,
// use the day before Kislev 1.
// - If the date of death is Kislev 30, the anniversary in general again depends
// on the first anniversary — if that was not Kislev 30, use the day before
// Tevet 1.
// - If the date of death is Adar II, the anniversary is the same day in the
// last month of the Hebrew year (Adar or Adar II).
// - If the date of death is Adar I 30, the anniversary in a Hebrew year that
// is not a leap year (in which Adar only has 29 days) is the last day in
// Shevat.
// - In all other cases, use the normal (that is, same month number) anniversary
// of the date of death. [Calendrical Calculations p. 113]
func GetYahrzeit(hyear int, date HDate) (HDate, error) {
if hyear <= date.Year() {
return HDate{}, errors.New("year " + strconv.Itoa(hyear) + " occurs on or before original date")
return HDate{}, fmt.Errorf("year %d occurs on or before original date", hyear)
}

if date.Month() == Cheshvan && date.Day() == 30 && !LongCheshvan(date.Year()+1) {
Expand Down Expand Up @@ -83,30 +80,29 @@ func GetYahrzeit(hyear int, date HDate) (HDate, error) {
return New(hyear, date.Month(), date.Day()), nil
}

/*
GetBirthdayOrAnniversary calculates a birthday or anniversary (non-yahrzeit).
hyear must be after original date of anniversary.
Returns an error when requested year precedes or is same as original year.

Hebcal uses the algorithm defined in "Calendrical Calculations"
by Edward M. Reingold and Nachum Dershowitz.

The birthday of someone born in Adar of an ordinary year or Adar II of
a leap year is also always in the last month of the year, be that Adar
or Adar II. The birthday in an ordinary year of someone born during the
first 29 days of Adar I in a leap year is on the corresponding day of Adar;
in a leap year, the birthday occurs in Adar I, as expected.

Someone born on the thirtieth day of Marcheshvan, Kislev, or Adar I
has his birthday postponed until the first of the following month in
years where that day does not occur. [Calendrical Calculations p. 111]
*/
// GetBirthdayOrAnniversary calculates a birthday or anniversary (non-yahrzeit).
// hyear must be after original date of anniversary.
// Returns an error when requested year precedes or is same as original year.
//
// Hebcal uses the algorithm defined in "Calendrical Calculations"
// by Edward M. Reingold and Nachum Dershowitz.
//
// The birthday of someone born in Adar of an ordinary year or Adar II of
// a leap year is also always in the last month of the year, be that Adar
// or Adar II. The birthday in an ordinary year of someone born during the
// first 29 days of Adar I in a leap year is on the corresponding day of Adar;
// in a leap year, the birthday occurs in Adar I, as expected.
//
// Someone born on the thirtieth day of Marcheshvan, Kislev, or Adar I
// has his birthday postponed until the first of the following month in
// years where that day does not occur. [Calendrical Calculations p. 111]
func GetBirthdayOrAnniversary(hyear int, date HDate) (HDate, error) {
origYear := date.Year()
if hyear == origYear {
return date, nil
} else if hyear < origYear {
return HDate{}, errors.New("year " + strconv.Itoa(hyear) + " occurs before original date")
}
if hyear < origYear {
return HDate{}, fmt.Errorf("year %d occurs before original date", hyear)
}
isOrigLeap := IsLeapYear(origYear)
month := date.Month()
Expand Down
Loading
Loading