-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add myEventsToClassicApi for triennial refactor
- Loading branch information
Showing
5 changed files
with
54 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {flags} from '@hebcal/core'; | ||
import {formatAliyahWithBook} from '@hebcal/leyning'; | ||
import { | ||
eventsToClassicApiHeader, eventToClassicApiObject, | ||
} from '@hebcal/rest-api'; | ||
import {getTriennialForParshaHaShavua} from '@hebcal/triennial'; | ||
import {readJSON} from './readJSON.js'; | ||
|
||
export const pkg = readJSON('../package.json'); | ||
|
||
export function myEventsToClassicApi(events, options, leyningOff) { | ||
const obj = eventsToClassicApiHeader(events, options); | ||
if (typeof obj.version === 'string') { | ||
obj.version += '-' + pkg.version; | ||
} | ||
obj.items = events.map((ev) => { | ||
const apiObj = eventToClassicApiObject(ev, options, !leyningOff); | ||
if (!leyningOff && | ||
(ev.getFlags() & flags.PARSHA_HASHAVUA) && | ||
ev.getDate().getFullYear() >= 5745) { | ||
const triReading = getTriennialForParshaHaShavua(ev, options.il); | ||
const aliyot = triReading?.aliyot; | ||
if (aliyot) { | ||
const triAliyot = {}; | ||
for (const [num, aliyah] of Object.entries(aliyot)) { | ||
if (typeof aliyah !== 'undefined') { | ||
const k = num === 'M' ? 'maftir' : num; | ||
triAliyot[k] = formatAliyahWithBook(aliyah); | ||
} | ||
} | ||
apiObj.leyning.triennial = triAliyot; | ||
} | ||
} | ||
return apiObj; | ||
}); | ||
return obj; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters