Skip to content

Commit

Permalink
New URL feature for print; select which month you can start from
Browse files Browse the repository at this point in the history
  • Loading branch information
NightScript370 committed Jun 4, 2024
1 parent 76f020f commit 0bf3e09
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 30 deletions.
36 changes: 18 additions & 18 deletions assets/js/WebsiteCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class WebsiteCalendar extends KosherZmanim.JewishCalendar {
english: this.getDate().toLocaleString('en-u-ca-hebrew', {month: 'long', year: "numeric", day: "numeric"}),
hebrew: [
hNum.formatHebrewNumber(this.getJewishDayOfMonth()),
this.getDate().toLocaleString('he-u-ca-hebrew', {month: 'long'}) + ',',
monthForLocale('he-u-ca-hebrew', 'long', 'hebrew', this.getDate().year)[this.getDate().month] + ',',
hNum.formatHebrewNumber(this.getJewishYear()),
].join(' ')
}
Expand Down Expand Up @@ -442,10 +442,8 @@ class WebsiteCalendar extends KosherZmanim.JewishCalendar {
const days = this.getDayOfOmer() % 7;

// Hebrew Attributes
const hbName = n2heWords(this.getDayOfOmer());

const hbDayWords = ["יוֹם", "יָמִים"]
const hbTitle = [hbName, hbDayWords[(this.getDayOfOmer() >= 2 && this.getDayOfOmer() <= 10 ? 1 : 0)]];
const hbTitle = [n2heWords(this.getDayOfOmer()), hbDayWords[(this.getDayOfOmer() >= 2 && this.getDayOfOmer() <= 10 ? 1 : 0)]];
if (this.getDayOfOmer() == 1)
hbTitle.reverse()

Expand All @@ -466,10 +464,8 @@ class WebsiteCalendar extends KosherZmanim.JewishCalendar {
}

// Hebrew Attributes
const ruName = n2ruWords(this.getDayOfOmer());

const ruDayWords = ["ём", "ямим"]
const ruTitle = [ruName, ruDayWords[(this.getDayOfOmer() >= 2 && this.getDayOfOmer() <= 10 ? 1 : 0)]];
const ruTitle = [n2ruWords(this.getDayOfOmer()), ruDayWords[(this.getDayOfOmer() >= 2 && this.getDayOfOmer() <= 10 ? 1 : 0)]];
if (this.getDayOfOmer() == 1)
ruTitle.reverse()

Expand Down Expand Up @@ -827,22 +823,26 @@ export function getOrdinal (n, htmlSup=false) {
* @param {string | string[]} localeName
* @param {"short" | "long" | "narrow"} [weekday]
*/
export function daysForLocale(localeName, weekday = 'long') {
const {format} = new Intl.DateTimeFormat(localeName, { weekday });
const array = [...Array(7).keys()]
.map((day) => format(new Date(Date.UTC(2021, 8, day))));
array.unshift(undefined);
return array;
export function daysForLocale(localeName, weekday = 'long', calendar = 'iso8601') {
const baseDate = KosherZmanim.Temporal.PlainDate.from({ year: 2024, month: 1, day: 1 }).withCalendar(calendar);
const dayLocale = [...Array(baseDate.daysInWeek).keys()]
.map((day) => baseDate.with({ day: day + 1 }).toLocaleString(localeName, { weekday }));

dayLocale.unshift(undefined);
return dayLocale;
}

/**
* @param {string | string[]} localeName
* @param {"short" | "long" | "narrow" | "numeric" | "2-digit"} [weekday]
* @param {"short" | "long" | "narrow" | "numeric" | "2-digit"} [month]
*/
export function monthForLocale(localeName, weekday = 'long') {
const {format} = new Intl.DateTimeFormat(localeName, { month: weekday });
return [...Array(13).keys()]
.map((day) => format(new Date(Date.UTC(2021, day, 1))));
export function monthForLocale(localeName, month = 'long', calendar = 'iso8601', year=2024) {
const baseDate = KosherZmanim.Temporal.PlainDate.from({ year: 2024, month: 1, day: 1 }).withCalendar(calendar).with({ year });
const monthLocale = [...Array(baseDate.monthsInYear).keys()]
.map((monthNum) => baseDate.with({ month: monthNum + 1 }).toLocaleString(localeName, { month }));

monthLocale.unshift(undefined);
return monthLocale;
}

export class HebrewNumberFormatter {
Expand Down
13 changes: 9 additions & 4 deletions assets/js/features/print-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import { settings } from "../settings/handler.js";
import n2wordsOrdinal from "../misc/n2wordsOrdinal.js";
import { Previewer } from "../../libraries/paged.js"

if (new URLSearchParams(window.location.search).has('lessContrast')) {
const printParam = new URLSearchParams(window.location.search);
if (printParam.has('lessContrast')) {
document.documentElement.style.setProperty('--bs-body-bg', 'snow');
document.documentElement.style.setProperty('--bs-body-color', '#1A0033');
}
const calcMonthStart = (printParam.has('currentMonth') ?
KosherZmanim.Temporal.Now.plainDateISO().withCalendar(settings.language() == 'en' ? 'iso8601' : 'hebrew').month
: 1
);

const hNum = new HebrewNumberFormatter();

Expand All @@ -25,7 +30,7 @@ const glArgs = Object.values(settings.location).map(numberFunc => numberFunc())
const geoLocation = new KosherZmanim.GeoLocation(...glArgs);

const jCal = new WebsiteLimudCalendar();
jCal.setDate(jCal.getDate().with({ day: 1, month: 1 }))
jCal.setDate(jCal.getDate().with({ day: 1, month: calcMonthStart }))
jCal.setInIsrael((geoLocation.getLocationName() || "").toLowerCase().includes('israel'));
const zmanCalc = (
!jCal.getInIsrael() && settings.calendarToggle.hourCalculators() == "degrees"
Expand Down Expand Up @@ -432,8 +437,8 @@ const rightSide = document.createElement("div");
rightSide.classList.add("sides", "d-flex", "justify-content-around")
footer.appendChild(rightSide);

let plainDateForLoop = jCal.getDate().withCalendar(settings.language() == 'en' ? 'iso8601' : 'hebrew').with({ month: 1, day: 1 })
for (let mIndex = 1; mIndex <= plainDateForLoop.monthsInYear; mIndex++) {
let plainDateForLoop = jCal.getDate().withCalendar(settings.language() == 'en' ? 'iso8601' : 'hebrew').with({ month: calcMonthStart, day: 1 })
for (let mIndex = plainDateForLoop.month; mIndex <= plainDateForLoop.monthsInYear; mIndex++) {
plainDateForLoop = plainDateForLoop.with({ month: mIndex });
jCal.setDate(plainDateForLoop.withCalendar("iso8601"));

Expand Down
2 changes: 1 addition & 1 deletion assets/js/flyers/shabbat.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ for (const sefiraElement of document.querySelectorAll('[data-sefira-backday]'))
separator.style.setProperty('--bs-border-width', '2px');
separator.style.opacity = 'unset';
sefiraElement.appendChild(separator);
const ruSefiraText = "нисан " + omerJCal.getOmerInfo().title.ru.mainCount + ` лаóмер` +
const ruSefiraText = "hаём " + omerJCal.getOmerInfo().title.ru.mainCount + ` лаóмер` +
(omerJCal.getDayOfOmer() >= 7 ? (`, шеһэм ` + omerJCal.getOmerInfo().title.ru.subCount.toString()) : '');

sefiraElement.appendChild(document.createTextNode(ruSefiraText.toLocaleUpperCase()))
Expand Down
6 changes: 3 additions & 3 deletions assets/libraries/kosherZmanim/kosher-zmanim.esm.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions assets/libraries/kosherZmanim/kosher-zmanim.esm.js.map

Large diffs are not rendered by default.

0 comments on commit 0bf3e09

Please sign in to comment.