diff --git a/src/calendar-model/generator.test.ts b/src/calendar-model/generator.test.ts index 52837fc0..acefbe26 100644 --- a/src/calendar-model/generator.test.ts +++ b/src/calendar-model/generator.test.ts @@ -1,8 +1,11 @@ import test from 'ava' import { UserSettings } from './user-settings.ts' import { LeiningGenerator } from './generator.ts' -import { HDate, months } from '@hebcal/core' -import { LeiningDate } from './model-types.ts' +import { HDate, Locale, months } from '@hebcal/core' +import { LeiningAliyah, LeiningDate } from './model-types.ts' +import hebrewNumeralFromInteger from '../hebrew-numeral.ts' +import { Ref } from '../ref.ts' +import { getBookName } from './hebcal-conversions.ts' const testSettings: UserSettings = { ashkenazi: true, @@ -26,43 +29,69 @@ for (let year = 5780; year < 5800; year++) { test('generates יום כיפור', (t) => { t.snapshot( - stripDate(generator.createLeiningDate(new HDate(10, months.TISHREI, 5784))) + dumpLeiningDate(new HDate(10, months.TISHREI, 5784)), + 'These tests verify the returned information, in easily readable format' ) }) test('generates שמחת תורה', (t) => { - t.snapshot( - stripDate(generator.createLeiningDate(new HDate(23, months.TISHREI, 5784))) - ) + t.snapshot(dumpLeiningDate(new HDate(23, months.TISHREI, 5784))) }) test('generates תענית אסתר', (t) => { - t.snapshot( - stripDate(generator.createLeiningDate(new HDate(13, months.ADAR_II, 5785))) - ) + t.snapshot(dumpLeiningDate(new HDate(13, months.ADAR_II, 5785))) }) test('generates פורים', (t) => { - t.snapshot( - stripDate(generator.createLeiningDate(new HDate(14, months.ADAR_II, 5784))) - ) + t.snapshot(dumpLeiningDate(new HDate(14, months.ADAR_II, 5784))) }) test('generates ערב תשעה באב', (t) => { - t.snapshot( - stripDate(generator.createLeiningDate(new HDate(8, months.AV, 5784))) - ) + t.snapshot(dumpLeiningDate(new HDate(8, months.AV, 5784))) }) test('generates תשעה באב', (t) => { - t.snapshot( - stripDate(generator.createLeiningDate(new HDate(9, months.AV, 5784))) - ) + t.snapshot(dumpLeiningDate(new HDate(9, months.AV, 5784))) }) test('generates שבת ראש חודש חנוכה', (t) => { + t.snapshot(dumpLeiningDate(new HDate(30, months.KISLEV, 5782))) +}) + +/** Prints the information in a `LeiningDate`, to be easily readable in the Markdown snapshot. */ +function dumpLeiningDate(date: HDate) { + const ld = generator.createLeiningDate(date) + if (!ld) return null + return { + date: ld.id, + title: ld.title, + leinings: ld.leinings.map((o) => ({ + isParsha: o.isParsha, + runs: o.runs.map((r) => ({ + id: r.id, + type: r.type, + scroll: r.scroll, + aliyot: r.aliyot.map( + // TODO(haftara): Render book name, once we have those + (a) => + `${a.index}: ${bookName(a)} ${dumpRef(a.start)} - ${dumpRef(a.end)}` + ), + })), + })), + } +} +function bookName(a: LeiningAliyah) { + return Locale.gettext(getBookName(a.start), 'he-x-nonikud') +} + +function dumpRef(ref: Ref) { + return `${hebrewNumeralFromInteger(ref.c)}:${hebrewNumeralFromInteger(ref.v)}` +} + +test('generates the full LeiningDate object for יום כיפור', (t) => { t.snapshot( - stripDate(generator.createLeiningDate(new HDate(30, months.KISLEV, 5782))) + stripDate(generator.createLeiningDate(new HDate(10, months.TISHREI, 5784))), + 'This test verified the full structure of the LeiningDate interface' ) }) diff --git a/src/calendar-model/generator.test.ts.md b/src/calendar-model/generator.test.ts.md index 08b53879..0a145d35 100644 --- a/src/calendar-model/generator.test.ts.md +++ b/src/calendar-model/generator.test.ts.md @@ -6,256 +6,65 @@ Generated by [AVA](https://avajs.dev). ## generates יום כיפור -> Snapshot 1 +> These tests verify the returned information, in easily readable format { - id: '2023-09-25', + date: '2023-09-25', leinings: [ { - date: [Circular], - id: 'שחרית', isParsha: false, runs: [ { aliyot: [ - { - end: { - b: 3, - c: 16, - scroll: 'torah', - v: 6, - }, - index: 1, - start: { - b: 3, - c: 16, - scroll: 'torah', - v: 1, - }, - }, - { - end: { - b: 3, - c: 16, - scroll: 'torah', - v: 11, - }, - index: 2, - start: { - b: 3, - c: 16, - scroll: 'torah', - v: 7, - }, - }, - { - end: { - b: 3, - c: 16, - scroll: 'torah', - v: 17, - }, - index: 3, - start: { - b: 3, - c: 16, - scroll: 'torah', - v: 12, - }, - }, - { - end: { - b: 3, - c: 16, - scroll: 'torah', - v: 24, - }, - index: 4, - start: { - b: 3, - c: 16, - scroll: 'torah', - v: 18, - }, - }, - { - end: { - b: 3, - c: 16, - scroll: 'torah', - v: 30, - }, - index: 5, - start: { - b: 3, - c: 16, - scroll: 'torah', - v: 25, - }, - }, - { - end: { - b: 3, - c: 16, - scroll: 'torah', - v: 34, - }, - index: 6, - start: { - b: 3, - c: 16, - scroll: 'torah', - v: 31, - }, - }, + '1: Leviticus טז:א - טז:ו', + '2: Leviticus טז:ז - טז:יא', + '3: Leviticus טז:יב - טז:יז', + '4: Leviticus טז:יח - טז:כד', + '5: Leviticus טז:כה - טז:ל', + '6: Leviticus טז:לא - טז:לד', ], id: '2023-09-25:shacharis,main', - leining: [Circular], scroll: 'torah', type: 'Main', }, { aliyot: [ - { - end: { - b: 4, - c: 29, - scroll: 'torah', - v: 11, - }, - index: 'Maftir', - start: { - b: 4, - c: 29, - scroll: 'torah', - v: 7, - }, - }, + 'Maftir: Numbers כט:ז - כט:יא', ], id: '2023-09-25:shacharis,maftir', - leining: [Circular], scroll: 'torah', type: 'מפטיר', }, { aliyot: [ - { - end: { - b: 1, - c: 58, - scroll: 'esther', - v: 14, - }, - index: undefined, - start: { - b: 1, - c: 57, - scroll: 'esther', - v: 14, - }, - }, + 'undefined: ישעיהו נז:יד - נח:יד', ], id: '2023-09-25:shacharis,haftara', - leining: [Circular], - scroll: 'esther', + scroll: 'isaiah', type: 'הפטרה', }, ], }, { - date: [Circular], - id: 'מנחה', isParsha: false, runs: [ { aliyot: [ - { - end: { - b: 3, - c: 18, - scroll: 'torah', - v: 5, - }, - index: 1, - start: { - b: 3, - c: 18, - scroll: 'torah', - v: 1, - }, - }, - { - end: { - b: 3, - c: 18, - scroll: 'torah', - v: 21, - }, - index: 2, - start: { - b: 3, - c: 18, - scroll: 'torah', - v: 6, - }, - }, - { - end: { - b: 3, - c: 18, - scroll: 'torah', - v: 30, - }, - index: 'Maftir', - start: { - b: 3, - c: 18, - scroll: 'torah', - v: 22, - }, - }, + '1: Leviticus יח:א - יח:ה', + '2: Leviticus יח:ו - יח:כא', + 'Maftir: Leviticus יח:כב - יח:ל', ], id: '2023-09-25:mincha,main', - leining: [Circular], scroll: 'torah', type: 'Main', }, { aliyot: [ - { - end: { - b: 1, - c: 4, - scroll: 'esther', - v: 11, - }, - index: undefined, - start: { - b: 1, - c: 1, - scroll: 'esther', - v: 1, - }, - }, - { - end: { - b: 1, - c: 7, - scroll: 'esther', - v: 20, - }, - index: undefined, - start: { - b: 1, - c: 7, - scroll: 'esther', - v: 18, - }, - }, + 'undefined: יונה א:א - ד:יא', + 'undefined: מיכה ז:יח - ז:כ', ], id: '2023-09-25:mincha,haftara', - leining: [Circular], - scroll: 'esther', + scroll: 'jonah', type: 'הפטרה', }, ], @@ -269,178 +78,46 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 { - id: '2023-10-08', + date: '2023-10-08', leinings: [ { - date: [Circular], - id: 'שחרית', isParsha: false, runs: [ { aliyot: [ - { - end: { - b: 5, - c: 33, - scroll: 'torah', - v: 7, - }, - index: 1, - start: { - b: 5, - c: 33, - scroll: 'torah', - v: 1, - }, - }, - { - end: { - b: 5, - c: 33, - scroll: 'torah', - v: 12, - }, - index: 2, - start: { - b: 5, - c: 33, - scroll: 'torah', - v: 8, - }, - }, - { - end: { - b: 5, - c: 33, - scroll: 'torah', - v: 17, - }, - index: 3, - start: { - b: 5, - c: 33, - scroll: 'torah', - v: 13, - }, - }, - { - end: { - b: 5, - c: 33, - scroll: 'torah', - v: 21, - }, - index: 4, - start: { - b: 5, - c: 33, - scroll: 'torah', - v: 18, - }, - }, - { - end: { - b: 5, - c: 33, - scroll: 'torah', - v: 26, - }, - index: 5, - start: { - b: 5, - c: 33, - scroll: 'torah', - v: 22, - }, - }, - { - end: { - b: 5, - c: 34, - scroll: 'torah', - v: 12, - }, - index: 6, - start: { - b: 5, - c: 33, - scroll: 'torah', - v: 27, - }, - }, + '1: Deuteronomy לג:א - לג:ז', + '2: Deuteronomy לג:ח - לג:יב', + '3: Deuteronomy לג:יג - לג:יז', + '4: Deuteronomy לג:יח - לג:כא', + '5: Deuteronomy לג:כב - לג:כו', + '6: Deuteronomy לג:כז - לד:יב', ], id: '2023-10-08:shacharis,main', - leining: [Circular], scroll: 'torah', type: 'Main', }, { aliyot: [ - { - end: { - b: 1, - c: 2, - scroll: 'torah', - v: 3, - }, - index: 7, - start: { - b: 1, - c: 1, - scroll: 'torah', - v: 1, - }, - }, + '7: Genesis א:א - ב:ג', ], id: '2023-10-08:shacharis,last-aliyah', - leining: [Circular], scroll: 'torah', type: 'שביעי', - }, - { - aliyot: [ - { - end: { - b: 4, - c: 30, - scroll: 'torah', - v: 1, - }, - index: 'Maftir', - start: { - b: 4, - c: 29, - scroll: 'torah', - v: 35, - }, - }, + }, + { + aliyot: [ + 'Maftir: Numbers כט:לה - ל:א', ], id: '2023-10-08:shacharis,maftir', - leining: [Circular], scroll: 'torah', type: 'מפטיר', }, { aliyot: [ - { - end: { - b: 1, - c: 1, - scroll: 'esther', - v: 18, - }, - index: undefined, - start: { - b: 1, - c: 1, - scroll: 'esther', - v: 1, - }, - }, + 'undefined: יהושוע א:א - א:יח', ], id: '2023-10-08:shacharis,haftara', - leining: [Circular], - scroll: 'esther', + scroll: 'joshua', type: 'הפטרה', }, ], @@ -454,184 +131,60 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 { - id: '2025-03-13', + date: '2025-03-13', leinings: [ { - date: [Circular], - id: 'שחרית', isParsha: false, runs: [ { aliyot: [ - { - end: { - b: 2, - c: 32, - scroll: 'torah', - v: 14, - }, - index: 1, - start: { - b: 2, - c: 32, - scroll: 'torah', - v: 11, - }, - }, - { - end: { - b: 2, - c: 34, - scroll: 'torah', - v: 3, - }, - index: 2, - start: { - b: 2, - c: 34, - scroll: 'torah', - v: 1, - }, - }, - { - end: { - b: 2, - c: 34, - scroll: 'torah', - v: 10, - }, - index: 3, - start: { - b: 2, - c: 34, - scroll: 'torah', - v: 4, - }, - }, + '1: Exodus לב:יא - לב:יד', + '2: Exodus לד:א - לד:ג', + '3: Exodus לד:ד - לד:י', ], id: '2025-03-13:shacharis,main', - leining: [Circular], scroll: 'torah', type: 'Main', }, ], }, { - date: [Circular], - id: 'מנחה', isParsha: false, runs: [ { aliyot: [ - { - end: { - b: 2, - c: 32, - scroll: 'torah', - v: 14, - }, - index: 1, - start: { - b: 2, - c: 32, - scroll: 'torah', - v: 11, - }, - }, - { - end: { - b: 2, - c: 34, - scroll: 'torah', - v: 3, - }, - index: 2, - start: { - b: 2, - c: 34, - scroll: 'torah', - v: 1, - }, - }, - { - end: { - b: 2, - c: 34, - scroll: 'torah', - v: 10, - }, - index: 'Maftir', - start: { - b: 2, - c: 34, - scroll: 'torah', - v: 4, - }, - }, + '1: Exodus לב:יא - לב:יד', + '2: Exodus לד:א - לד:ג', + 'Maftir: Exodus לד:ד - לד:י', ], id: '2025-03-13:mincha,main', - leining: [Circular], scroll: 'torah', type: 'Main', }, { aliyot: [ - { - end: { - b: 1, - c: 56, - scroll: 'esther', - v: 8, - }, - index: undefined, - start: { - b: 1, - c: 55, - scroll: 'esther', - v: 6, - }, - }, + 'undefined: ישעיהו נה:ו - נו:ח', ], id: '2025-03-13:mincha,haftara', - leining: [Circular], - scroll: 'esther', + scroll: 'isaiah', type: 'הפטרה', }, ], }, { - date: [Circular], - id: 'מגילה', isParsha: false, runs: [ { aliyot: [ - { - end: { - b: 1, - c: 10, - scroll: 'esther', - v: 3, - }, - index: undefined, - start: { - b: 1, - c: 1, - scroll: 'esther', - v: 1, - }, - }, + 'undefined: אסתר א:א - י:ג', ], id: '2025-03-13:megillah,megillah', - leining: [Circular], scroll: 'esther', type: 'מגילה', }, ], }, { - date: [Circular], - id: 'מעריב', isParsha: false, runs: [], }, @@ -644,93 +197,31 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 { - id: '2024-03-24', + date: '2024-03-24', leinings: [ { - date: [Circular], - id: 'מגילה', isParsha: false, runs: [ { aliyot: [ - { - end: { - b: 1, - c: 10, - scroll: 'esther', - v: 3, - }, - index: undefined, - start: { - b: 1, - c: 1, - scroll: 'esther', - v: 1, - }, - }, + 'undefined: אסתר א:א - י:ג', ], id: '2024-03-24:megillah,megillah', - leining: [Circular], scroll: 'esther', type: 'מגילה', }, ], }, { - date: [Circular], - id: 'שחרית', isParsha: false, runs: [ { aliyot: [ - { - end: { - b: 2, - c: 17, - scroll: 'torah', - v: 10, - }, - index: 1, - start: { - b: 2, - c: 17, - scroll: 'torah', - v: 8, - }, - }, - { - end: { - b: 2, - c: 17, - scroll: 'torah', - v: 13, - }, - index: 2, - start: { - b: 2, - c: 17, - scroll: 'torah', - v: 11, - }, - }, - { - end: { - b: 2, - c: 17, - scroll: 'torah', - v: 16, - }, - index: 3, - start: { - b: 2, - c: 17, - scroll: 'torah', - v: 14, - }, - }, + '1: Exodus יז:ח - יז:י', + '2: Exodus יז:יא - יז:יג', + '3: Exodus יז:יד - יז:טז', ], id: '2024-03-24:shacharis,main', - leining: [Circular], scroll: 'torah', type: 'Main', }, @@ -745,54 +236,145 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 { - id: '2024-08-12', + date: '2024-08-12', leinings: [ { - date: [Circular], - id: 'מגילה', isParsha: false, runs: [ { aliyot: [ - { - end: { - b: 1, - c: 5, - scroll: 'esther', - v: 22, - }, - index: undefined, - start: { - b: 1, - c: 1, - scroll: 'esther', - v: 1, - }, - }, + 'undefined: איכה א:א - ה:כב', + ], + id: '2024-08-12:megillah,megillah', + scroll: 'lamentations', + type: 'מגילה', + }, + ], + }, + { + isParsha: false, + runs: [], + }, + ], + title: 'ערב תשעה באב', + } + +## generates תשעה באב + +> Snapshot 1 + + { + date: '2024-08-13', + leinings: [ + { + isParsha: false, + runs: [ + { + aliyot: [ + '1: Deuteronomy ד:כה - ד:כט', + '2: Deuteronomy ד:ל - ד:לה', + '3: Deuteronomy ד:לו - ד:מ', + ], + id: '2024-08-13:shacharis,main', + scroll: 'torah', + type: 'Main', + }, + { + aliyot: [ + 'undefined: ירמיהו ח:יג - ט:כג', + ], + id: '2024-08-13:shacharis,haftara', + scroll: 'jeremiah', + type: 'הפטרה', + }, + ], + }, + { + isParsha: false, + runs: [ + { + aliyot: [ + '1: Exodus לב:יא - לב:יד', + '2: Exodus לד:א - לד:ג', + 'Maftir: Exodus לד:ד - לד:י', + ], + id: '2024-08-13:mincha,main', + scroll: 'torah', + type: 'Main', + }, + { + aliyot: [ + 'undefined: ישעיהו נה:ו - נו:ח', + ], + id: '2024-08-13:mincha,haftara', + scroll: 'isaiah', + type: 'הפטרה', + }, + ], + }, + ], + title: 'תשעה באב', + } + +## generates שבת ראש חודש חנוכה + +> Snapshot 1 + + { + date: '2021-12-04', + leinings: [ + { + isParsha: true, + runs: [ + { + aliyot: [ + '1: Genesis מא:א - מא:יד', + '2: Genesis מא:טו - מא:לח', + '3: Genesis מא:לט - מא:נב', + '4: Genesis מא:נג - מב:יח', + '5: Genesis מב:יט - מג:טו', + '6: Genesis מג:טז - מד:יז', + ], + id: '2021-12-04:shacharis,main', + scroll: 'torah', + type: 'Main', + }, + { + aliyot: [ + '7: Numbers כח:ט - כח:טו', + ], + id: '2021-12-04:shacharis,last-aliyah', + scroll: 'torah', + type: 'שביעי', + }, + { + aliyot: [ + 'Maftir: Numbers ז:מב - ז:מז', + ], + id: '2021-12-04:shacharis,maftir', + scroll: 'torah', + type: 'מפטיר', + }, + { + aliyot: [ + 'undefined: זכריה ב:יד - ד:ז', ], - id: '2024-08-12:megillah,megillah', - leining: [Circular], - scroll: 'esther', - type: 'מגילה', + id: '2021-12-04:shacharis,haftara', + scroll: 'zechariah', + type: 'הפטרה', }, ], }, - { - date: [Circular], - id: 'מעריב', - isParsha: false, - runs: [], - }, ], - title: 'ערב תשעה באב', + title: 'פרשת מקץ', } -## generates תשעה באב +## generates the full LeiningDate object for יום כיפור -> Snapshot 1 +> This test verified the full structure of the LeiningDate interface { - id: '2024-08-13', + id: '2023-09-25', leinings: [ { date: [Circular], @@ -803,273 +385,202 @@ Generated by [AVA](https://avajs.dev). aliyot: [ { end: { - b: 5, - c: 4, + b: 3, + c: 16, scroll: 'torah', - v: 29, + v: 6, }, index: 1, start: { - b: 5, - c: 4, + b: 3, + c: 16, scroll: 'torah', - v: 25, + v: 1, }, }, { end: { - b: 5, - c: 4, + b: 3, + c: 16, scroll: 'torah', - v: 35, + v: 11, }, index: 2, start: { - b: 5, - c: 4, + b: 3, + c: 16, scroll: 'torah', - v: 30, + v: 7, }, }, { end: { - b: 5, - c: 4, + b: 3, + c: 16, scroll: 'torah', - v: 40, + v: 17, }, index: 3, start: { - b: 5, - c: 4, + b: 3, + c: 16, scroll: 'torah', - v: 36, + v: 12, }, }, - ], - id: '2024-08-13:shacharis,main', - leining: [Circular], - scroll: 'torah', - type: 'Main', - }, - { - aliyot: [ { end: { - b: 1, - c: 9, - scroll: 'esther', - v: 23, + b: 3, + c: 16, + scroll: 'torah', + v: 24, }, - index: undefined, + index: 4, start: { - b: 1, - c: 8, - scroll: 'esther', - v: 13, + b: 3, + c: 16, + scroll: 'torah', + v: 18, }, }, - ], - id: '2024-08-13:shacharis,haftara', - leining: [Circular], - scroll: 'esther', - type: 'הפטרה', - }, - ], - }, - { - date: [Circular], - id: 'מנחה', - isParsha: false, - runs: [ - { - aliyot: [ { end: { - b: 2, - c: 32, + b: 3, + c: 16, scroll: 'torah', - v: 14, + v: 30, }, - index: 1, + index: 5, start: { - b: 2, - c: 32, + b: 3, + c: 16, scroll: 'torah', - v: 11, + v: 25, }, }, { end: { - b: 2, - c: 34, + b: 3, + c: 16, scroll: 'torah', - v: 3, + v: 34, }, - index: 2, + index: 6, start: { - b: 2, - c: 34, + b: 3, + c: 16, scroll: 'torah', - v: 1, + v: 31, }, }, + ], + id: '2023-09-25:shacharis,main', + leining: [Circular], + scroll: 'torah', + type: 'Main', + }, + { + aliyot: [ { end: { - b: 2, - c: 34, + b: 4, + c: 29, scroll: 'torah', - v: 10, + v: 11, }, index: 'Maftir', start: { - b: 2, - c: 34, + b: 4, + c: 29, scroll: 'torah', - v: 4, + v: 7, }, }, ], - id: '2024-08-13:mincha,main', + id: '2023-09-25:shacharis,maftir', leining: [Circular], scroll: 'torah', - type: 'Main', + type: 'מפטיר', }, { aliyot: [ { end: { b: 1, - c: 56, - scroll: 'esther', - v: 8, + c: 58, + scroll: 'isaiah', + v: 14, }, index: undefined, start: { b: 1, - c: 55, - scroll: 'esther', - v: 6, + c: 57, + scroll: 'isaiah', + v: 14, }, }, ], - id: '2024-08-13:mincha,haftara', + id: '2023-09-25:shacharis,haftara', leining: [Circular], - scroll: 'esther', + scroll: 'isaiah', type: 'הפטרה', }, ], }, - ], - title: 'תשעה באב', - } - -## generates שבת ראש חודש חנוכה - -> Snapshot 1 - - { - id: '2021-12-04', - leinings: [ { date: [Circular], - id: 'שחרית', - isParsha: true, + id: 'מנחה', + isParsha: false, runs: [ { aliyot: [ { end: { - b: 1, - c: 41, + b: 3, + c: 18, scroll: 'torah', - v: 14, + v: 5, }, index: 1, start: { - b: 1, - c: 41, + b: 3, + c: 18, scroll: 'torah', v: 1, }, }, { end: { - b: 1, - c: 41, + b: 3, + c: 18, scroll: 'torah', - v: 38, + v: 21, }, index: 2, start: { - b: 1, - c: 41, - scroll: 'torah', - v: 15, - }, - }, - { - end: { - b: 1, - c: 41, - scroll: 'torah', - v: 52, - }, - index: 3, - start: { - b: 1, - c: 41, - scroll: 'torah', - v: 39, - }, - }, - { - end: { - b: 1, - c: 42, - scroll: 'torah', - v: 18, - }, - index: 4, - start: { - b: 1, - c: 41, - scroll: 'torah', - v: 53, - }, - }, - { - end: { - b: 1, - c: 43, - scroll: 'torah', - v: 15, - }, - index: 5, - start: { - b: 1, - c: 42, + b: 3, + c: 18, scroll: 'torah', - v: 19, + v: 6, }, }, { end: { - b: 1, - c: 44, + b: 3, + c: 18, scroll: 'torah', - v: 17, + v: 30, }, - index: 6, + index: 'Maftir', start: { - b: 1, - c: 43, + b: 3, + c: 18, scroll: 'torah', - v: 16, + v: 22, }, }, ], - id: '2021-12-04:shacharis,main', + id: '2023-09-25:mincha,main', leining: [Circular], scroll: 'torah', type: 'Main', @@ -1078,73 +589,42 @@ Generated by [AVA](https://avajs.dev). aliyot: [ { end: { - b: 4, - c: 28, - scroll: 'torah', - v: 15, - }, - index: 7, - start: { - b: 4, - c: 28, - scroll: 'torah', - v: 9, - }, - }, - ], - id: '2021-12-04:shacharis,last-aliyah', - leining: [Circular], - scroll: 'torah', - type: 'שביעי', - }, - { - aliyot: [ - { - end: { - b: 4, - c: 7, - scroll: 'torah', - v: 47, + b: 1, + c: 4, + scroll: 'jonah', + v: 11, }, - index: 'Maftir', + index: undefined, start: { - b: 4, - c: 7, - scroll: 'torah', - v: 42, + b: 1, + c: 1, + scroll: 'jonah', + v: 1, }, }, - ], - id: '2021-12-04:shacharis,maftir', - leining: [Circular], - scroll: 'torah', - type: 'מפטיר', - }, - { - aliyot: [ { end: { b: 1, - c: 4, - scroll: 'esther', - v: 7, + c: 7, + scroll: 'micah', + v: 20, }, index: undefined, start: { b: 1, - c: 2, - scroll: 'esther', - v: 14, + c: 7, + scroll: 'micah', + v: 18, }, }, ], - id: '2021-12-04:shacharis,haftara', + id: '2023-09-25:mincha,haftara', leining: [Circular], - scroll: 'esther', + scroll: 'jonah', type: 'הפטרה', }, ], }, ], - title: 'פרשת מקץ', + title: 'יום כפור', } diff --git a/src/calendar-model/generator.test.ts.snap b/src/calendar-model/generator.test.ts.snap index 6fcf4a7a..08daf16d 100644 Binary files a/src/calendar-model/generator.test.ts.snap and b/src/calendar-model/generator.test.ts.snap differ diff --git a/src/calendar-model/hebcal-conversions.ts b/src/calendar-model/hebcal-conversions.ts index c9bd999f..92f2f274 100644 --- a/src/calendar-model/hebcal-conversions.ts +++ b/src/calendar-model/hebcal-conversions.ts @@ -1,7 +1,7 @@ /** @fileoverview Contains generic helpers to convert between @hebcal types and our model types. */ import { Aliyah, calculateNumVerses } from '@hebcal/leyning' -import { Ref, RefWithScroll, ScrollName } from '../ref.ts' +import { RefWithScroll, ScrollName } from '../ref.ts' import { LeiningAliyah } from './model-types.ts' /** Maps scrolls with multiple books to their book names as used in @hebcal. */ @@ -46,7 +46,10 @@ export function toLeiningAliyah( } /** Counts the number of פסוקים between two locations. Returns zero if both arguments are equal. */ -export function numVersesBetween(start: Ref, end: RefWithScroll): number { +export function numVersesBetween( + start: RefWithScroll, + end: RefWithScroll +): number { // Note that this is currently only used in חומש. // Construct a fake Aliyah to pass to hebcal's utility function. @@ -54,12 +57,17 @@ export function numVersesBetween(start: Ref, end: RefWithScroll): number { b: `${start.v}:${start.c}`, e: `${end.c}:${end.v}`, // If the book isn't in our map, convert our lowercase name to @hebcal's title-case name - k: bookNames[end.scroll]?.[start.b] ?? toTitleCase(end.scroll), + k: getBookName(start), } // This helper includes the ending verse, which is not what we want here. return calculateNumVerses(aliyah) - 1 } +/** Gets a @hebcal-compatible book name. */ +export function getBookName(end: RefWithScroll): string { + return bookNames[end.scroll]?.[end.b] ?? toTitleCase(end.scroll) +} + function toTitleCase(str: string) { return str.charAt(0).toUpperCase() + str.slice(1) } diff --git a/src/calendar-model/test-utils.ts b/src/calendar-model/test-utils.ts index 853d9d68..29ccece7 100644 --- a/src/calendar-model/test-utils.ts +++ b/src/calendar-model/test-utils.ts @@ -1,4 +1,4 @@ -import { RenderedLineInfo } from './scroll-view-model' +import { RenderedLineInfo } from './scroll-view-model.ts' export function renderLine(line: RenderedLineInfo): string { return `${line.labels}: ${line.text