Skip to content

Commit

Permalink
Support he-x-NoNikud
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Aug 12, 2024
1 parent 0520203 commit b3ca7b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
2 changes: 2 additions & 0 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ func ExampleHDate_MonthName() {
hd := hdate.New(5765, hdate.Adar2, 22)
fmt.Println(hd.MonthName("en"))
fmt.Println(hd.MonthName("he"))
fmt.Println(hd.MonthName("he-x-NoNikud"))
// Output:
// Adar II
// אַדָר ב׳
// אדר ב׳
}

func ExampleHDate_IsLeapYear() {
Expand Down
45 changes: 26 additions & 19 deletions hdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,21 @@ var longMonthNames = []string{
"Nisan",
}

var heMonthNames = map[HMonth]string{
Adar1: "אַדָר א׳",
Adar2: "אַדָר ב׳",
Av: "אָב",
Cheshvan: "חֶשְׁוָן",
Elul: "אֱלוּל",
Iyyar: "אִיָיר",
Kislev: "כִּסְלֵו",
Nisan: "נִיסָן",
Shvat: "שְׁבָט",
Sivan: "סִיוָן",
Tamuz: "תַּמּוּז",
Tevet: "טֵבֵת",
Tishrei: "תִשְׁרֵי",
var heAdar = []string{"אַדָר", "אדר"}
var heMonthNames = map[HMonth][]string{
Adar1: {"אַדָר א׳", "אדר א׳"},
Adar2: {"אַדָר ב׳", "אדר ב׳"},
Av: {"אָב", "אב"},
Cheshvan: {"חֶשְׁוָן", "חשון"},
Elul: {"אֱלוּל", "אלול"},
Iyyar: {"אִיָיר", "אייר"},
Kislev: {"כִּסְלֵו", "כסלו"},
Nisan: {"נִיסָן", "ניסן"},
Shvat: {"שְׁבָט", "שבט"},
Sivan: {"סִיוָן", "סיון"},
Tamuz: {"תַּמּוּז", "תמוז"},
Tevet: {"טֵבֵת", "טבת"},
Tishrei: {"תִשְׁרֵי", "תשרי"},
}

// String returns the English name of the month ("Nisan", "Iyyar", ...).
Expand Down Expand Up @@ -397,13 +398,19 @@ func (hd HDate) IsLeapYear() bool {
// (e.g. "Tishrei", "Sh'vat", "Adar II").
func (hd HDate) MonthName(locale string) string {
month := hd.Month()
if locale == "he" {
if month == Adar1 && !hd.IsLeapYear() {
return "אַדָר"
isAdar := month == Adar1 && !hd.IsLeapYear()
locale = s.ToLower(locale)
if locale == "he" || locale == "he-x-nonikud" {
idx := 0
if locale == "he-x-nonikud" {
idx = 1
}
return heMonthNames[month]
if isAdar {
return heAdar[idx]
}
return heMonthNames[month][idx]
}
if month == Adar1 && !hd.IsLeapYear() {
if isAdar {
return "Adar"
}
return month.String()
Expand Down
4 changes: 4 additions & 0 deletions hdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ func TestMonthNames2(t *testing.T) {
assert := assert.New(t)
hd := hdate.New(5782, hdate.Adar1, 15)
assert.Equal("Adar I", hd.MonthName("en"))
assert.Equal("אַדָר א׳", hd.MonthName("he"))
assert.Equal("אדר א׳", hd.MonthName("he-x-NoNikud"))
hd = hdate.New(5783, hdate.Adar1, 15)
assert.Equal("Adar", hd.MonthName("en"))
assert.Equal("אַדָר", hd.MonthName("he"))
assert.Equal("אדר", hd.MonthName("he-x-NoNikud"))
}

func TestAdar2ResetToAdar1(t *testing.T) {
Expand Down

0 comments on commit b3ca7b5

Please sign in to comment.