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
9 changes: 7 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Examples
>>> month = hebrewcal.Month(5781, 10)
>>> month.month_name()
'Teves'
>>> from pyluach.utils import Transliteration
>>> month.month_name(transliteration=Transliteration.MODERN_ISRAELI)
'Tevet'
>>> month.month_name(True)
'טבת'
>>> month + 3
Expand All @@ -73,11 +76,13 @@ Examples
... print(month.month_name())
Tishrei Cheshvan ...

>>> date = dates.GregorianDate(2010, 10, 6)
>>> date = dates.GregorianDate(2010, 10, 2)
>>> parshios.getparsha(date)
[0]
>>> parshios.getparsha_string(date, israel=True)
'Beraishis'
'Bereishis'
>>> parshios.getparsha_string(date, israel=True, transliteration=Transliteration.MODERN_ISRAELI)
'Bereshit'
>>> parshios.getparsha_string(date, hebrew=True)
'בראשית'
>>> new_date = dates.GregorianDate(2021, 3, 10)
Expand Down
41 changes: 29 additions & 12 deletions src/pyluach/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _day_of_holiday(self, israel, hebrew=False):
return str(day)
return ''

def fast_day(self, hebrew=False):
def fast_day(self, hebrew=False, transliteration=utils.Transliteration.ASHKENAZ):
"""Return name of fast day of date.

Parameters
Expand All @@ -224,20 +224,25 @@ def fast_day(self, hebrew=False):
``True`` if you want the fast day name in Hebrew letters. Default
is ``False``, which returns the name transliterated into English.

transliteration : enum, optional
Determines which style of transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation

Returns
-------
str or None
The name of the fast day or ``None`` if the date is not
a fast day.
"""
return utils._fast_day_string(self, hebrew)
return utils._fast_day_string(self, hebrew, transliteration)

def festival(
self,
israel=False,
hebrew=False,
include_working_days=True,
prefix_day=False
prefix_day=False,
transliteration=utils.Transliteration.ASHKENAZ
):
"""Return name of Jewish festival of date.

Expand All @@ -259,6 +264,9 @@ def festival(
prefix_day : bool, optional
``True`` to prefix multi day festivals with the day of the
festival. Default is ``False``.
transliteration : enum, optional
Determines which style of transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation

Returns
-------
Expand All @@ -278,15 +286,15 @@ def festival(
'Shavuos'
"""
name = utils._festival_string(
self, israel, hebrew, include_working_days
self, israel, hebrew, include_working_days, transliteration
)
if prefix_day and name is not None:
day = self._day_of_holiday(israel=israel, hebrew=hebrew)
if day:
return f'{day} {name}'
return name

def holiday(self, israel=False, hebrew=False, prefix_day=False):
def holiday(self, israel=False, hebrew=False, prefix_day=False, transliteration=utils.Transliteration.ASHKENAZ):
"""Return name of Jewish holiday of the date.

The holidays include the major and minor religious Jewish
Expand All @@ -303,6 +311,9 @@ def holiday(self, israel=False, hebrew=False, prefix_day=False):
prefix_day : bool, optional
``True`` to prefix multi day holidays with the day of the
holiday. Default is ``False``.
transliteration : enum, optional
Determines which style of transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation

Returns
-------
Expand All @@ -322,8 +333,8 @@ def holiday(self, israel=False, hebrew=False, prefix_day=False):
'Taanis Esther'
"""
return (
self.fast_day(hebrew=hebrew)
or self.festival(israel, hebrew, prefix_day=prefix_day)
self.fast_day(hebrew=hebrew, transliteration=transliteration)
or self.festival(israel, hebrew, prefix_day=prefix_day, transliteration=transliteration)
)


Expand Down Expand Up @@ -747,13 +758,14 @@ class HebrewDate(BaseDate, CalendarDateMixin):

====== ======= ===========================================================
Format Example Meaning
====== ======= ===========================================================
====== ======= =========================================================================
%a Sun Weekday as locale's abbreviated name
%A Sunday Weekday as locale's full name
%w 1 Weekday as decimal number 1-7 Sunday-Shabbos
%d 07 Day of the month as a 0-padded 2 digit decimal number
%-d 7 Day of the month as a decimal number
%B Iyar Month name transliterated into English
%B Teves Month name transliterated into English following Ashkenazi transliteration
%C Tevet Month name transliterated into English following Israeli transliteration
%m 02 Month as a 0-padded 2 digit decimal number
%-m 2 Month as a decimal number
%y 82, 01 Year without century as a zero-padded decimal number
Expand All @@ -766,7 +778,7 @@ class HebrewDate(BaseDate, CalendarDateMixin):
%*y תשפ״ב Year in Hebrew numerals without the thousands place
%*Y ה'תשפ״ב Year in Hebrew numerals with the thousands place
%% % A literal '%' character
====== ======= ===========================================================
====== ======= =========================================================================

Example
-------
Expand Down Expand Up @@ -895,6 +907,8 @@ def __format__(self, fmt):
new.append(format(self.day, '02d'))
elif curr == 'B':
new.append(self.month_name(False))
elif curr == 'C':
new.append(self.month_name(False, transliteration=utils.Transliteration.MODERN_ISRAELI))
elif curr == 'm':
new.append(format(self.month, '02d'))
elif curr.casefold() == 'y':
Expand Down Expand Up @@ -993,7 +1007,7 @@ def to_pydate(self):
def to_heb(self):
return self

def month_name(self, hebrew=False):
def month_name(self, hebrew=False, transliteration=utils.Transliteration.ASHKENAZ):
"""Return the name of the month.

Parameters
Expand All @@ -1002,12 +1016,15 @@ def month_name(self, hebrew=False):
``True`` if the month name should be in Hebrew characters.
Default is ``False`` which returns the month name
transliterated into English.
transliteration : enum, optional
Determines which style of transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation

Returns
-------
str
"""
return utils._month_name(self.year, self.month, hebrew)
return utils._month_name(self.year, self.month, hebrew, transliteration)

def hebrew_day(self, withgershayim=True):
"""Return the day of the month in Hebrew letters.
Expand Down
58 changes: 41 additions & 17 deletions src/pyluach/hebrewcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def _month_number(self):
"""Return month number 1-12 or 13, Tishrei - Elul."""
return list(Year(self.year)).index(self.month) + 1

def month_name(self, hebrew=False):
def month_name(self, hebrew=False, transliteration=utils.Transliteration.ASHKENAZ):
"""Return the name of the month.

Replaces `name` attribute.
Expand All @@ -396,13 +396,17 @@ def month_name(self, hebrew=False):
hebrew : bool, optional
`True` if the month name should be written with Hebrew letters
and False to be transliterated into English using the Ashkenazic
pronunciation. Default is `False`.
Transliteration. Default is `False`.

transliteration : enum, optional
Determines which style of Transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation

Returns
-------
str
"""
return utils._month_name(self.year, self.month, hebrew)
return utils._month_name(self.year, self.month, hebrew, transliteration=transliteration)

def month_string(self, thousands=False):
"""Return month and year in Hebrew.
Expand Down Expand Up @@ -574,13 +578,18 @@ class HebrewCalendar(calendar.Calendar):
hebrewyear : bool, optional
``True`` to show the year in Hebrew numerals. Default is ``False``,
which shows the year as a decimal number.
transliteration : enum, optional
Determines which style of Transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation


Attributes
----------
hebrewnumerals : bool
hebrewweekdays : bool
hebrewmonths : bool
hebrewyear : bool
transliteration: enum

Note
----
Expand All @@ -591,7 +600,7 @@ class HebrewCalendar(calendar.Calendar):

def __init__(
self, firstweekday=1, hebrewnumerals=True, hebrewweekdays=False,
hebrewmonths=False, hebrewyear=False
hebrewmonths=False, hebrewyear=False, transliteration=utils.Transliteration.ASHKENAZ
):
if not 1 <= firstweekday <= 7:
raise IllegalWeekdayError(firstweekday)
Expand All @@ -601,6 +610,7 @@ def __init__(
self.hebrewweekdays = hebrewweekdays
self.hebrewmonths = hebrewmonths
self.hebrewyear = hebrewyear
self.transliteration = transliteration

@property
def firstweekday(self):
Expand Down Expand Up @@ -866,6 +876,9 @@ class HebrewHTMLCalendar(HebrewCalendar, calendar.HTMLCalendar):
rtl : bool, optional
``True`` to arrange the months and the days of the month from
right to left. Default is ``False``.
transliteration : enum, optional
Determines which style of Transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation

Attributes
----------
Expand All @@ -878,15 +891,16 @@ class HebrewHTMLCalendar(HebrewCalendar, calendar.HTMLCalendar):

def __init__(
self, firstweekday=1, hebrewnumerals=True, hebrewweekdays=False,
hebrewmonths=False, hebrewyear=False, rtl=False
hebrewmonths=False, hebrewyear=False, rtl=False, transliteration=utils.Transliteration.ASHKENAZ
):
self.rtl = rtl
super().__init__(
firstweekday,
hebrewnumerals,
hebrewweekdays,
hebrewmonths,
hebrewyear
hebrewyear,
transliteration
)

def _rtl_str(self):
Expand Down Expand Up @@ -969,7 +983,7 @@ def formatmonthname(self, theyear, themonth, withyear=True):
------
str
"""
s = Month(theyear, themonth).month_name(self.hebrewmonths)
s = Month(theyear, themonth).month_name(self.hebrewmonths, transliteration=self.transliteration)
if withyear:
s = f'{s} {self.formatyearnumber(theyear)}'
return (
Expand Down Expand Up @@ -999,7 +1013,7 @@ def formatmonth(self, theyear, themonth, withyear=True):
f'class="{self.cssclass_month}"{self._rtl_str()}>'
)
a('\n')
a(self.formatmonthname(theyear, themonth, withyear=withyear))
a(self.formatmonthname(theyear, themonth, withyear=withyear, transliteration=self.transliteration))
a('\n')
a(self.formatweekheader())
a('\n')
Expand Down Expand Up @@ -1045,7 +1059,7 @@ def formatyear(self, theyear, width=3):
for m in months:
a('<td>')
a(self.formatmonth(
theyear, yearmonths[m-1], withyear=False
theyear, yearmonths[m-1], withyear=False, transliteration=self.transliteration
))
a('</td>')
a('</tr>')
Expand Down Expand Up @@ -1159,7 +1173,7 @@ def formatmonthname(
-------
str
"""
s = Month(theyear, themonth).month_name(self.hebrewmonths)
s = Month(theyear, themonth).month_name(self.hebrewmonths, transliteration=self.transliteration)
if withyear:
if self.hebrewyear:
year = to_hebrew_numeral(theyear)
Expand Down Expand Up @@ -1202,7 +1216,7 @@ def formatyear(self, theyear, w=2, l=1, c=6, m=3): # noqa: E741
months = range(m*i+1, min(m*(i+1)+1, len(yearmonths)+1))
a('\n'*l)
names = (
self.formatmonthname(theyear, yearmonths[k-1], colwidth, False)
self.formatmonthname(theyear, yearmonths[k-1], colwidth, False, transliteration=self.transliteration)
for k in months
)
a(calendar.formatstring(names, colwidth, c).rstrip())
Expand All @@ -1224,7 +1238,7 @@ def formatyear(self, theyear, w=2, l=1, c=6, m=3): # noqa: E741
return ''.join(v)


def fast_day(date, hebrew=False):
def fast_day(date, hebrew=False, transliteration=utils.Transliteration.ASHKENAZ):
"""Return name of fast day or None.

Parameters
Expand All @@ -1234,22 +1248,26 @@ def fast_day(date, hebrew=False):
hebrew : bool, optional
``True`` if you want the fast_day name in Hebrew letters. Default
is ``False``, which returns the name transliterated into English.
transliteration : enum, optional
Determines which style of transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation

Returns
-------
str or None
The name of the fast day or ``None`` if the given date is not
a fast day.
"""
return date.fast_day(hebrew)
return date.fast_day(hebrew, transliteration=transliteration)


def festival(
date,
israel=False,
hebrew=False,
include_working_days=True,
prefix_day=False
prefix_day=False,
transliteration=utils.Transliteration.ASHKENAZ
):
"""Return Jewish festival of given day.

Expand All @@ -1274,6 +1292,9 @@ def festival(
prefix_day : bool, optional
``True`` to prefix multi day festivals with the day of the
festival. Default is ``False``.
transliteration : enum, optional
Determines which style of transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation

Returns
-------
Expand All @@ -1293,10 +1314,10 @@ def festival(
>>> festival(shavuos, israel=True, prefix_day=True)
'Shavuos'
"""
return date.festival(israel, hebrew, include_working_days, prefix_day)
return date.festival(israel, hebrew, include_working_days, prefix_day, transliteration=transliteration)


def holiday(date, israel=False, hebrew=False, prefix_day=False):
def holiday(date, israel=False, hebrew=False, prefix_day=False, transliteration=utils.Transliteration.ASHKENAZ):
"""Return Jewish holiday of given date.

The holidays include the major and minor religious Jewish
Expand All @@ -1315,6 +1336,9 @@ def holiday(date, israel=False, hebrew=False, prefix_day=False):
prefix_day : bool, optional
``True`` to prefix multi day holidays with the day of the
holiday. Default is ``False``.
transliteration : enum, optional
Determines which style of transliteration English spellings should follow
Default is ``utils.Transliteration.ASHKENAZ`` for backward compatibility with the original pyluach implementation

Returns
-------
Expand All @@ -1334,4 +1358,4 @@ def holiday(date, israel=False, hebrew=False, prefix_day=False):
>>> holiday(taanis_esther, prefix_day=True)
'Taanis Esther'
"""
return date.holiday(israel, hebrew, prefix_day)
return date.holiday(israel, hebrew, prefix_day, transliteration=transliteration)
Loading