Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hebcal/hebcal-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.9.24
Choose a base ref
...
head repository: hebcal/hebcal-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# hebcal-go

[![Build Status](https://app.travis-ci.com/hebcal/hebcal-go.svg?branch=main)](https://app.travis-ci.com/hebcal/hebcal-go)
[![Build Status](https://github.com/hebcal/hebcal-go/actions/workflows/go.yml/badge.svg)](https://github.com/hebcal/hebcal-go/actions/workflows/go.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/hebcal/hebcal-go)](https://goreportcard.com/report/github.com/hebcal/hebcal-go)
[![GoDoc](https://pkg.go.dev/badge/github.com/hebcal/hebcal-go?status.svg)](https://pkg.go.dev/github.com/hebcal/hebcal-go)

4 changes: 3 additions & 1 deletion event/dafyomi.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package event

import (
"strconv"
"strings"

"github.com/hebcal/gematriya"
"github.com/hebcal/hdate"
@@ -24,7 +25,8 @@ func (ev dafYomiEvent) GetDate() hdate.HDate {

func (ev dafYomiEvent) Render(locale string) string {
name, _ := locales.LookupTranslation(ev.Daf.Name, locale)
if locale == "he" {
locale = strings.ToLower(locale)
if locale == "he" || locale == "he-x-nonikud" {
return name + " דף " + gematriya.Gematriya(ev.Daf.Blatt)
}
return name + " " + strconv.Itoa(ev.Daf.Blatt)
1 change: 1 addition & 0 deletions event/event_test.go
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ func TestHebrewDateEvent(t *testing.T) {
assert.Equal(t, "3rd of Sivan, 5781", ev.Render("en"))
assert.Equal(t, "ג׳ סִיוָן תשפ״א", ev.Render("he"))
assert.Equal(t, "3 Sziván 5781", ev.Render("hu"))
assert.Equal(t, "ג׳ סיון תשפ״א", ev.Render("he-x-NoNikud"))
}

func TestParshaEvent_Render(t *testing.T) {
6 changes: 4 additions & 2 deletions event/hdate.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package event

import (
"strconv"
"strings"

"github.com/dustin/go-humanize"
"github.com/hebcal/gematriya"
@@ -20,9 +21,10 @@ func (ev hebrewDateEvent) GetDate() hdate.HDate {
func (ev hebrewDateEvent) Render(locale string) string {
hd := ev.Date
enMonthName := hd.MonthName("en")
locale = strings.ToLower(locale)
switch locale {
case "he":
return gematriya.Gematriya(hd.Day()) + " " + hd.MonthName("he") + " " + gematriya.Gematriya(hd.Year())
case "he", "he-x-nonikud":
return gematriya.Gematriya(hd.Day()) + " " + hd.MonthName(locale) + " " + gematriya.Gematriya(hd.Year())
case "", "en", "sephardic", "ashkenazi",
"ashkenazi_litvish", "ashkenazi_poylish", "ashkenazi_standard":
return humanize.Ordinal(hd.Day()) + " of " + enMonthName +
38 changes: 37 additions & 1 deletion event/molad.go
Original file line number Diff line number Diff line change
@@ -2,8 +2,10 @@ package event

import (
"fmt"
"strings"

"github.com/hebcal/hdate"
"github.com/hebcal/hebcal-go/locales"
"github.com/hebcal/hebcal-go/molad"
)

@@ -25,9 +27,43 @@ func (ev moladEvent) GetDate() hdate.HDate {
return ev.Date
}

var heDayNames = []string{
"רִאשׁוֹן", "שֵׁנִי", "שְׁלִישִׁי", "רְבִיעִי", "חֲמִישִׁי", "שִׁישִּׁי", "שַׁבָּת",
}

const night = "בַּלַּ֥יְלָה"
const morning = "בַּבֹּקֶר"
const afternoon = "בַּצׇּהֳרַיִים"
const evening = "בָּעֶרֶב"

func (ev moladEvent) Render(locale string) string {
monthStr, _ := locales.LookupTranslation(ev.MonthName, locale)
locale = strings.ToLower(locale)
if locale == "he" || locale == "he-x-nonikud" {
dow := heDayNames[ev.Molad.Date.Weekday()]
var ampm string
if ev.Molad.Hours < 5 {
ampm = night
} else if ev.Molad.Hours < 12 {
ampm = morning
} else if ev.Molad.Hours < 17 {
ampm = afternoon
} else if ev.Molad.Hours < 21 {
ampm = evening
} else {
ampm = night
}
str := fmt.Sprintf("מוֹלָד הָלְּבָנָה %s יִהְיֶה בַּיּוֹם %s בשָׁבוּעַ, "+
"בְּשָׁעָה %d %s, ו-%d דַּקּוֹת "+"ו-%d חֲלָקִים",
monthStr, dow,
ev.Molad.Hours, ampm, ev.Molad.Minutes, ev.Molad.Chalakim)
if locale == "he-x-nonikud" {
str = locales.HebrewStripNikkud(str)
}
return str
}
return fmt.Sprintf("Molad %s: %s, %d minutes and %d chalakim after %d:00",
ev.MonthName, ev.Molad.Date.Weekday().String()[0:3],
monthStr, ev.Molad.Date.Weekday().String()[0:3],
ev.Molad.Minutes, ev.Molad.Chalakim, ev.Molad.Hours)
}

4 changes: 3 additions & 1 deletion event/nachyomi.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package event

import (
"strconv"
"strings"

"github.com/hebcal/gematriya"
"github.com/hebcal/hdate"
@@ -24,7 +25,8 @@ func (ev nachYomiEvent) GetDate() hdate.HDate {

func (ev nachYomiEvent) Render(locale string) string {
name, _ := locales.LookupTranslation(ev.Chapter.Name, locale)
if locale == "he" {
locale = strings.ToLower(locale)
if locale == "he" || locale == "he-x-nonikud" {
return name + " " + gematriya.Gematriya(ev.Chapter.Blatt)
}
return name + " " + strconv.Itoa(ev.Chapter.Blatt)
3 changes: 2 additions & 1 deletion event/parsha.go
Original file line number Diff line number Diff line change
@@ -24,12 +24,13 @@ func (ev parshaEvent) GetDate() hdate.HDate {
}

func (ev parshaEvent) Render(locale string) string {
locale = strings.ToLower(locale)
prefix, _ := locales.LookupTranslation("Parashat", locale)
name, _ := locales.LookupTranslation(ev.Parsha.Name[0], locale)
if len(ev.Parsha.Name) == 2 {
p2, _ := locales.LookupTranslation(ev.Parsha.Name[1], locale)
delim := "-"
if locale == "he" {
if locale == "he" || locale == "he-x-nonikud" {
delim = "־"
}
name = name + delim + p2
4 changes: 3 additions & 1 deletion event/yyomi.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package event

import (
"strconv"
"strings"

"github.com/hebcal/gematriya"
"github.com/hebcal/hdate"
@@ -25,7 +26,8 @@ func (ev yyomiEvent) GetDate() hdate.HDate {
func (ev yyomiEvent) Render(locale string) string {
yerushalmiStr, _ := locales.LookupTranslation("Yerushalmi", locale)
name, _ := locales.LookupTranslation(ev.Daf.Name, locale)
if locale == "he" {
locale = strings.ToLower(locale)
if locale == "he" || locale == "he-x-nonikud" {
return yerushalmiStr + " " + name + " דף " + gematriya.Gematriya(ev.Daf.Blatt)
}
return yerushalmiStr + " " + name + " " + strconv.Itoa(ev.Daf.Blatt)
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@ go 1.13
require github.com/stretchr/testify v1.8.1

require (
github.com/dustin/go-humanize v1.0.0
github.com/dustin/go-humanize v1.0.1
github.com/hebcal/gematriya v1.0.1
github.com/hebcal/greg v1.0.0
github.com/hebcal/hdate v1.0.1
github.com/hebcal/greg v1.0.1
github.com/hebcal/hdate v1.1.0
github.com/nathan-osman/go-sunrise v1.1.0
)
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/hebcal/gematriya v1.0.1 h1:lktI5tX4lxg2o2OIEQXGYiMWxL9VkbfOXa+/kamjrLQ=
github.com/hebcal/gematriya v1.0.1/go.mod h1:hQJm5ggDgm45RsnaaSrYB387VIBDI0Kcq5wglx7KVpI=
github.com/hebcal/greg v1.0.0 h1:F38VvHeYwhLIBtMQ4tl97jOfQhzeKX53Sa1T63RE31k=
github.com/hebcal/greg v1.0.0/go.mod h1:HhnDLPDm/dgcrANH5WYN9ol0tlkK/6mJVkWDIYhkKJM=
github.com/hebcal/hdate v1.0.1 h1:DkoN1oiOv5yrgXhrKdZCffpNsV5h6enXtiG7Rni28K0=
github.com/hebcal/hdate v1.0.1/go.mod h1:EXz7O48tnOqmTHC9wat7JJ2+f7OLZ2c4m+x4gnaiLcQ=
github.com/hebcal/greg v1.0.1 h1:NTZvxbFftReh+Ig8WluTvQTlviD5DmhxNmFh21BFJME=
github.com/hebcal/greg v1.0.1/go.mod h1:HhnDLPDm/dgcrANH5WYN9ol0tlkK/6mJVkWDIYhkKJM=
github.com/hebcal/hdate v1.1.0 h1:7kbsYc7pSpPtLgmMJG+RKa11DGzC6XeO6zR/3Iz/Ktw=
github.com/hebcal/hdate v1.1.0/go.mod h1:EXz7O48tnOqmTHC9wat7JJ2+f7OLZ2c4m+x4gnaiLcQ=
github.com/nathan-osman/go-sunrise v1.1.0 h1:ZqZmtmtzs8Os/DGQYi0YMHpuUqR/iRoJK+wDO0wTCw8=
github.com/nathan-osman/go-sunrise v1.1.0/go.mod h1:RcWqhT+5ShCZDev79GuWLayetpJp78RSjSWxiDowmlM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2 changes: 1 addition & 1 deletion hebcal/all_holidays_test.go
Original file line number Diff line number Diff line change
@@ -7,5 +7,5 @@ import (
)

func TestGetAllHolidaysForYear(t *testing.T) {
assert.Equal(t, 126, len(getAllHolidaysForYear(5783)))
assert.Equal(t, 127, len(getAllHolidaysForYear(5783)))
}
24 changes: 13 additions & 11 deletions hebcal/candles.go
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ type TimedEvent struct {

func NewTimedEvent(hd hdate.HDate, desc string, flags event.HolidayFlags, t time.Time,
sunsetOffset int, linkedEvent event.CalEvent, opts *CalOptions) TimedEvent {
if (t == time.Time{}) {
if t.IsZero() {
return TimedEvent{}
}
var emoji string
@@ -136,7 +136,7 @@ func makeCandleEvent(hd hdate.HDate, opts *CalOptions, ev event.CalEvent) TimedE
} else {
eventTime = z.Tzeit(opts.HavdalahDeg)
}
if (eventTime == time.Time{}) {
if eventTime.IsZero() {
return TimedEvent{} // no sunset
}
desc := "Candle lighting"
@@ -162,8 +162,8 @@ func makeChanukahCandleLighting(ev event.HolidayEvent, opts *CalOptions) TimedEv
year, month, day := hd.Greg()
gregDate := time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
z := zmanim.New(loc, gregDate)
candleLightingTime := z.Dusk()
if (candleLightingTime == time.Time{}) {
candleLightingTime := z.BeinHashmashos()
if candleLightingTime.IsZero() {
return TimedEvent{} // no sunset
}
return TimedEvent{
@@ -245,23 +245,25 @@ func dailyZemanim(date hdate.HDate, opts *CalOptions) []event.CalEvent {
{"Alot haShachar", z.AlotHaShachar()},
{"Misheyakir", z.Misheyakir()},
{"Misheyakir Machmir", z.MisheyakirMachmir()},
{"Dawn", z.Dawn()},
{"Sunrise", z.Sunrise()},
{"Kriat Shema, sof zeman", z.SofZmanShma()},
{"Kriat Shema, sof zeman (MGA)", z.SofZmanShmaMGA()},
{"Tefilah, sof zeman", z.SofZmanTfilla()},
{"Kriat Shema, sof zeman (GRA)", z.SofZmanShma()},
{"Tefilah, sof zeman (MGA)", z.SofZmanTfillaMGA()},
{"Tefilah, sof zeman (GRA)", z.SofZmanTfilla()},
{"Chatzot hayom", z.Chatzot()},
{"Mincha Gedolah", z.MinchaGedola()},
{"Mincha Ketanah", z.MinchaKetana()},
{"Plag HaMincha", z.PlagHaMincha()},
{"Sunset", z.Sunset()},
{"Dusk", z.Dusk()},
{"Bein HaShemashot", z.BeinHashmashos()},
{"Tzeit HaKochavim", z.Tzeit(zmanim.Tzeit3SmallStars)},
}
events := make([]event.CalEvent, len(times))
for i, ev := range times {
events[i] = NewTimedEvent(date, ev.desc, event.ZMANIM, ev.t, 0, nil, opts)
events := make([]event.CalEvent, 0, len(times))
for _, zman := range times {
if !zman.t.IsZero() {
ev := NewTimedEvent(date, zman.desc, event.ZMANIM, zman.t, 0, nil, opts)
events = append(events, ev)
}
}
return events
}
72 changes: 62 additions & 10 deletions hebcal/hebcal_test.go
Original file line number Diff line number Diff line change
@@ -176,18 +176,18 @@ func TestHebrewCalendarChanukahCandles(t *testing.T) {
assert.Equal(nil, err)
assert.Equal(14, len(events))
expected := []string{
"2022-12-18 Chanukah: 1 Candle: 5:04",
"2022-12-19 Chanukah: 2 Candles: 5:05",
"2022-12-20 Chanukah: 3 Candles: 5:05",
"2022-12-21 Chanukah: 4 Candles: 5:06",
"2022-12-22 Chanukah: 5 Candles: 5:06",
"2022-12-18 Chanukah: 1 Candle: 4:56",
"2022-12-19 Chanukah: 2 Candles: 4:57",
"2022-12-20 Chanukah: 3 Candles: 4:57",
"2022-12-21 Chanukah: 4 Candles: 4:58",
"2022-12-22 Chanukah: 5 Candles: 4:58",
"2022-12-23 Chanukah: 6 Candles: 4:00",
"2022-12-23 Candle lighting: 4:00",
"2022-12-24 Chag HaBanot",
"2022-12-24 Chanukah: 7 Candles: 5:20",
"2022-12-24 Rosh Chodesh Tevet",
"2022-12-24 Havdalah: 5:20",
"2022-12-25 Chanukah: 8 Candles: 5:08",
"2022-12-25 Chanukah: 8 Candles: 5:00",
"2022-12-25 Rosh Chodesh Tevet",
"2022-12-26 Chanukah: 8th Day",
}
@@ -419,18 +419,17 @@ func TestDailyZemanim(t *testing.T) {
"2021-11-27 Alot haShachar: 05:21",
"2021-11-27 Misheyakir: 05:47",
"2021-11-27 Misheyakir Machmir: 05:54",
"2021-11-27 Dawn: 06:18",
"2021-11-27 Sunrise: 06:49",
"2021-11-27 Kriat Shema, sof zeman: 09:11",
"2021-11-27 Kriat Shema, sof zeman (MGA): 08:35",
"2021-11-27 Tefilah, sof zeman: 09:58",
"2021-11-27 Kriat Shema, sof zeman (GRA): 09:11",
"2021-11-27 Tefilah, sof zeman (MGA): 09:34",
"2021-11-27 Tefilah, sof zeman (GRA): 09:58",
"2021-11-27 Chatzot hayom: 11:33",
"2021-11-27 Mincha Gedolah: 11:57",
"2021-11-27 Mincha Ketanah: 14:19",
"2021-11-27 Plag HaMincha: 15:18",
"2021-11-27 Sunset: 16:17",
"2021-11-27 Dusk: 16:48",
"2021-11-27 Bein HaShemashot: 16:41",
"2021-11-27 Tzeit HaKochavim: 17:02",
}
assert.Equal(t, expected, actual)
@@ -546,3 +545,56 @@ func TestYear1(t *testing.T) {
assert.Equal(t, nil, err)
assert.Equal(t, 79, len(events))
}

func TestHebrewCalendarZmanimOnly(t *testing.T) {
assert := assert.New(t)
loc := zmanim.LookupCity("Amsterdam")
opts := hebcal.CalOptions{
Start: hdate.New(5783, hdate.Sivan, 9),
End: hdate.New(5783, hdate.Sivan, 9),
Location: loc,
DailyZmanim: true,
}
events, err := hebcal.HebrewCalendar(&opts)
assert.Equal(nil, err)
assert.Equal(14, len(events)) // not 15 (no Alot HaShachar)
}

func TestHebrewCalendar1752CE(t *testing.T) {
assert := assert.New(t)
opts := hebcal.CalOptions{
Year: 5513,
IsHebrewYear: true,
AddHebrewDates: true,
}
events0, err := hebcal.HebrewCalendar(&opts)
events := events0[:18]

assert.Equal(nil, err)
expected := []string{
"1752-08-28 29th of Elul, 5512",
"1752-08-28 Erev Rosh Hashana",
"1752-08-29 1st of Tishrei, 5513",
"1752-08-29 Rosh Hashana 5513",
"1752-08-30 2nd of Tishrei, 5513",
"1752-08-30 Rosh Hashana II",
"1752-08-31 3rd of Tishrei, 5513",
"1752-08-31 Tzom Gedaliah",
"1752-09-01 4th of Tishrei, 5513",
"1752-09-02 5th of Tishrei, 5513",
"1752-09-14 6th of Tishrei, 5513",
"1752-09-15 7th of Tishrei, 5513",
"1752-09-16 8th of Tishrei, 5513",
"1752-09-16 Shabbat Shuva",
"1752-09-17 9th of Tishrei, 5513",
"1752-09-17 Erev Yom Kippur",
"1752-09-18 10th of Tishrei, 5513",
"1752-09-18 Yom Kippur",
}
actual := make([]string, 0, len(events))
for _, ev := range events {
line := fmt.Sprintf("%s %s", hd2iso(ev.GetDate()), ev.Render("en"))
actual = append(actual, line)
}
assert.Equal(expected, actual)
}
5 changes: 4 additions & 1 deletion hebcal/holidays.go
Original file line number Diff line number Diff line change
@@ -218,10 +218,13 @@ var staticModernHolidays = []struct {
{firstYear: 5765, mm: hdate.Tamuz, dd: 29, desc: "Jabotinsky Day",
satPostponeToSun: true},
{firstYear: 5769, mm: hdate.Cheshvan, dd: 29, desc: "Sigd",
chul: true, suppressEmoji: true},
chul: true, suppressEmoji: true, friSatMovetoThu: true},
{firstYear: 5777, mm: hdate.Nisan, dd: 10, desc: "Yom HaAliyah",
chul: true},
{firstYear: 5777, mm: hdate.Cheshvan, dd: 7, desc: "Yom HaAliyah School Observance"},
// https://www.gov.il/he/departments/policies/2012_des5234
{firstYear: 5773, mm: hdate.Tevet, dd: 21, desc: "Hebrew Language Day",
friSatMovetoThu: true},
}

func tzomGedaliahDate(rh hdate.HDate) hdate.HDate {
Loading