Skip to content

Commit

Permalink
Partial implementation of Tanakh Yomi
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Jan 22, 2024
1 parent 39897c1 commit bddb83d
Show file tree
Hide file tree
Showing 8 changed files with 1,064 additions and 106 deletions.
44 changes: 44 additions & 0 deletions src/DafPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {Locale, gematriya} from '@hebcal/core';

/**
* Represents a tractate and page number
*/
export class DafPage {
/**
* Initializes a daf yomi instance
* @param {string} name
* @param {number} blatt
*/
constructor(name, blatt) {
this.name = name;
this.blatt = blatt;
}
/**
* @return {number}
*/
getBlatt() {
return this.blatt;
}
/**
* @return {string}
*/
getName() {
return this.name;
}
/**
* Formats (with translation) the dafyomi result as a string like "Pesachim 34"
* @param {string} [locale] Optional locale name (defaults to active locale).
* @return {string}
*/
render(locale) {
locale = locale || Locale.getLocaleName();
if (typeof locale === 'string') {
locale = locale.toLowerCase();
}
if (locale === 'he' || locale === 'he-x-nonikud') {
return Locale.gettext(this.name, locale) + ' דף ' +
gematriya(this.blatt);
}
return Locale.gettext(this.name, locale) + ' ' + this.blatt;
}
}
61 changes: 61 additions & 0 deletions src/DafPageEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {Event} from '@hebcal/core';

export const dafYomiSefaria = {
'Berachot': 'Berakhot',
'Rosh Hashana': 'Rosh Hashanah',
'Gitin': 'Gittin',
'Baba Kamma': 'Bava Kamma',
'Baba Metzia': 'Bava Metzia',
'Baba Batra': 'Bava Batra',
'Bechorot': 'Bekhorot',
'Arachin': 'Arakhin',
'Midot': 'Middot',
'Shekalim': 'Jerusalem_Talmud_Shekalim',
};

/**
* Event wrapper around a DafPage instance
*/
export class DafPageEvent extends Event {
/**
* @param {HDate} date
* @param {DafPage} daf
* @param {number} mask
*/
constructor(date, daf, mask) {
super(date, daf.render('en'), mask);
this.daf = daf;
}
/**
* Returns Daf Yomi name including the 'Daf Yomi: ' prefix (e.g. "Daf Yomi: Pesachim 107").
* @param {string} [locale] Optional locale name (defaults to active locale).
* @return {string}
*/
render(locale) {
return this.daf.render(locale);
}
/**
* Returns Daf Yomi name without the 'Daf Yomi: ' prefix (e.g. "Pesachim 107").
* @param {string} [locale] Optional locale name (defaults to active locale).
* @return {string}
*/
renderBrief(locale) {
return this.daf.render(locale);
}
/**
* Returns a link to sefaria.org or dafyomi.org
* @return {string}
*/
url() {
const daf = this.daf;
const tractate = daf.getName();
const blatt = daf.getBlatt();
if (tractate == 'Kinnim' || tractate == 'Midot') {
return `https://www.dafyomi.org/index.php?masechta=meilah&daf=${blatt}a`;
} else {
const name0 = dafYomiSefaria[tractate] || tractate;
const name = name0.replace(/ /g, '_');
return `https://www.sefaria.org/${name}.${blatt}a?lang=bi`;
}
}
}
3 changes: 2 additions & 1 deletion src/dafWeekly.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {flags, greg} from '@hebcal/core';
import {shas0, findDaf, DafPageEvent} from './dafyomi.js';
import {shas0, findDaf} from './dafyomi.js';
import {DafPageEvent} from './DafPageEvent.js';
import {getAbsDate, checkTooEarly} from './common.js';

const startDate = new Date(2005, 2, 6);
Expand Down
107 changes: 3 additions & 104 deletions src/dafyomi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {greg, Event, flags, Locale, gematriya} from '@hebcal/core';
import {greg, flags, Locale} from '@hebcal/core';
import {getAbsDate, checkTooEarly} from './common.js';
import {DafPage} from './DafPage.js';
import {DafPageEvent} from './DafPageEvent.js';

const osdate = new Date(1923, 8, 11);
export const osday = greg.greg2abs(osdate);
Expand Down Expand Up @@ -71,49 +73,6 @@ export const shas0 = [
return {name: m[0], blatt: m[1]};
});

/**
* Represents a tractate and page number
*/
export class DafPage {
/**
* Initializes a daf yomi instance
* @param {string} name
* @param {number} blatt
*/
constructor(name, blatt) {
this.name = name;
this.blatt = blatt;
}
/**
* @return {number}
*/
getBlatt() {
return this.blatt;
}
/**
* @return {string}
*/
getName() {
return this.name;
}
/**
* Formats (with translation) the dafyomi result as a string like "Pesachim 34"
* @param {string} [locale] Optional locale name (defaults to active locale).
* @return {string}
*/
render(locale) {
locale = locale || Locale.getLocaleName();
if (typeof locale === 'string') {
locale = locale.toLowerCase();
}
if (locale === 'he' || locale === 'he-x-nonikud') {
return Locale.gettext(this.name, locale) + ' דף ' +
gematriya(this.blatt);
}
return Locale.gettext(this.name, locale) + ' ' + this.blatt;
}
}

/**
* @private
* @param {Date|HDate|number} date Gregorian or Hebrew date
Expand Down Expand Up @@ -198,66 +157,6 @@ export class DafYomi extends DafPage {
}
}

const dafYomiSefaria = {
'Berachot': 'Berakhot',
'Rosh Hashana': 'Rosh Hashanah',
'Gitin': 'Gittin',
'Baba Kamma': 'Bava Kamma',
'Baba Metzia': 'Bava Metzia',
'Baba Batra': 'Bava Batra',
'Bechorot': 'Bekhorot',
'Arachin': 'Arakhin',
'Midot': 'Middot',
'Shekalim': 'Jerusalem_Talmud_Shekalim',
};

/**
* Event wrapper around a DafPage instance
*/
export class DafPageEvent extends Event {
/**
* @param {HDate} date
* @param {DafPage} daf
* @param {number} mask
*/
constructor(date, daf, mask) {
super(date, daf.render('en'), mask);
this.daf = daf;
}
/**
* Returns Daf Yomi name including the 'Daf Yomi: ' prefix (e.g. "Daf Yomi: Pesachim 107").
* @param {string} [locale] Optional locale name (defaults to active locale).
* @return {string}
*/
render(locale) {
return this.daf.render(locale);
}
/**
* Returns Daf Yomi name without the 'Daf Yomi: ' prefix (e.g. "Pesachim 107").
* @param {string} [locale] Optional locale name (defaults to active locale).
* @return {string}
*/
renderBrief(locale) {
return this.daf.render(locale);
}
/**
* Returns a link to sefaria.org or dafyomi.org
* @return {string}
*/
url() {
const daf = this.daf;
const tractate = daf.getName();
const blatt = daf.getBlatt();
if (tractate == 'Kinnim' || tractate == 'Midot') {
return `https://www.dafyomi.org/index.php?masechta=meilah&daf=${blatt}a`;
} else {
const name0 = dafYomiSefaria[tractate] || tractate;
const name = name0.replace(/ /g, '_');
return `https://www.sefaria.org/${name}.${blatt}a?lang=bi`;
}
}
}

/**
* Event wrapper around a DafYomi instance
*/
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import './register.js';
export {DafPage, DafPageEvent, DafYomi, DafYomiEvent} from './dafyomi.js';
export {DafPage} from './DafPage.js';
export {DafPageEvent} from './DafPageEvent.js';
export {DafYomi, DafYomiEvent} from './dafyomi.js';
export {MishnaYomiEvent} from './MishnaYomiEvent.js';
export {MishnaYomiIndex, mishnaYomiStart} from './mishnaYomi.js';
export {NachYomiEvent} from './NachYomiEvent.js';
Expand Down
10 changes: 10 additions & 0 deletions src/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {dailyRambam1, DailyRambamEvent, rambam1Start} from './rambam.js';
import {shemiratHaLashon, ShemiratHaLashonEvent, shemiratHaLashonStart} from './shemiratHaLashon.js';
import {dailyPsalms, PsalmsEvent} from './psalms.js';
import {dafWeekly, DafWeeklyEvent, dafWeeklyStart} from './dafWeekly.js';
import {tanakhYomi, tanakhYomiStart, TanakhYomiEvent} from './tanakhYomi.js';
import poHe from './he.po.js';
import poAshkenazi from './ashkenazi.po.js';

Expand Down Expand Up @@ -117,6 +118,15 @@ DailyLearning.addCalendar('dafWeeklySunday', function(hd) {
return new DafWeeklyEvent(hd, daf);
});

DailyLearning.addCalendar('tanakhYomi', function(hd) {
const abs = hd.abs();
if (abs < tanakhYomiStart) {
return null;
}
const daf = tanakhYomi(abs);
return new TanakhYomiEvent(hd, daf);
});

Locale.addTranslations('he', poHe);
Locale.addTranslations('h', poHe);
Locale.addTranslations('ashkenazi', poAshkenazi);
Expand Down
Loading

0 comments on commit bddb83d

Please sign in to comment.