@sembokulove (Missing place)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

在線プログラムが日にちの判断をしてくれないです。具体的いうと、diatymejudge内にあるconst holidaysが聞かないです。

解決したいこと

ここに解決したい内容を記載してください。

例)
diatypejudgeファイルで指定されている、const holidays関数が効き目なしです。

発生している問題・エラー


出ているエラーメッセージを入力

例)

NameError (uninitialized constant World)

在宣 質問-11 20250610 Tue.png
uploading...0

該当するソースコード

// diaTypeJudge.js から holidays 配列をインポートまたはコピーしてきたと仮定します。

function getJapaneseHolidays(year) {
    const holidays = [];

    // 固定祝日
    holidays.push({ month: 1, date: 1 });   // 元日
    holidays.push({ month: 2, date: 11 });  // 建国記念の日
    holidays.push({ month: 2, date: 23 });  // 天皇誕生日 (2020年以降)
    holidays.push({ month: 4, date: 29 });  // 昭和の日
    holidays.push({ month: 5, date: 3 });   // 憲法記念日
    holidays.push({ month: 5, date: 5 });   // こどもの日
    holidays.push({ month: 11, date: 3 });  // 文化の日
    holidays.push({ month: 11, date: 23 }); // 勤労感謝の日

    // 移動祝日 (ハッピーマンデー制度)
    // 成人の日 (1月の第2月曜日)
    holidays.push(getNthDayOfMonth(year, 1, DayOfWeek.MONDAY, 2));
    // 海の日 (7月の第3月曜日)
    holidays.push(getNthDayOfMonth(year, 7, DayOfWeek.MONDAY, 3));
    // 敬老の日 (9月の第3月曜日)
    holidays.push(getNthDayOfMonth(year, 9, DayOfWeek.MONDAY, 3));
    // スポーツの日 (10月の第2月曜日)
    // ※2020年は特例で7月24日、2021年は8月9日、それ以外は10月第2月曜
    // ここでは一般的な10月第2月曜として記述します。特例対応が必要なら別途ロジックを追加。
    holidays.push(getNthDayOfMonth(year, 10, DayOfWeek.MONDAY, 2));


    // 春分の日と秋分の日は計算が複雑なため、簡略化した近似値または外部データを使用するのが一般的ですが、
    // ここでは簡略化されたロジック(一般的な日付の範囲)で記述します。
    // 正確な計算は国立天文台などのデータを参照するか、より高度なライブラリが必要です。
    // 仮に春分の日を3月20日頃、秋分の日を9月23日頃とします。
    // 厳密な計算が必要な場合は、複雑な天文計算を行うか、信頼できるAPI等からデータを取得する必要があります。
    // 例: 春分の日 (約3月20日)
    const equinoxSpring = calculateVernalEquinox(year); // 後述の関数
    if (equinoxSpring) {
        holidays.push({ month: equinoxSpring.getMonth() + 1, date: equinoxSpring.getDate() });
    }
    // 例: 秋分の日 (約9月23日)
    const equinoxAutumn = calculateAutumnalEquinox(year); // 後述の関数
    if (equinoxAutumn) {
        holidays.push({ month: equinoxAutumn.getMonth() + 1, date: equinoxAutumn.getDate() });
    }

    // 振替休日(特定の祝日が日曜日の場合に翌平日が休日になる)の計算
    // これは、isHolidayOrSunday 関数内で、祝日判定後に自動的に判定されるようにします。
    // holidays配列に直接追加せず、isHolidayOrSundayのロジックで対応する方が柔軟です。

    return holidays;
}


// N番目の特定の曜日の日付を取得するヘルパー関数
function getNthDayOfMonth(year, month, dayOfWeek, n) {
    let count = 0;
    let day = 1;
    let targetDate = null;
    while (true) {
        const dateObj = new Date(year, month - 1, day);
        if (dateObj.getMonth() !== month - 1) { // 月が変わったら終了
            break;
        }
        if (dateObj.getDay() === dayOfWeek) {
            count++;
            if (count === n) {
                targetDate = dateObj;
                break;
            }
        }
        day++;
    }
    if (targetDate) {
        return { year: targetDate.getFullYear(), month: targetDate.getMonth() + 1, date: targetDate.getDate() };
    }
    return null; // 見つからなかった場合
}

// 春分の日・秋分の日を計算する簡易関数 (あくまで簡易版であり、厳密な計算ではありません)
// 正確な計算は非常に複雑なため、国立天文台などのデータを用いるのが確実です。
// ここでは、一般的な傾向に基づいた近似値で実装します。
// 例: 春分の日 (3月20日または21日)
function calculateVernalEquinox(year) {
    // 1980年~2099年の間に3月20日または21日
    // 簡易的なロジックとして、3月20日をデフォルトとし、必要に応じて21日を考慮する
    let day = 20;
    // 2012年以降、4年に一度21日になる傾向 (うるう年と関連)
    if (year >= 2012 && year % 4 === 0) { // 簡易的な例
        // 厳密な計算はさらに複雑ですが、ここではあくまで例
        if (year === 2012 || year === 2016 || year === 2020 || year === 2024 || year === 2028) { // 適当な例
            day = 20; // 実際は2020年は20日、2024年は20日など
        } else {
            // day = 21; // これは非常に簡易な例で、年によって異なる
        }
    }
    // 国立天文台のデータに基づく例(あくまで例示で、実際の年によって異なる)
    // 2020年: 3/20, 2021年: 3/20, 2022年: 3/20, 2023年: 3/21, 2024年: 3/20, 2025年: 3/20
    // この関数は簡易的なものであり、正確性を保証するものではありません。
    return new Date(year, 2, day); // 月は0から始まるため 2 = 3月
}

// 秋分の日 (9月22日または23日)
function calculateAutumnalEquinox(year) {
    // 1980年~2099年の間に9月22日または23日
    let day = 23;
    // 簡易的なロジックとして、9月23日をデフォルトとし、必要に応じて22日を考慮する
    if (year >= 2012 && year % 4 === 0) { // 簡易的な例
        // 厳密な計算はさらに複雑ですが、ここではあくまで例
        if (year === 2012 || year === 2016 || year === 2020 || year === 2024 || year === 2028) { // 適当な例
            day = 22; // 実際は2020年は22日、2024年は22日など
        } else {
            // day = 23; // これは非常に簡易な例で、年によって異なる
        }
    }
    // 国立天文台のデータに基づく例(あくまで例示で、実際の年によって異なる)
    // 2020年: 9/22, 2021年: 9/23, 2022年: 9/23, 2023年: 9/23, 2024年: 9/22, 2025年: 9/23
    // この関数は簡易的なものであり、正確性を保証するものではありません。
    return new Date(year, 8, day); // 月は0から始まるため 8 = 9月
}


// isHolidayOrSunday 関数を修正し、振替休日にも対応させる
function isHolidayOrSunday(year, month, day) {
    const dateObj = new Date(year, month - 1, day);

    // 1. まず日曜日であるかチェック
    if (dateObj.getDay() === DayOfWeek.SUNDAY) {
        return true; // 日曜日
    }

    // 2. その年の祝日リストを動的に取得
    const currentYearHolidays = getJapaneseHolidays(year);

    // 3. 祝日リストに日付が含まれているかチェック
    for (let i = 0; i < currentYearHolidays.length; i++) {
        if (currentYearHolidays[i].month === month && currentYearHolidays[i].date === day) {
            return true; // 祝日
        }
    }

    // 4. 振替休日かチェック(祝日が日曜日の場合、翌平日が振替休日)
    // その日が月曜日以降で、かつ前日が日曜日で祝日である場合
    if (dateObj.getDay() === DayOfWeek.MONDAY) { // 月曜日のみをチェック
        const previousDay = new Date(year, month - 1, day - 1); // 前日
        const previousDayYear = previousDay.getFullYear();
        const previousDayMonth = previousDay.getMonth() + 1;
        const previousDayDate = previousDay.getDate();

        // 前日が日曜日か、かつ前日が祝日であるか(ただし、isHolidayOrSunday自体を再帰的に呼ぶと無限ループになるので注意)
        // ここでは、祝日リストに直接含まれているか、または前日が日曜日であるかをチェック
        if (previousDay.getDay() === DayOfWeek.SUNDAY) {
            const previousYearHolidays = getJapaneseHolidays(previousDayYear);
            for (let i = 0; i < previousYearHolidays.length; i++) {
                if (previousYearHolidays[i].month === previousDayMonth && previousYearHolidays[i].date === previousDayDate) {
                    return true; // 前日が日曜日で祝日なので、本日(月曜日)は振替休日
                }
            }
        }
    }


    return false; // 日曜日でも祝日でも振替休日でもない場合
}

// dayJudge 関数は、以前提示した「修正案1(ネストしたswitch形式)」または「修正案2(ネストしたswitch形式)」のどちらかを適用してください。
// ここでは修正案1の例を再掲します。
function dayJudge(year, month, date, day) { // day は 0:日曜, 1:月曜, ..., 6:土曜

    // 1. まず特殊ダイヤ1と特殊ダイヤ2の判定を先に行う (優先順位を考慮)
    const isSpecialDay1 = (date === 12 && month === 10)||(date === 3 && month === 11)||(date === 24 && month === 11);
    if (isSpecialDay1) {
        return DiaType.SPECIAL1;
    }

    // 2. 個別の日付ダイヤ(OCT_XX, NOV_XXなど)の判定を優先的に行う
    switch (month) {
        case 10: // 10月の処理
            switch (date) {
                case 1: return DiaType.OCT_01;
                case 2: return DiaType.OCT_02;
                case 3: return DiaType.OCT_03;
                case 4: return DiaType.OCT_04;
                case 5: return DiaType.OCT_05;
                case 6: return DiaType.OCT_06;
                case 7: return DiaType.OCT_07;
                case 8: return DiaType.OCT_08;
                case 9: return DiaType.OCT_09;
                case 10: return DiaType.OCT_10;
                case 11: return DiaType.OCT_11;
                case 12: return DiaType.OCT_12;
                case 13: return DiaType.OCT_13;
                case 14: return DiaType.OCT_14;
                case 15: return DiaType.OCT_15;
                case 16: return DiaType.OCT_16;
                case 17: return DiaType.OCT_17;
                case 18: return DiaType.OCT_18;
                case 19: return DiaType.OCT_19;
                case 20: return DiaType.OCT_20;
                case 21: return DiaType.OCT_21;
                case 22: return DiaType.OCT_22;
                case 23: return DiaType.OCT_23;
                case 24: return DiaType.OCT_24;
                case 25: return DiaType.OCT_25;
                case 26: return DiaType.OCT_26;
                case 27: return DiaType.OCT_27;
                case 28: return DiaType.OCT_28;
                case 29: return DiaType.OCT_29;
                case 30: return DiaType.OCT_30;
                case 31: return DiaType.OCT_31;
                default: break;
            }
            break;
        case 11: // 11月の処理
            switch (date) {
                case 1: return DiaType.NOV_01;
                case 2: return DiaType.NOV_02;
                case 3: return DiaType.NOV_03;
                case 4: return DiaType.NOV_04;
                case 5: return DiaType.NOV_05;
                case 6: return DiaType.NOV_06;
                case 7: return DiaType.NOV_07;
                case 8: return DiaType.NOV_08;
                case 9: return DiaType.NOV_09;
                case 10: return DiaType.NOV_10;
                case 11: return DiaType.NOV_11;
                case 12: return DiaType.NOV_12;
                case 13: return DiaType.NOV_13;
                case 14: return DiaType.NOV_14;
                case 15: return DiaType.NOV_15;
                case 16: return DiaType.NOV_16;
                case 17: return DiaType.NOV_17;
                case 18: return DiaType.NOV_18;
                case 19: return DiaType.NOV_19;
                case 20: return DiaType.NOV_20;
                case 21: return DiaType.NOV_21;
                case 22: return DiaType.NOV_22;
                case 23: return DiaType.NOV_23;
                case 24: return DiaType.NOV_24;
                case 25: return DiaType.NOV_25;
                case 26: return DiaType.NOV_26;
                case 27: return DiaType.NOV_27;
                case 28: return DiaType.NOV_28;
                case 29: return DiaType.NOV_29;
                case 30: return DiaType.NOV_30;
                default: break;
            }
            break;
        default:
            break;
    }

    // 3. 日曜日または祝日であるかどうかの判定(holidays配列と日曜日の両方を含む)
    if (isHolidayOrSunday(year, month, date)) {
        const dateObj = new Date(year, month - 1, date);
        if (dateObj.getDay() === DayOfWeek.SUNDAY) {
            return DiaType.SUNDAY;
        } else {
            return DiaType.HOLIDAY;
        }
    }

    // 4. 土曜日であるかどうかの判定
    if (day === DayOfWeek.SATURDAY) {
        return DiaType.SATURDAY;
    }

    // 5. それ以外は平日
    return DiaType.WEEKDAY;
}

例)
参照元

http://r113.web.fc2.com/p/viewer/jrw-hokuriku-20150314/index.html

自分で試したこと

geminiで何度試したことでしょうか。
ちなみにmain.jsの改変版はこちらになります。
尚このjsは、上のほうはあまりいじっていないので、今回は割愛、
また、読者の皆様の読むことに対する精神的身体的負担への配慮により誠に勝手ながら、一部の日付や一部の〇〇日運転という部分は、長くなるので割愛させていただきました。
おそらく、先ほど挙げました、diatymejudge.jsfunction dayJudge(year, month, date, day) {のエラーだと思われますので、まず、目をつけていただくのはそのコード内容かと思います。
ただそうはいっても、swith分を壊されますと、今度は、日付判定が聞かなくなる可能性があるので、その辺はご留意を。

// 曜日を表す列挙型
// 曜日を表す列挙型
const DayOfWeek = {
    SUNDAY: 0,
    MONDAY: 1,
    TUESDAY: 2,
    WEDNESDAY: 3,
    THURSDAY: 4,
    FRIDAY: 5,
    SATURDAY: 6
};

const DiaType = {
    OCT_01: 0,
    OCT_02: 1,
    OCT_03: 2,,
    NOV_30: 60,
    WEEKDAY: 61,
    HOLIDAY: 62
};

let diaDay = DiaType.WEEKDAY;

function judgeDiaDay() {
    let nowDateSet = new Date(); // 現在の日付を取得
    let nowHour = nowDateSet.getHours();
    let nowMinute = nowDateSet.getMinutes();
    let nowSecond = nowDateSet.getSeconds();
    let nowDay = nowDateSet.getDay();
    
    // 現在の年、月、日を取得
    let nowYear = nowDateSet.getFullYear();
    let nowMonth = nowDateSet.getMonth() + 1; // 月は0から始まるため1を加算
    let nowDate = nowDateSet.getDate();

    // 日付変更時刻と現在時刻を比較
    if (HHMMSSToSecond(nowHour, nowMinute, nowSecond) < dayChangeTime) {
        nowDateSet.setDate(nowDateSet.getDate() - 1); // 前日の日付に変更
        nowYear = nowDateSet.getFullYear();
        nowMonth = nowDateSet.getMonth() + 1;
        nowDate = nowDateSet.getDate();
        nowDay = nowDateSet.getDay();
    }

    if (nowYear < 2000) nowYear += 1900; // 年の補正

    setYear = nowYear; // ここでsetYearに現在の年を設定
    setMonth = nowMonth;
    setDate = nowDate;
    setDay = nowDay;


    switch (setMonth) {
        case 10:
            switch (setDate) {
                case 01: diaDay = DiaType.OCT_01; break;
                case 02: diaDay = DiaType.OCT_02; break;
                case 03: diaDay = DiaType.OCT_03; break;
                case 31: diaDay = DiaType.OCT_31; break;
                default: 
                    if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.SUNDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.MONDAY;  // 週末の処理
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.TUESDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.WEDNESDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.THURSDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.FRIDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.SATURDAY;
                    } else if (isWeekend(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.WEEKEND;  // 週末の処理
                    } else {
                        diaDay = DiaType.HOLIDAY;
                    }
            }
            break;
        case 11:
            switch (setDate) {
                case 01: diaDay = DiaType.NOV_01; break;
                case 02: diaDay = DiaType.NOV_02; break;
                case 03: diaDay = DiaType.NOV_03; break;
                case 30: diaDay = DiaType.NOV_30; break;
                default: 
                    if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.SUNDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.MONDAY;  // 週末の処理
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.TUESDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.WEDNESDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.THURSDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.FRIDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.SATURDAY;
                    } else if (isWeekend(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.WEEKEND;  // 週末の処理
                    } else {
                        diaDay = DiaType.HOLIDAY;
                    }
            }
                break;
            default: 
                diaDay = dayJudge(setYear, setMonth, setDate, setDay) === "weekday" ? DiaType.WEEKDAY : DiaType.HOLIDAY;
    }

    updateDisplayDiaDay();
    return diaDay === DiaType.WEEKDAY;
}

function updateDisplayDiaDay() {
    const todayDiaDaySpan = document.getElementById("todayDiaDaySpan");
    if (todayDiaDaySpan) {
        todayDiaDaySpan.innerHTML = getDiaTypeString(diaDay);
        todayDiaDaySpan.style.backgroundColor = getDiaTypeColor(diaDay);
    }
}

function getDiaTypeString(diaType) {
    switch (diaType) {
        case DiaType.WEEKDAY: return " 平日ダイヤ ";
        case DiaType.HOLIDAY: return "土・休日ダイヤ";
        case DiaType.OCT_01: return "10月01日ダイヤ";
        case DiaType.OCT_02: return "10月02日ダイヤ";
        case DiaType.OCT_03: return "10月03日ダイヤ";

        case DiaType.NOV_30: return "11月30日ダイヤ";
        default: return "";
    }
}

function getDiaTypeColor(diaType) {
    switch (diaType) {
        case DiaType.WEEKDAY: return "#9ff";
        case DiaType.HOLIDAY: return "#fcf";
        case DiaType.OCT_01: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
        case DiaType.OCT_02: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
        case DiaType.OCT_03: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
        case DiaType.NOV_30: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
        default: return "";
    }
}


function isHoliday(year, month, day) {
    const date = new Date(year, month - 1, day); // Month is 0-indexed in Date
    const dayOfWeek = date.getDay();
    return dayOfWeek === 0 || dayOfWeek === 6; // 0 is Sunday, 6 is Saturday
}

function isWeekday(year, month, day) {
    const dayOfWeek = new Date(year, month - 1, day).getDay();
    return dayOfWeek >= 1 && dayOfWeek <= 5;
}

function isSunday(year, month, day) {
    const date = new Date(year, month - 1, day);
    return date.getDay() === 0;
}
function isTwilightDown(year, month, day) {
    const date = new Date(year, month - 1, day);
    const dayOfWeek = date.getDay();
    return dayOfWeek === 1 || dayOfWeek === 3 || dayOfWeek === 5 || dayOfWeek === 6;
}
function isTwilightUp(year, month, day) {
    const date = new Date(year, month - 1, day);
    const dayOfWeek = date.getDay();
    return dayOfWeek === 0 || dayOfWeek === 1 || dayOfWeek === 3 || dayOfWeek === 5;
}
function isWednesday(year, month, day) {
    const date = new Date(year, month - 1, day);
    return date.getDay() === 3;
}

function judgeTrainRunningDay(value) {
    if (value === "全日") return true;
    if (value === "平日") {
        if (((diaDay === DiaType.WEEKDAY))||
           ((diaDay === DiaType.OCT_01 && isWeekday(setYear, 10, 1)) ||
            (diaDay === DiaType.OCT_02 && isWeekday(setYear, 10, 2)) ||
            (diaDay === DiaType.OCT_03 && isWeekday(setYear, 10, 3)) ||
            (diaDay === DiaType.OCT_04 && isWeekday(setYear, 10, 4)) ||
            (diaDay === DiaType.OCT_05 && isWeekday(setYear, 10, 5)) ||
            (diaDay === DiaType.OCT_06 && isWeekday(setYear, 10, 6)) ||
            (diaDay === DiaType.OCT_07 && isWeekday(setYear, 10, 7)) ||
            (diaDay === DiaType.OCT_08 && isWeekday(setYear, 10, 8)) ||
            (diaDay === DiaType.OCT_09 && isWeekday(setYear, 10, 9)) ||
            (diaDay === DiaType.OCT_10 && isWeekday(setYear, 10, 10)) ||
            (diaDay === DiaType.OCT_11 && isWeekday(setYear, 10, 11)) ||
            (diaDay === DiaType.OCT_12 && isWeekday(setYear, 10, 12)) ||
            (diaDay === DiaType.OCT_13 && isWeekday(setYear, 10, 13)) ||
            (diaDay === DiaType.OCT_14 && isWeekday(setYear, 10, 14)) ||
            (diaDay === DiaType.OCT_15 && isWeekday(setYear, 10, 15)) ||
            (diaDay === DiaType.OCT_16 && isWeekday(setYear, 10, 16)) ||
            (diaDay === DiaType.OCT_17 && isWeekday(setYear, 10, 17)) ||
            (diaDay === DiaType.OCT_18 && isWeekday(setYear, 10, 18)) ||
            (diaDay === DiaType.OCT_19 && isWeekday(setYear, 10, 19)) ||
            (diaDay === DiaType.OCT_20 && isWeekday(setYear, 10, 20)) ||
            (diaDay === DiaType.OCT_21 && isWeekday(setYear, 10, 21)) ||
            (diaDay === DiaType.OCT_22 && isWeekday(setYear, 10, 22)) ||
            (diaDay === DiaType.OCT_23 && isWeekday(setYear, 10, 23)) ||
            (diaDay === DiaType.OCT_24 && isWeekday(setYear, 10, 24)) ||
            (diaDay === DiaType.OCT_25 && isWeekday(setYear, 10, 25)) ||
            (diaDay === DiaType.OCT_26 && isWeekday(setYear, 10, 26)) ||
            (diaDay === DiaType.OCT_31 && isWeekday(setYear, 10, 31)) ||
            (diaDay === DiaType.NOV_01 && isWeekday(setYear, 11, 1)) ||
            (diaDay === DiaType.NOV_02 && isWeekday(setYear, 11, 2)) ||
            (diaDay === DiaType.NOV_03 && isWeekday(setYear, 11, 3)) ||
            (diaDay === DiaType.NOV_04 && isWeekday(setYear, 11, 4)) ||
            (diaDay === DiaType.NOV_05 && isWeekday(setYear, 11, 5)) ||
            (diaDay === DiaType.NOV_06 && isWeekday(setYear, 11, 6)) ||
            (diaDay === DiaType.NOV_07 && isWeekday(setYear, 11, 7)) ||
            (diaDay === DiaType.NOV_08 && isWeekday(setYear, 11, 8)) ||
            (diaDay === DiaType.NOV_09 && isWeekday(setYear, 11, 9)) ||
            (diaDay === DiaType.NOV_10 && isWeekday(setYear, 11, 10)) ||
            (diaDay === DiaType.NOV_11 && isWeekday(setYear, 11, 11)) ||
            (diaDay === DiaType.NOV_12 && isWeekday(setYear, 11, 12)) ||
            (diaDay === DiaType.NOV_13 && isWeekday(setYear, 11, 13)) ||
            (diaDay === DiaType.NOV_14 && isWeekday(setYear, 11, 14)) ||
            (diaDay === DiaType.NOV_15 && isWeekday(setYear, 11, 15)) ||
            (diaDay === DiaType.NOV_16 && isWeekday(setYear, 11, 16)) ||
            (diaDay === DiaType.NOV_17 && isWeekday(setYear, 11, 17)) ||
            (diaDay === DiaType.NOV_18 && isWeekday(setYear, 11, 18)) ||
            (diaDay === DiaType.NOV_19 && isWeekday(setYear, 11, 19)) ||
            (diaDay === DiaType.NOV_20 && isWeekday(setYear, 11, 20)) ||
            (diaDay === DiaType.NOV_21 && isWeekday(setYear, 11, 21)) ||
            (diaDay === DiaType.NOV_22 && isWeekday(setYear, 11, 22)) ||
            (diaDay === DiaType.NOV_23 && isWeekday(setYear, 11, 23)) ||
            (diaDay === DiaType.NOV_24 && isWeekday(setYear, 11, 24)) ||
            (diaDay === DiaType.NOV_25 && isWeekday(setYear, 11, 25)) ||
            (diaDay === DiaType.NOV_26 && isWeekday(setYear, 11, 26)) ||
            (diaDay === DiaType.NOV_27 && isWeekday(setYear, 11, 27)) ||
            (diaDay === DiaType.NOV_28 && isWeekday(setYear, 11, 28)) ||
            (diaDay === DiaType.NOV_29 && isWeekday(setYear, 11, 29)) ||
            (diaDay === DiaType.NOV_30 && isWeekday(setYear, 11, 30)))) {
                return true; // 水曜日運休の場合
        }
    }
    return false; // その他の場合
}//エラーの原因は認識されていないダイヤパターン
function changeDiaType() {
    switch (diaDay) {
        case DiaType.WEEKDAY: diaDay = DiaType.HOLIDAY; break;
        case DiaType.HOLIDAY: diaDay = DiaType.OCT_01; break;
        case DiaType.OCT_01: diaDay = DiaType.OCT_02; break;
        case DiaType.OCT_02: diaDay = DiaType.OCT_03; break;
        case DiaType.OCT_03: diaDay = DiaType.OCT_04; break;
        case DiaType.NOV_30: diaDay = DiaType.WEEKDAY; break;
    }

    updateDisplayDiaDay();
    getTimeTable();
    setNewTime(setSecondSum);
    drawTrain();
    resetTimetableSpace();
}





//種別を入れると文字色と背景色を返す
//color=0なら背景色を返す、color=1なら文字色を返す
function getTypeColor(typeName, colorType)
{
	var i;
	for(i=0 ; i<trainTypeColor.length ; i++)
	{
		//alert(typeName+" "+trainTypeColor[i])
		if(typeName == trainTypeColor[i][0])
		{
			if(colorType == 0)
				//背景色を返す
				return trainTypeColor[i][1][0];
			else
				//文字色を返す
				return [i][1][1];
		}
	}
	
}






function HHMMtoSecond(HHMM)
{
	var hour = Math.floor(HHMM / 100);
	var minute = HHMM % 100;
	var second = 0;
	
	return hour * 60 * 60 + minute * 60 + second;
}

function HHMMSSToSecond(hour, minute, second)
{
	return hour * 60 * 60 + minute * 60 + second;
}

function secondToHHMMSS(value)
{
	var hour = Math.floor(value / 3600);
	var minute = Math.floor(value % 3600 / 60);
	var second = Math.floor(value % 60);
	
	return hour + ":" + minute + ":" + second;
}

function secondToHour(value)
{
	var num = Math.floor(value / 3600);
	if(num < 24)
		return num;
	else
		return num - 24;
}

function secondToMinute(value)
{
	return Math.floor(value % 3600 / 60);
}

function secondToSecond(value)
{
	return Math.floor(value % 60);
}
1 likes

3Answer

クリックした時に呼ばれるchangeDiaType関数から、judgeDiaDay関数を呼んでいなさそうです。ご提示のコードでは、judgeDiaDay関数はどこからも呼ばれていないようですが、実際のコードではどこからか呼んでいるのですか?

0Like

Comments

  1. @sembokulove

    Questioner

    お返事遅れて大変申し訳ございません。
    基本的にmainに関しては今あげた部分以外には抜本的には変えていないのですが、
    冒頭部分のコードをご紹介します。
    おそらく上のコードが無視されているのかと思われます。
    あとはおおもとのページをご参照くださいませ。

    function main()
    {
    	//現在時刻を1秒ごとに更新して表示する
    	nowTimeDisplay();
    	judgeDiaDay(); //今日が平日ダイヤか休日ダイヤか
    	setInterval("nowTimeDisplay()",1000);
    	
    	//時刻表データを取得、整える
    	getTimeTable();
    	
    	//現在日時の取得	
    
    	//路線図を描く
    	drawRouteMap();
    	adjustRouteMap();
    	
    	
    	//最初に列車を描くスペースを作っておく
    	makeDrawTrainSpace();
    	
    	
    	//駅から発車する列車の時刻を取得する
    	//getStationTimetable(34);
    	
    	
    	//設定時刻を12時に設定
    	//setSecondSum = 12 * 60 * 60;
    	//設定時刻を表示
    	//document.getElementById("setDateDisplaySpan").innerHTML = "設定日時 " +digitAdjuster(secondToHour(setSecondSum), " ")+":"+digitAdjuster(secondToMinute(setSecondSum), "0")+":"+digitAdjuster(secondToSecond(setSecondSum), "0");	
    	
    	//各列車の在線位置を割り出す
    	//getTrainPosition();
    	
    	//路線図に列車を配置していく
    	//drawTrain();
    	
    	//リアルタイムで表示更新する
    	changeUpdateInterval();
    	
    	//表示枠をウインドウの大きさに合わせる
    	setDisplayArea();
    }
    
    
  2. main関数はページ読み込み時に実行されるのであろうと思うのですが、そうだとすると、「切り替え」ボタンはどのような機能を持っているのですか? judgeDiaDay関数は今日の日付を元に表示を切り替えるのだと思うのですが、「切り替え」ボタンによって別の日付に変更するとか、そういうことですか?

  3. 他の方のコメントを読みましたが、わたしのお聞きしたいところが伝わっていなさそうなので、詳しく書きます。


    ■ページ表示時の動作はこうなります。

    ページロード → main関数呼び出し → dayJudge関数呼び出し → 今日のダイヤにデータ切り替え → 表示切り替え

    ■一方で、「切り替え」ボタンをクリックした時はこうです。

    「切り替え」ボタンクリック → changeDiaType関数呼び出し → dayJudge関数は呼ばれない → 今日のダイヤのデータのまま → 表示切り替えをしても変更されないはず


    ですので、「切り替え」ボタンを押しても何も起きないのは当然のように思えます。
    「切り替え」ボタンをクリックした時にあなたはどういうことが起きてほしいのかを教えてください、あなたが何に困っているのかさっぱりわからないので第三者に伝わるように書いてください。というのがコメントの主旨です。

  4. @sembokulove

    Questioner

    「切り替え」ボタンをクリックした時にあなたはどういうことが起きてほしいのかを教えてください→日付が平日、土曜・休日、10月1日といったように、順番に日付が回るようにしたいです。
    以前、ここかテラテイルでプログラミングの質問をする際に教わったことは、
    あまり長すぎると読み手がつかれるというのを聞きました。
    それは嘘なのですね。
    今回はあえて長く書きます。
    但し、途中のいくつかの10月9・12・31日・11月3・21・24日運転といった部分は省略しております。
    これは、qiitaに出せれる文字数制限の関係ですね。
    これで読み手側がつかれると言ったら、こちらとしては心外です。

    const DayOfWeek = {
        SUNDAY: 0,
        MONDAY: 1,
        TUESDAY: 2,
        WEDNESDAY: 3,
        THURSDAY: 4,
        FRIDAY: 5,
        SATURDAY: 6
    };
    
    const DiaType = {
        OCT_01: 0,
        OCT_02: 1,
        OCT_03: 2,
        OCT_04: 3,
        OCT_05: 4,
        OCT_06: 5,
        OCT_07: 6,
        OCT_08: 7,
        OCT_09: 8,
        OCT_10: 9,
        OCT_11: 10,
        OCT_12: 11,
        OCT_13: 12,
        OCT_14: 13,
        OCT_15: 14,
        OCT_16: 15,
        OCT_17: 16,
        OCT_18: 17,
        OCT_19: 18,
        OCT_20: 19,
        OCT_21: 20,
        OCT_22: 21,
        OCT_23: 22,
        OCT_24: 23,
        OCT_25: 24,
        OCT_26: 25,
        OCT_27: 26,
        OCT_28: 27,
        OCT_29: 28,
        OCT_30: 29,
        OCT_31: 30,
        NOV_01: 31,
        NOV_02: 32,
        NOV_03: 33,
        NOV_04: 34,
        NOV_05: 35,
        NOV_06: 36,
        NOV_07: 37,
        NOV_08: 38,
        NOV_09: 39,
        NOV_10: 40,
        NOV_11: 41,
        NOV_12: 42,
        NOV_13: 43,
        NOV_14: 44,
        NOV_15: 45,
        NOV_16: 46,
        NOV_17: 47,
        NOV_18: 48,
        NOV_19: 49,
        NOV_20: 50,
        NOV_21: 51,
        NOV_22: 52,
        NOV_23: 53,
        NOV_24: 54,
        NOV_25: 55,
        NOV_26: 56,
        NOV_27: 57,
        NOV_28: 58,
        NOV_29: 59,
        NOV_30: 60,
        WEEKDAY: 61,
        HOLIDAY: 62
    };
    
    let diaDay = DiaType.WEEKDAY;
    
    function judgeDiaDay() {
        let nowDateSet = new Date(); // 現在の日付を取得
        let nowHour = nowDateSet.getHours();
        let nowMinute = nowDateSet.getMinutes();
        let nowSecond = nowDateSet.getSeconds();
        let nowDay = nowDateSet.getDay();
        
        // 現在の年、月、日を取得
        let nowYear = nowDateSet.getFullYear();
        let nowMonth = nowDateSet.getMonth() + 1; // 月は0から始まるため1を加算
        let nowDate = nowDateSet.getDate();
    
        // 日付変更時刻と現在時刻を比較
        if (HHMMSSToSecond(nowHour, nowMinute, nowSecond) < dayChangeTime) {
            nowDateSet.setDate(nowDateSet.getDate() - 1); // 前日の日付に変更
            nowYear = nowDateSet.getFullYear();
            nowMonth = nowDateSet.getMonth() + 1;
            nowDate = nowDateSet.getDate();
            nowDay = nowDateSet.getDay();
        }
    
        if (nowYear < 2000) nowYear += 1900; // 年の補正
    
        setYear = nowYear; // ここでsetYearに現在の年を設定
        setMonth = nowMonth;
        setDate = nowDate;
        setDay = nowDay;
    
    
        switch (setMonth) {
            case 10:
                switch (setDate) {
                    case 01: diaDay = DiaType.OCT_01; break;
                    case 02: diaDay = DiaType.OCT_02; break;
                    case 03: diaDay = DiaType.OCT_03; break;
                    case 04: diaDay = DiaType.OCT_04; break;
                    case 05: diaDay = DiaType.OCT_05; break;
                    case 06: diaDay = DiaType.OCT_06; break;
                    case 07: diaDay = DiaType.OCT_07; break;
                    case 08: diaDay = DiaType.OCT_08; break;
                    case 09: diaDay = DiaType.OCT_09; break;
                    case 10: diaDay = DiaType.OCT_10; break;
                    case 11: diaDay = DiaType.OCT_11; break;
                    case 12: diaDay = DiaType.OCT_12; break;
                    case 13: diaDay = DiaType.OCT_13; break;
                    case 14: diaDay = DiaType.OCT_14; break;
                    case 15: diaDay = DiaType.OCT_15; break;
                    case 16: diaDay = DiaType.OCT_16; break;
                    case 17: diaDay = DiaType.OCT_17; break;
                    case 18: diaDay = DiaType.OCT_18; break;
                    case 19: diaDay = DiaType.OCT_19; break;
                    case 20: diaDay = DiaType.OCT_20; break;
                    case 21: diaDay = DiaType.OCT_21; break;
                    case 22: diaDay = DiaType.OCT_22; break;
                    case 23: diaDay = DiaType.OCT_23; break;
                    case 24: diaDay = DiaType.OCT_24; break;
                    case 25: diaDay = DiaType.OCT_25; break;
                    case 26: diaDay = DiaType.OCT_26; break;
                    case 27: diaDay = DiaType.OCT_27; break;
                    case 28: diaDay = DiaType.OCT_28; break;
                    case 29: diaDay = DiaType.OCT_29; break;
                    case 30: diaDay = DiaType.OCT_30; break;
                    case 31: diaDay = DiaType.OCT_31; break;
                    default: 
                        if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.SUNDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.MONDAY;  // 週末の処理
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.TUESDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.WEDNESDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.THURSDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.FRIDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.SATURDAY;
                        } else if (isWeekend(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.WEEKEND;  // 週末の処理
                        } else {
                            diaDay = DiaType.HOLIDAY;
                        }
                }
                break;
            case 11:
                switch (setDate) {
                    case 01: diaDay = DiaType.NOV_01; break;
                    case 02: diaDay = DiaType.NOV_02; break;
                    case 03: diaDay = DiaType.NOV_03; break;
                    case 04: diaDay = DiaType.NOV_04; break;
                    case 05: diaDay = DiaType.NOV_05; break;
                    case 06: diaDay = DiaType.NOV_06; break;
                    case 07: diaDay = DiaType.NOV_07; break;
                    case 08: diaDay = DiaType.NOV_08; break;
                    case 09: diaDay = DiaType.NOV_09; break;
                    case 10: diaDay = DiaType.NOV_10; break;
                    case 11: diaDay = DiaType.NOV_11; break;
                    case 12: diaDay = DiaType.NOV_12; break;
                    case 13: diaDay = DiaType.NOV_13; break;
                    case 14: diaDay = DiaType.NOV_14; break;
                    case 15: diaDay = DiaType.NOV_15; break;
                    case 16: diaDay = DiaType.NOV_16; break;
                    case 17: diaDay = DiaType.NOV_17; break;
                    case 18: diaDay = DiaType.NOV_18; break;
                    case 19: diaDay = DiaType.NOV_19; break;
                    case 20: diaDay = DiaType.NOV_20; break;
                    case 21: diaDay = DiaType.NOV_21; break;
                    case 22: diaDay = DiaType.NOV_22; break;
                    case 23: diaDay = DiaType.NOV_23; break;
                    case 24: diaDay = DiaType.NOV_24; break;
                    case 25: diaDay = DiaType.NOV_25; break;
                    case 26: diaDay = DiaType.NOV_26; break;
                    case 27: diaDay = DiaType.NOV_27; break;
                    case 28: diaDay = DiaType.NOV_28; break;
                    case 29: diaDay = DiaType.NOV_29; break;
                    case 30: diaDay = DiaType.NOV_30; break;
                    default: 
                        if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.SUNDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.MONDAY;  // 週末の処理
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.TUESDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.WEDNESDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.THURSDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.FRIDAY;
                        } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.SATURDAY;
                        } else if (isWeekend(setYear, setMonth, setDate, setDay)) {
                            diaDay = DiaType.WEEKEND;  // 週末の処理
                        } else {
                            diaDay = DiaType.HOLIDAY;
                        }
                }
                    break;
                default: 
                    diaDay = dayJudge(setYear, setMonth, setDate, setDay) === "weekday" ? DiaType.WEEKDAY : DiaType.HOLIDAY;
        }
    
        updateDisplayDiaDay();
        return diaDay === DiaType.WEEKDAY;
    }
    
    function updateDisplayDiaDay() {
        const todayDiaDaySpan = document.getElementById("todayDiaDaySpan");
        if (todayDiaDaySpan) {
            todayDiaDaySpan.innerHTML = getDiaTypeString(diaDay);
            todayDiaDaySpan.style.backgroundColor = getDiaTypeColor(diaDay);
        }
    }
    
    function getDiaTypeString(diaType) {
        switch (diaType) {
            case DiaType.WEEKDAY: return " 平日ダイヤ ";
            case DiaType.HOLIDAY: return "土・休日ダイヤ";
            case DiaType.OCT_01: return "10月01日ダイヤ";
            case DiaType.OCT_02: return "10月02日ダイヤ";
            case DiaType.OCT_03: return "10月03日ダイヤ";
            case DiaType.OCT_04: return "10月04日ダイヤ";
            case DiaType.OCT_05: return "10月05日ダイヤ";
            case DiaType.OCT_06: return "10月06日ダイヤ";
            case DiaType.OCT_07: return "10月07日ダイヤ";
            case DiaType.OCT_08: return "10月08日ダイヤ";
            case DiaType.OCT_09: return "10月09日ダイヤ";
            case DiaType.OCT_10: return "10月10日ダイヤ";
            case DiaType.OCT_11: return "10月11日ダイヤ";
            case DiaType.OCT_12: return "10月12日ダイヤ";
            case DiaType.OCT_13: return "10月13日ダイヤ";
            case DiaType.OCT_14: return "10月14日ダイヤ";
            case DiaType.OCT_15: return "10月15日ダイヤ";
            case DiaType.OCT_16: return "10月16日ダイヤ";
            case DiaType.OCT_17: return "10月17日ダイヤ";
            case DiaType.OCT_18: return "10月18日ダイヤ";
            case DiaType.OCT_19: return "10月19日ダイヤ";
            case DiaType.OCT_20: return "10月20日ダイヤ";
            case DiaType.OCT_21: return "10月21日ダイヤ";
            case DiaType.OCT_22: return "10月22日ダイヤ";
            case DiaType.OCT_23: return "10月23日ダイヤ";
            case DiaType.OCT_24: return "10月24日ダイヤ";
            case DiaType.OCT_25: return "10月25日ダイヤ";
            case DiaType.OCT_26: return "10月26日ダイヤ";
            case DiaType.OCT_27: return "10月27日ダイヤ";
            case DiaType.OCT_28: return "10月28日ダイヤ";
            case DiaType.OCT_29: return "10月29日ダイヤ";
            case DiaType.OCT_30: return "10月30日ダイヤ";
            case DiaType.OCT_31: return "10月31日ダイヤ";
            case DiaType.NOV_01: return "11月01日ダイヤ";
            case DiaType.NOV_02: return "11月02日ダイヤ";
            case DiaType.NOV_03: return "11月03日ダイヤ";
            case DiaType.NOV_04: return "11月04日ダイヤ";
            case DiaType.NOV_05: return "11月05日ダイヤ";
            case DiaType.NOV_06: return "11月06日ダイヤ";
            case DiaType.NOV_07: return "11月07日ダイヤ";
            case DiaType.NOV_08: return "11月08日ダイヤ";
            case DiaType.NOV_09: return "11月09日ダイヤ";
            case DiaType.NOV_10: return "11月10日ダイヤ";
            case DiaType.NOV_11: return "11月11日ダイヤ";
            case DiaType.NOV_12: return "11月12日ダイヤ";
            case DiaType.NOV_13: return "11月13日ダイヤ";
            case DiaType.NOV_14: return "11月14日ダイヤ";
            case DiaType.NOV_15: return "11月15日ダイヤ";
            case DiaType.NOV_16: return "11月16日ダイヤ";
            case DiaType.NOV_17: return "11月17日ダイヤ";
            case DiaType.NOV_18: return "11月18日ダイヤ";
            case DiaType.NOV_19: return "11月19日ダイヤ";
            case DiaType.NOV_20: return "11月20日ダイヤ";
            case DiaType.NOV_21: return "11月21日ダイヤ";
            case DiaType.NOV_22: return "11月22日ダイヤ";
            case DiaType.NOV_23: return "11月23日ダイヤ";
            case DiaType.NOV_24: return "11月24日ダイヤ";
            case DiaType.NOV_25: return "11月25日ダイヤ";
            case DiaType.NOV_26: return "11月26日ダイヤ";
            case DiaType.NOV_27: return "11月27日ダイヤ";
            case DiaType.NOV_28: return "11月28日ダイヤ";
            case DiaType.NOV_29: return "11月29日ダイヤ";
            case DiaType.NOV_30: return "11月30日ダイヤ";
            default: return "";
        }
    }
    
    function getDiaTypeColor(diaType) {
        switch (diaType) {
            case DiaType.WEEKDAY: return "#9ff";
            case DiaType.HOLIDAY: return "#fcf";
            case DiaType.OCT_01: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_02: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_03: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_04: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_05: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_06: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_07: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_08: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_09: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_10: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_11: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_12: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_13: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_14: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_15: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_16: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_17: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_18: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_19: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_20: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_21: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_22: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_23: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_24: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_25: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_26: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_27: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_28: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_29: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.OCT_30: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.OCT_31: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_01: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_02: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_03: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_04: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_05: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_06: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_07: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_08: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_09: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_10: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_11: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_12: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_13: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_14: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_15: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_16: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_17: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_18: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_19: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_20: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_21: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_22: return "#a0f0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_23: return "#f0a0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_24: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_25: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_26: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_27: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_28: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            case DiaType.NOV_29: return "#f0a0a0"; // 例:2月12日ダイヤの背景色
            case DiaType.NOV_30: return "#a0f0a0"; // 例:2月11日ダイヤの背景色
            default: return "";
        }
    }
    
    
    function isHoliday(year, month, day) {
        const date = new Date(year, month - 1, day); // Month is 0-indexed in Date
        const dayOfWeek = date.getDay();
        return dayOfWeek === 0 || dayOfWeek === 6; // 0 is Sunday, 6 is Saturday
    }
    
    function isWeekday(year, month, day) {
        const dayOfWeek = new Date(year, month - 1, day).getDay();
        return dayOfWeek >= 1 && dayOfWeek <= 5;
    }
    
    function isSunday(year, month, day) {
        const date = new Date(year, month - 1, day);
        return date.getDay() === 0;
    }
    function isTwilightDown(year, month, day) {
        const date = new Date(year, month - 1, day);
        const dayOfWeek = date.getDay();
        return dayOfWeek === 1 || dayOfWeek === 3 || dayOfWeek === 5 || dayOfWeek === 6;
    }
    function isTwilightUp(year, month, day) {
        const date = new Date(year, month - 1, day);
        const dayOfWeek = date.getDay();
        return dayOfWeek === 0 || dayOfWeek === 1 || dayOfWeek === 3 || dayOfWeek === 5;
    }
    function isWednesday(year, month, day) {
        const date = new Date(year, month - 1, day);
        return date.getDay() === 3;
    }
    
    function judgeTrainRunningDay(value) {
        if (value === "全日") return true;
        if (value === "平日") {
            if (((diaDay === DiaType.WEEKDAY))||
               ((diaDay === DiaType.OCT_01 && isWeekday(setYear, 10, 1)) ||
                (diaDay === DiaType.OCT_02 && isWeekday(setYear, 10, 2)) ||
                (diaDay === DiaType.OCT_03 && isWeekday(setYear, 10, 3)) ||
                (diaDay === DiaType.OCT_04 && isWeekday(setYear, 10, 4)) ||
                (diaDay === DiaType.OCT_05 && isWeekday(setYear, 10, 5)) ||
                (diaDay === DiaType.OCT_06 && isWeekday(setYear, 10, 6)) ||
                (diaDay === DiaType.OCT_07 && isWeekday(setYear, 10, 7)) ||
                (diaDay === DiaType.OCT_08 && isWeekday(setYear, 10, 8)) ||
                (diaDay === DiaType.OCT_09 && isWeekday(setYear, 10, 9)) ||
                (diaDay === DiaType.OCT_10 && isWeekday(setYear, 10, 10)) ||
                (diaDay === DiaType.OCT_11 && isWeekday(setYear, 10, 11)) ||
                (diaDay === DiaType.OCT_12 && isWeekday(setYear, 10, 12)) ||
                (diaDay === DiaType.OCT_13 && isWeekday(setYear, 10, 13)) ||
                (diaDay === DiaType.OCT_14 && isWeekday(setYear, 10, 14)) ||
                (diaDay === DiaType.OCT_15 && isWeekday(setYear, 10, 15)) ||
                (diaDay === DiaType.OCT_16 && isWeekday(setYear, 10, 16)) ||
                (diaDay === DiaType.OCT_17 && isWeekday(setYear, 10, 17)) ||
                (diaDay === DiaType.OCT_18 && isWeekday(setYear, 10, 18)) ||
                (diaDay === DiaType.OCT_19 && isWeekday(setYear, 10, 19)) ||
                (diaDay === DiaType.OCT_20 && isWeekday(setYear, 10, 20)) ||
                (diaDay === DiaType.OCT_21 && isWeekday(setYear, 10, 21)) ||
                (diaDay === DiaType.OCT_22 && isWeekday(setYear, 10, 22)) ||
                (diaDay === DiaType.OCT_23 && isWeekday(setYear, 10, 23)) ||
                (diaDay === DiaType.OCT_24 && isWeekday(setYear, 10, 24)) ||
                (diaDay === DiaType.OCT_25 && isWeekday(setYear, 10, 25)) ||
                (diaDay === DiaType.OCT_26 && isWeekday(setYear, 10, 26)) ||
                (diaDay === DiaType.OCT_31 && isWeekday(setYear, 10, 31)) ||
                (diaDay === DiaType.NOV_01 && isWeekday(setYear, 11, 1)) ||
                (diaDay === DiaType.NOV_02 && isWeekday(setYear, 11, 2)) ||
                (diaDay === DiaType.NOV_03 && isWeekday(setYear, 11, 3)) ||
                (diaDay === DiaType.NOV_04 && isWeekday(setYear, 11, 4)) ||
                (diaDay === DiaType.NOV_05 && isWeekday(setYear, 11, 5)) ||
                (diaDay === DiaType.NOV_06 && isWeekday(setYear, 11, 6)) ||
                (diaDay === DiaType.NOV_07 && isWeekday(setYear, 11, 7)) ||
                (diaDay === DiaType.NOV_08 && isWeekday(setYear, 11, 8)) ||
                (diaDay === DiaType.NOV_09 && isWeekday(setYear, 11, 9)) ||
                (diaDay === DiaType.NOV_10 && isWeekday(setYear, 11, 10)) ||
                (diaDay === DiaType.NOV_11 && isWeekday(setYear, 11, 11)) ||
                (diaDay === DiaType.NOV_12 && isWeekday(setYear, 11, 12)) ||
                (diaDay === DiaType.NOV_13 && isWeekday(setYear, 11, 13)) ||
                (diaDay === DiaType.NOV_14 && isWeekday(setYear, 11, 14)) ||
                (diaDay === DiaType.NOV_15 && isWeekday(setYear, 11, 15)) ||
                (diaDay === DiaType.NOV_16 && isWeekday(setYear, 11, 16)) ||
                (diaDay === DiaType.NOV_17 && isWeekday(setYear, 11, 17)) ||
                (diaDay === DiaType.NOV_18 && isWeekday(setYear, 11, 18)) ||
                (diaDay === DiaType.NOV_19 && isWeekday(setYear, 11, 19)) ||
                (diaDay === DiaType.NOV_20 && isWeekday(setYear, 11, 20)) ||
                (diaDay === DiaType.NOV_21 && isWeekday(setYear, 11, 21)) ||
                (diaDay === DiaType.NOV_22 && isWeekday(setYear, 11, 22)) ||
                (diaDay === DiaType.NOV_23 && isWeekday(setYear, 11, 23)) ||
                (diaDay === DiaType.NOV_24 && isWeekday(setYear, 11, 24)) ||
                (diaDay === DiaType.NOV_25 && isWeekday(setYear, 11, 25)) ||
                (diaDay === DiaType.NOV_26 && isWeekday(setYear, 11, 26)) ||
                (diaDay === DiaType.NOV_27 && isWeekday(setYear, 11, 27)) ||
                (diaDay === DiaType.NOV_28 && isWeekday(setYear, 11, 28)) ||
                (diaDay === DiaType.NOV_29 && isWeekday(setYear, 11, 29)) ||
                (diaDay === DiaType.NOV_30 && isWeekday(setYear, 11, 30)))) {
                    return true; // 水曜日運休の場合
            }
        }
        if ((value === "休日")||(value === "休日運転")) {
            if ((diaDay === DiaType.HOLIDAY)||
               ((diaDay === DiaType.OCT_01 && isSunday(setYear, 10, 1)) ||
                (diaDay === DiaType.OCT_02 && isSunday(setYear, 10, 2)) ||
                (diaDay === DiaType.OCT_03 && isSunday(setYear, 10, 3)) ||
                (diaDay === DiaType.OCT_04 && isSunday(setYear, 10, 4)) ||
                (diaDay === DiaType.OCT_05 && isSunday(setYear, 10, 5)) ||
                (diaDay === DiaType.OCT_06 && isSunday(setYear, 10, 6)) ||
                (diaDay === DiaType.OCT_07 && isSunday(setYear, 10, 7)) ||
                (diaDay === DiaType.OCT_08 && isSunday(setYear, 10, 8)) ||
                (diaDay === DiaType.OCT_09 && isSunday(setYear, 10, 9)) ||
                (diaDay === DiaType.OCT_10 && isSunday(setYear, 10, 10)) ||
                (diaDay === DiaType.OCT_11 && isSunday(setYear, 10, 11)) ||
                (diaDay === DiaType.OCT_12 && isSunday(setYear, 10, 12)) ||
                (diaDay === DiaType.OCT_13 && isSunday(setYear, 10, 13)) ||
                (diaDay === DiaType.OCT_14 && isSunday(setYear, 10, 14)) ||
                (diaDay === DiaType.OCT_15 && isSunday(setYear, 10, 15)) ||
                (diaDay === DiaType.OCT_16 && isSunday(setYear, 10, 16)) ||
                (diaDay === DiaType.OCT_17 && isSunday(setYear, 10, 17)) ||
                (diaDay === DiaType.OCT_18 && isSunday(setYear, 10, 18)) ||
                (diaDay === DiaType.OCT_19 && isSunday(setYear, 10, 19)) ||
                (diaDay === DiaType.OCT_20 && isSunday(setYear, 10, 20)) ||
                (diaDay === DiaType.OCT_21 && isSunday(setYear, 10, 21)) ||
                (diaDay === DiaType.OCT_22 && isSunday(setYear, 10, 22)) ||
                (diaDay === DiaType.OCT_23 && isSunday(setYear, 10, 23)) ||
                (diaDay === DiaType.OCT_24 && isSunday(setYear, 10, 24)) ||
                (diaDay === DiaType.OCT_25 && isSunday(setYear, 10, 25)) ||
                (diaDay === DiaType.OCT_26 && isSunday(setYear, 10, 26)) ||
                (diaDay === DiaType.OCT_27 && isSunday(setYear, 10, 27)) ||
                (diaDay === DiaType.OCT_28 && isSunday(setYear, 10, 28)) ||
                (diaDay === DiaType.OCT_29 && isSunday(setYear, 10, 29)) ||
                (diaDay === DiaType.OCT_30 && isSunday(setYear, 10, 30)) ||
                (diaDay === DiaType.OCT_31 && isSunday(setYear, 10, 31)) ||
                (diaDay === DiaType.NOV_01 && isSunday(setYear, 11, 1)) ||
                (diaDay === DiaType.NOV_02 && isSunday(setYear, 11, 2)) ||
                (diaDay === DiaType.NOV_03 && isSunday(setYear, 11, 3)) ||
                (diaDay === DiaType.NOV_04 && isSunday(setYear, 11, 4)) ||
                (diaDay === DiaType.NOV_05 && isSunday(setYear, 11, 5)) ||
                (diaDay === DiaType.NOV_06 && isSunday(setYear, 11, 6)) ||
                (diaDay === DiaType.NOV_07 && isSunday(setYear, 11, 7)) ||
                (diaDay === DiaType.NOV_08 && isSunday(setYear, 11, 8)) ||
                (diaDay === DiaType.NOV_09 && isSunday(setYear, 11, 9)) ||
                (diaDay === DiaType.NOV_10 && isSunday(setYear, 11, 10)) ||
                (diaDay === DiaType.NOV_11 && isSunday(setYear, 11, 11)) ||
                (diaDay === DiaType.NOV_12 && isSunday(setYear, 11, 12)) ||
                (diaDay === DiaType.NOV_13 && isSunday(setYear, 11, 13)) ||
                (diaDay === DiaType.NOV_14 && isSunday(setYear, 11, 14)) ||
                (diaDay === DiaType.NOV_15 && isSunday(setYear, 11, 15)) ||
                (diaDay === DiaType.NOV_16 && isSunday(setYear, 11, 16)) ||
                (diaDay === DiaType.NOV_17 && isSunday(setYear, 11, 17)) ||
                (diaDay === DiaType.NOV_18 && isSunday(setYear, 11, 18)) ||
                (diaDay === DiaType.NOV_19 && isSunday(setYear, 11, 19)) ||
                (diaDay === DiaType.NOV_20 && isSunday(setYear, 11, 20)) ||
                (diaDay === DiaType.NOV_21 && isSunday(setYear, 11, 21)) ||
                (diaDay === DiaType.NOV_22 && isSunday(setYear, 11, 22)) ||
                (diaDay === DiaType.NOV_23 && isSunday(setYear, 11, 23)) ||
                (diaDay === DiaType.NOV_24 && isSunday(setYear, 11, 24)) ||
                (diaDay === DiaType.NOV_25 && isSunday(setYear, 11, 25)) ||
                (diaDay === DiaType.NOV_26 && isSunday(setYear, 11, 26)) ||
                (diaDay === DiaType.NOV_27 && isSunday(setYear, 11, 27)) ||
                (diaDay === DiaType.NOV_28 && isSunday(setYear, 11, 28)) ||
                (diaDay === DiaType.NOV_29 && isSunday(setYear, 11, 29)) ||
                (diaDay === DiaType.NOV_30 && isSunday(setYear, 11, 30)))) {
                    return true; // 水曜日運休の場合
            }
        }
        if (value === "休日運休") {
            if ((diaDay === DiaType.WEEKDAY)||
               ((diaDay === DiaType.OCT_01 && !isSunday(setYear, 10, 1)) ||
                (diaDay === DiaType.OCT_02 && !isSunday(setYear, 10, 2)) ||
                (diaDay === DiaType.OCT_03 && !isSunday(setYear, 10, 3)) ||
                (diaDay === DiaType.OCT_04 && !isSunday(setYear, 10, 4)) ||
                (diaDay === DiaType.OCT_05 && !isSunday(setYear, 10, 5)) ||
                (diaDay === DiaType.OCT_06 && !isSunday(setYear, 10, 6)) ||
                (diaDay === DiaType.OCT_07 && !isSunday(setYear, 10, 7)) ||
                (diaDay === DiaType.OCT_08 && !isSunday(setYear, 10, 8)) ||
                (diaDay === DiaType.OCT_09 && !isSunday(setYear, 10, 9)) ||
                (diaDay === DiaType.OCT_10 && !isSunday(setYear, 10, 10)) ||
                (diaDay === DiaType.OCT_11 && !isSunday(setYear, 10, 11)) ||
                (diaDay === DiaType.OCT_12 && !isSunday(setYear, 10, 12)) ||
                (diaDay === DiaType.OCT_13 && !isSunday(setYear, 10, 13)) ||
                (diaDay === DiaType.OCT_14 && !isSunday(setYear, 10, 14)) ||
                (diaDay === DiaType.OCT_15 && !isSunday(setYear, 10, 15)) ||
                (diaDay === DiaType.OCT_16 && !isSunday(setYear, 10, 16)) ||
                (diaDay === DiaType.OCT_17 && !isSunday(setYear, 10, 17)) ||
                (diaDay === DiaType.OCT_18 && !isSunday(setYear, 10, 18)) ||
                (diaDay === DiaType.OCT_19 && !isSunday(setYear, 10, 19)) ||
                (diaDay === DiaType.OCT_20 && !isSunday(setYear, 10, 20)) ||
                (diaDay === DiaType.OCT_21 && !isSunday(setYear, 10, 21)) ||
                (diaDay === DiaType.OCT_22 && !isSunday(setYear, 10, 22)) ||
                (diaDay === DiaType.OCT_23 && !isSunday(setYear, 10, 23)) ||
                (diaDay === DiaType.OCT_24 && !isSunday(setYear, 10, 24)) ||
                (diaDay === DiaType.OCT_25 && !isSunday(setYear, 10, 25)) ||
                (diaDay === DiaType.OCT_26 && !isSunday(setYear, 10, 26)) ||
                (diaDay === DiaType.OCT_27 && !isSunday(setYear, 10, 27)) ||
                (diaDay === DiaType.OCT_28 && !isSunday(setYear, 10, 28)) ||
                (diaDay === DiaType.OCT_29 && !isSunday(setYear, 10, 29)) ||
                (diaDay === DiaType.OCT_30 && !isSunday(setYear, 10, 30)) ||
                (diaDay === DiaType.OCT_31 && !isSunday(setYear, 10, 31)) ||
                (diaDay === DiaType.NOV_01 && !isSunday(setYear, 11, 1)) ||
                (diaDay === DiaType.NOV_02 && !isSunday(setYear, 11, 2)) ||
                (diaDay === DiaType.NOV_03 && !isSunday(setYear, 11, 3)) ||
                (diaDay === DiaType.NOV_04 && !isSunday(setYear, 11, 4)) ||
                (diaDay === DiaType.NOV_05 && !isSunday(setYear, 11, 5)) ||
                (diaDay === DiaType.NOV_06 && !isSunday(setYear, 11, 6)) ||
                (diaDay === DiaType.NOV_07 && !isSunday(setYear, 11, 7)) ||
                (diaDay === DiaType.NOV_08 && !isSunday(setYear, 11, 8)) ||
                (diaDay === DiaType.NOV_09 && !isSunday(setYear, 11, 9)) ||
                (diaDay === DiaType.NOV_10 && !isSunday(setYear, 11, 10)) ||
                (diaDay === DiaType.NOV_11 && !isSunday(setYear, 11, 11)) ||
                (diaDay === DiaType.NOV_12 && !isSunday(setYear, 11, 12)) ||
                (diaDay === DiaType.NOV_13 && !isSunday(setYear, 11, 13)) ||
                (diaDay === DiaType.NOV_14 && !isSunday(setYear, 11, 14)) ||
                (diaDay === DiaType.NOV_15 && !isSunday(setYear, 11, 15)) ||
                (diaDay === DiaType.NOV_16 && !isSunday(setYear, 11, 16)) ||
                (diaDay === DiaType.NOV_17 && !isSunday(setYear, 11, 17)) ||
                (diaDay === DiaType.NOV_18 && !isSunday(setYear, 11, 18)) ||
                (diaDay === DiaType.NOV_19 && !isSunday(setYear, 11, 19)) ||
                (diaDay === DiaType.NOV_20 && !isSunday(setYear, 11, 20)) ||
                (diaDay === DiaType.NOV_21 && !isSunday(setYear, 11, 21)) ||
                (diaDay === DiaType.NOV_22 && !isSunday(setYear, 11, 22)) ||
                (diaDay === DiaType.NOV_23 && !isSunday(setYear, 11, 23)) ||
                (diaDay === DiaType.NOV_24 && !isSunday(setYear, 11, 24)) ||
                (diaDay === DiaType.NOV_25 && !isSunday(setYear, 11, 25)) ||
                (diaDay === DiaType.NOV_26 && !isSunday(setYear, 11, 26)) ||
                (diaDay === DiaType.NOV_27 && !isSunday(setYear, 11, 27)) ||
                (diaDay === DiaType.NOV_28 && !isSunday(setYear, 11, 28)) ||
                (diaDay === DiaType.NOV_29 && !isSunday(setYear, 11, 29)) ||
                (diaDay === DiaType.NOV_30 && !isSunday(setYear, 11, 30)))) {
                    return true; // 水曜日運休の場合
            }
        }
        if (value === "土曜・休日") {
            if (((diaDay === DiaType.HOLIDAY))||
               ((diaDay === DiaType.OCT_01 && isHoliday(setYear, 10, 1)) ||
                (diaDay === DiaType.OCT_02 && isHoliday(setYear, 10, 2)) ||
                (diaDay === DiaType.OCT_03 && isHoliday(setYear, 10, 3)) ||
                (diaDay === DiaType.OCT_04 && isHoliday(setYear, 10, 4)) ||
                (diaDay === DiaType.OCT_05 && isHoliday(setYear, 10, 5)) ||
                (diaDay === DiaType.OCT_06 && isHoliday(setYear, 10, 6)) ||
                (diaDay === DiaType.OCT_07 && isHoliday(setYear, 10, 7)) ||
                (diaDay === DiaType.OCT_08 && isHoliday(setYear, 10, 8)) ||
                (diaDay === DiaType.OCT_09 && isHoliday(setYear, 10, 9)) ||
                (diaDay === DiaType.OCT_10 && isHoliday(setYear, 10, 10)) ||
                (diaDay === DiaType.OCT_11 && isHoliday(setYear, 10, 11)) ||
                (diaDay === DiaType.OCT_12 && isHoliday(setYear, 10, 12)) ||
                (diaDay === DiaType.OCT_13 && isHoliday(setYear, 10, 13)) ||
                (diaDay === DiaType.OCT_14 && isHoliday(setYear, 10, 14)) ||
                (diaDay === DiaType.OCT_15 && isHoliday(setYear, 10, 15)) ||
                (diaDay === DiaType.OCT_16 && isHoliday(setYear, 10, 16)) ||
                (diaDay === DiaType.OCT_17 && isHoliday(setYear, 10, 17)) ||
                (diaDay === DiaType.OCT_18 && isHoliday(setYear, 10, 18)) ||
                (diaDay === DiaType.OCT_19 && isHoliday(setYear, 10, 19)) ||
                (diaDay === DiaType.OCT_20 && isHoliday(setYear, 10, 20)) ||
                (diaDay === DiaType.OCT_21 && isHoliday(setYear, 10, 21)) ||
                (diaDay === DiaType.OCT_22 && isHoliday(setYear, 10, 22)) ||
                (diaDay === DiaType.OCT_23 && isHoliday(setYear, 10, 23)) ||
                (diaDay === DiaType.OCT_24 && isHoliday(setYear, 10, 24)) ||
                (diaDay === DiaType.OCT_25 && isHoliday(setYear, 10, 25)) ||
                (diaDay === DiaType.OCT_26 && isHoliday(setYear, 10, 26)) ||
                (diaDay === DiaType.OCT_31 && isHoliday(setYear, 10, 31)) ||
                (diaDay === DiaType.NOV_01 && isHoliday(setYear, 11, 1)) ||
                (diaDay === DiaType.NOV_02 && isHoliday(setYear, 11, 2)) ||
                (diaDay === DiaType.NOV_03 && isHoliday(setYear, 11, 3)) ||
                (diaDay === DiaType.NOV_04 && isHoliday(setYear, 11, 4)) ||
                (diaDay === DiaType.NOV_05 && isHoliday(setYear, 11, 5)) ||
                (diaDay === DiaType.NOV_06 && isHoliday(setYear, 11, 6)) ||
                (diaDay === DiaType.NOV_07 && isHoliday(setYear, 11, 7)) ||
                (diaDay === DiaType.NOV_08 && isHoliday(setYear, 11, 8)) ||
                (diaDay === DiaType.NOV_09 && isHoliday(setYear, 11, 9)) ||
                (diaDay === DiaType.NOV_10 && isHoliday(setYear, 11, 10)) ||
                (diaDay === DiaType.NOV_11 && isHoliday(setYear, 11, 11)) ||
                (diaDay === DiaType.NOV_12 && isHoliday(setYear, 11, 12)) ||
                (diaDay === DiaType.NOV_13 && isHoliday(setYear, 11, 13)) ||
                (diaDay === DiaType.NOV_14 && isHoliday(setYear, 11, 14)) ||
                (diaDay === DiaType.NOV_15 && isHoliday(setYear, 11, 15)) ||
                (diaDay === DiaType.NOV_16 && isHoliday(setYear, 11, 16)) ||
                (diaDay === DiaType.NOV_17 && isHoliday(setYear, 11, 17)) ||
                (diaDay === DiaType.NOV_18 && isHoliday(setYear, 11, 18)) ||
                (diaDay === DiaType.NOV_19 && isHoliday(setYear, 11, 19)) ||
                (diaDay === DiaType.NOV_20 && isHoliday(setYear, 11, 20)) ||
                (diaDay === DiaType.NOV_21 && isHoliday(setYear, 11, 21)) ||
                (diaDay === DiaType.NOV_22 && isHoliday(setYear, 11, 22)) ||
                (diaDay === DiaType.NOV_23 && isHoliday(setYear, 11, 23)) ||
                (diaDay === DiaType.NOV_24 && isHoliday(setYear, 11, 24)) ||
                (diaDay === DiaType.NOV_25 && isHoliday(setYear, 11, 25)) ||
                (diaDay === DiaType.NOV_26 && isHoliday(setYear, 11, 26)) ||
                (diaDay === DiaType.NOV_27 && isHoliday(setYear, 11, 27)) ||
                (diaDay === DiaType.NOV_28 && isHoliday(setYear, 11, 28)) ||
                (diaDay === DiaType.NOV_29 && isHoliday(setYear, 11, 29)) ||
                (diaDay === DiaType.NOV_30 && isHoliday(setYear, 11, 30)))) {
                    return true; // 水曜日運休の場合
            }
        }
        return false; // その他の場合
    }//エラーの原因は認識されていないダイヤパターン
    function changeDiaType() {
        switch (diaDay) {
            case DiaType.WEEKDAY: diaDay = DiaType.HOLIDAY; break;
            case DiaType.HOLIDAY: diaDay = DiaType.OCT_01; break;
            case DiaType.OCT_01: diaDay = DiaType.OCT_02; break;
            case DiaType.OCT_02: diaDay = DiaType.OCT_03; break;
            case DiaType.OCT_03: diaDay = DiaType.OCT_04; break;
            case DiaType.OCT_04: diaDay = DiaType.OCT_05; break;
            case DiaType.OCT_05: diaDay = DiaType.OCT_06; break;
            case DiaType.OCT_06: diaDay = DiaType.OCT_07; break;
            case DiaType.OCT_07: diaDay = DiaType.OCT_08; break;
            case DiaType.OCT_08: diaDay = DiaType.OCT_09; break;
            case DiaType.OCT_09: diaDay = DiaType.OCT_10; break;
            case DiaType.OCT_10: diaDay = DiaType.OCT_11; break;
            case DiaType.OCT_11: diaDay = DiaType.OCT_12; break;
            case DiaType.OCT_12: diaDay = DiaType.OCT_13; break;
            case DiaType.OCT_13: diaDay = DiaType.OCT_14; break;
            case DiaType.OCT_14: diaDay = DiaType.OCT_15; break;
            case DiaType.OCT_15: diaDay = DiaType.OCT_16; break;
            case DiaType.OCT_16: diaDay = DiaType.OCT_17; break;
            case DiaType.OCT_17: diaDay = DiaType.OCT_18; break;
            case DiaType.OCT_18: diaDay = DiaType.OCT_19; break;
            case DiaType.OCT_19: diaDay = DiaType.OCT_20; break;
            case DiaType.OCT_20: diaDay = DiaType.OCT_21; break;
            case DiaType.OCT_21: diaDay = DiaType.OCT_22; break;
            case DiaType.OCT_22: diaDay = DiaType.OCT_23; break;
            case DiaType.OCT_23: diaDay = DiaType.OCT_24; break;
            case DiaType.OCT_24: diaDay = DiaType.OCT_25; break;
            case DiaType.OCT_25: diaDay = DiaType.OCT_26; break;
            case DiaType.OCT_26: diaDay = DiaType.OCT_27; break;
            case DiaType.OCT_27: diaDay = DiaType.OCT_28; break;
            case DiaType.OCT_28: diaDay = DiaType.OCT_29; break;
            case DiaType.OCT_29: diaDay = DiaType.OCT_30; break;
            case DiaType.OCT_30: diaDay = DiaType.OCT_31; break;
            case DiaType.OCT_31: diaDay = DiaType.NOV_01; break;
            case DiaType.NOV_01: diaDay = DiaType.NOV_02; break;
            case DiaType.NOV_02: diaDay = DiaType.NOV_03; break;
            case DiaType.NOV_03: diaDay = DiaType.NOV_04; break;
            case DiaType.NOV_04: diaDay = DiaType.NOV_05; break;
            case DiaType.NOV_05: diaDay = DiaType.NOV_06; break;
            case DiaType.NOV_06: diaDay = DiaType.NOV_07; break;
            case DiaType.NOV_07: diaDay = DiaType.NOV_08; break;
            case DiaType.NOV_08: diaDay = DiaType.NOV_09; break;
            case DiaType.NOV_09: diaDay = DiaType.NOV_10; break;
            case DiaType.NOV_10: diaDay = DiaType.NOV_11; break;
            case DiaType.NOV_11: diaDay = DiaType.NOV_12; break;
            case DiaType.NOV_12: diaDay = DiaType.NOV_13; break;
            case DiaType.NOV_13: diaDay = DiaType.NOV_14; break;
            case DiaType.NOV_14: diaDay = DiaType.NOV_15; break;
            case DiaType.NOV_15: diaDay = DiaType.NOV_16; break;
            case DiaType.NOV_16: diaDay = DiaType.NOV_17; break;
            case DiaType.NOV_17: diaDay = DiaType.NOV_18; break;
            case DiaType.NOV_18: diaDay = DiaType.NOV_19; break;
            case DiaType.NOV_19: diaDay = DiaType.NOV_20; break;
            case DiaType.NOV_20: diaDay = DiaType.NOV_21; break;
            case DiaType.NOV_21: diaDay = DiaType.NOV_22; break;
            case DiaType.NOV_22: diaDay = DiaType.NOV_23; break;
            case DiaType.NOV_23: diaDay = DiaType.NOV_24; break;
            case DiaType.NOV_24: diaDay = DiaType.NOV_25; break;
            case DiaType.NOV_25: diaDay = DiaType.NOV_26; break;
            case DiaType.NOV_26: diaDay = DiaType.NOV_27; break;
            case DiaType.NOV_27: diaDay = DiaType.NOV_28; break;
            case DiaType.NOV_28: diaDay = DiaType.NOV_29; break;
            case DiaType.NOV_29: diaDay = DiaType.NOV_30; break;
            case DiaType.NOV_30: diaDay = DiaType.WEEKDAY; break;
        }
    
        updateDisplayDiaDay();
        getTimeTable();
        setNewTime(setSecondSum);
        drawTrain();
        resetTimetableSpace();
    }
    
    
    
    
    
    //種別を入れると文字色と背景色を返す
    //color=0なら背景色を返す、color=1なら文字色を返す
    function getTypeColor(typeName, colorType)
    {
    	var i;
    	for(i=0 ; i<trainTypeColor.length ; i++)
    	{
    		//alert(typeName+" "+trainTypeColor[i])
    		if(typeName == trainTypeColor[i][0])
    		{
    			if(colorType == 0)
    				//背景色を返す
    				return trainTypeColor[i][1][0];
    			else
    				//文字色を返す
    				return trainTypeColor[i][1][1];
    		}
    	}
    	
    }
    
    
    
    
    
    
    function HHMMtoSecond(HHMM)
    {
    	var hour = Math.floor(HHMM / 100);
    	var minute = HHMM % 100;
    	var second = 0;
    	
    	return hour * 60 * 60 + minute * 60 + second;
    }
    
    function HHMMSSToSecond(hour, minute, second)
    {
    	return hour * 60 * 60 + minute * 60 + second;
    }
    
    function secondToHHMMSS(value)
    {
    	var hour = Math.floor(value / 3600);
    	var minute = Math.floor(value % 3600 / 60);
    	var second = Math.floor(value % 60);
    	
    	return hour + ":" + minute + ":" + second;
    }
    
    function secondToHour(value)
    {
    	var num = Math.floor(value / 3600);
    	if(num < 24)
    		return num;
    	else
    		return num - 24;
    }
    
    function secondToMinute(value)
    {
    	return Math.floor(value % 3600 / 60);
    }
    
    function secondToSecond(value)
    {
    	return Math.floor(value % 60);
    }
    
  5. 以前、ここかテラテイルでプログラミングの質問をする際に教わったことは、
    あまり長すぎると読み手がつかれるというのを聞きました。
    それは嘘なのですね。
    今回はあえて長く書きます。

    日本語不自由やめてね

  6. @sembokulove

    以前の質問でも同様の指摘がありましたが、まず他責思考はやめたほうがいいです。

    今回も不要なテンプレート文が残っていたり、内容が整理されていなかったりと、読み手への配慮が不足している印象を受けます。
    投稿前に「誰が読んでも誤解なく伝わるか」を意識して、丁寧に確認してみてください。

    あまり長すぎると読み手がつかれるというのを聞きました。
    それは嘘なのですね。

    嘘ではないです。
    「長い=悪い」のではなく、「関係のない情報まで含めると読み手の負担になる」ということです。
    質問する際は、問題の切り分けをした上で、影響範囲を明確にした質問文を作るようにしましょう。

    他の方のアドバイスにもありますが、まずはもう少し自分で整理し、問題の切り分けを行った上で質問するようにしてください。

  7. ご提示の参考にしたページのコードをダウンロードし、ご提示されたコードに差し替えて試してみましたが、切り替えボタンをクリックすると問題なく「平日」→「土・休日」→「10月1日」…と切り替わります。

    どのような手順で問題が起きるのか、詳しく書いていただけますか?

  8. ご提示の参考にしたページ

    参考にしたページは完動品で、質問者がそのページからコピーして改変したコードが動かないと言う意味かと。


    シミュレーターのプログラムについては改変についてはOKとしてますが、ライセンスが明確では無いため、コピーライトと言う認識で良いかと思います。


    oh_jigさんの回答にもありますが未計画のコードをどうしたいのか、これが伝わらない限り、永遠に話が進むことは無いでしょう。

  9. @sembokulove

    Questioner

    10月と11月に関しては、完全に土曜日と日祝日を分割します。
    それ以外の月では平常通り、土日祝と平日の分岐をさせます。

  10. @STSynthe

    参考にしたページは完動品で、質問者がそのページからコピーして改変したコードが動かないと言う意味かと。

    まさにそういうことなんですよ。なので完動品のコードを提示された改変コードで差し替えて試してみたのですが、問題が発生しないので、質問者が何に困っているのかわからない、というのが現状なのです。

    おそらく、提示されていないコードがあるんだとは思うのですが。

  11. @sembokulove

    Questioner

    間違いがあるとすれば、多分ここか、

    function isHoliday(year, month, day) {
        const date = new Date(year, month - 1, day); // Month is 0-indexed in Date
        const dayOfWeek = date.getDay();
        return dayOfWeek === 0 || dayOfWeek === 6; // 0 is Sunday, 6 is Saturday
    }
    
    function isWeekday(year, month, day) {
        const dayOfWeek = new Date(year, month - 1, day).getDay();
        return dayOfWeek >= 1 && dayOfWeek <= 5;
    }
    
    function isSunday(year, month, day) {
        const date = new Date(year, month - 1, day);
        return date.getDay() === 0;
    }
    function isTwilightDown(year, month, day) {
        const date = new Date(year, month - 1, day);
        const dayOfWeek = date.getDay();
        return dayOfWeek === 1 || dayOfWeek === 3 || dayOfWeek === 5 || dayOfWeek === 6;
    }
    function isTwilightUp(year, month, day) {
        const date = new Date(year, month - 1, day);
        const dayOfWeek = date.getDay();
        return dayOfWeek === 0 || dayOfWeek === 1 || dayOfWeek === 3 || dayOfWeek === 5;
    }
    function isWednesday(year, month, day) {
        const date = new Date(year, month - 1, day);
        return date.getDay() === 3;
    }
    

    かもしくは、少々長くなりますが、

    // dayTypeJudge11.txt - Modified holidays array
    const holidays = [
        { year: 2013, month: 1, date: 1 },
        { year: 2013, month: 10, date: 14 },
        { year: 2013, month: 11, date: 4 },
        { year: 2013, month: 12, date: 23 },
        { year: 2014, month: 1, date: 1 },
        { year: 2014, month: 1, date: 2 },
        { year: 2014, month: 1, date: 3 },
        { year: 2014, month: 1, date: 13 },
        { year: 2014, month: 2, date: 11 },
        { year: 2014, month: 3, date: 21 },
        { year: 2014, month: 4, date: 29 },
        { year: 2014, month: 5, date: 5 },
        { year: 2014, month: 7, date: 21 },
        { year: 2014, month: 9, date: 15 },
        { year: 2014, month: 9, date: 23 },
        { year: 2014, month: 10, date: 12 },
        { year: 2014, month: 11, date: 3 },
        { year: 2014, month: 11, date: 24 },
        { year: 2014, month: 12, date: 23 },
        { year: 2015, month: 1, date: 1 },
        { year: 2015, month: 1, date: 2 },
        { year: 2015, month: 1, date: 3 },
        { year: 2015, month: 1, date: 12 },
        { year: 2015, month: 2, date: 11 },
        { year: 2015, month: 3, date: 21 },
        // Fixed Japanese Holidays (added based on your request)
        { year: 2015, month: 1, date: 1 },  // 元日
        { year: 2015, month: 2, date: 11 }, // 建国記念の日
        { year: 2020, month: 2, date: 23 }, // 天皇誕生日 (example year for 2020 onwards)
        { year: 2015, month: 4, date: 29 }, // 昭和の日
        { year: 2015, month: 5, date: 3 },  // 憲法記念日
        { year: 2015, month: 5, date: 4 },  // みどりの日
        { year: 2015, month: 5, date: 5 },  // こどもの日
        { year: 2015, month: 11, date: 3 }, // 文化の日
        { year: 2015, month: 11, date: 23 }, // 勤労感謝の日
        { year: 2025, month: 6, date: 13 } // 勤労感謝の日
    ];
    
    // DayOfWeek enum remains the same as in diaTypeJudge11.txt
    
    // Helper function to get the Nth day of a specific day of the week in a month 
    function getNthDayOfMonth(year, month, dayOfWeek, n) {
        let count = 0;
        let day = 1;
        let targetDate = null;
        while (true) {
            const dateObj = new Date(year, month - 1, day);
            if (dateObj.getMonth() !== month - 1) { // 月が変わったら終了 
                break;
            }
            if (dateObj.getDay() === dayOfWeek) {
                count++;
                if (count === n) {
                    targetDate = dateObj;
                    break;
                }
            }
            day++;
        }
        if (targetDate) {
            return { year: targetDate.getFullYear(), month: targetDate.getMonth() + 1, date: targetDate.getDate() };
        }
        return null; // 見つからなかった場合 
    }
    
    // Simplified function to calculate Vernal Equinox (approximate) 
    function calculateVernalEquinox(year) {
        let day = 20;
        if (year >= 2012 && year % 4 === 0) {
            if (year === 2012 || year === 2016 || year === 2020 || year === 2024 || year === 2028) {
                day = 20;
            }
        }
        return new Date(year, 2, day);
    }
    
    // Simplified function to calculate Autumnal Equinox (approximate) 
    function calculateAutumnalEquinox(year) {
        let day = 23;
        if (year >= 2012 && year % 4 === 0) {
            if (year === 2012 || year === 2016 || year === 2020 || year === 2024 || year === 2028) {
                day = 22;
            }
        }
        return new Date(year, 8, day);
    }
    
    
    // Function to get Japanese Holidays dynamically 
    function getJapaneseHolidays(year) {
        const dynamicHolidays = [];
    
        // Fixed Holidays (already in `holidays` array, but shown here for dynamic calculation if needed)
        // For fixed holidays, we are now relying on the `holidays` array defined at the top.
        // This function will primarily handle the "Happy Monday" and Equinox holidays.
    
        // Happy Monday Holidays 
        dynamicHolidays.push(getNthDayOfMonth(year, 1, DayOfWeek.MONDAY, 2)); // 成人の日 (2nd Monday of Jan) 
        dynamicHolidays.push(getNthDayOfMonth(year, 7, DayOfWeek.MONDAY, 3)); // 海の日 (3rd Monday of July) 
        dynamicHolidays.push(getNthDayOfMonth(year, 9, DayOfWeek.MONDAY, 3)); // 敬老の日 (3rd Monday of Sep) 
        dynamicHolidays.push(getNthDayOfMonth(year, 10, DayOfWeek.MONDAY, 2)); // スポーツの日 (2nd Monday of Oct) 
    
        // Equinox Holidays (approximate) 
        const equinoxSpring = calculateVernalEquinox(year);
        if (equinoxSpring) {
            dynamicHolidays.push({ month: equinoxSpring.getMonth() + 1, date: equinoxSpring.getDate() });
        }
        const equinoxAutumn = calculateAutumnalEquinox(year);
        if (equinoxAutumn) {
            dynamicHolidays.push({ month: equinoxAutumn.getMonth() + 1, date: equinoxAutumn.getDate() });
        }
    
        // Filter out nulls from getNthDayOfMonth for years where a holiday might not exist (e.g., if n is too high)
        return dynamicHolidays.filter(h => h !== null);
    }
    
    // Modified isHolidayOrSunday function based on diaTypeJudge1501.txt 
    function isHolidayOrSunday(year, month, date) {
        const dateObj = new Date(year, month - 1, date);
    
        // 1. Check if it's a Sunday 
        if (dateObj.getDay() === DayOfWeek.SUNDAY) {
            return true;
        }
    
        // 2. Check against the predefined fixed holidays array 
        const isFixedHoliday = holidays.some(holiday =>
            holiday.year === year && holiday.month === month && holiday.date === date
        );
        if (isFixedHoliday) {
            return true;
        }
    
        // 3. Get dynamically calculated holidays for the given year 
        const currentYearDynamicHolidays = getJapaneseHolidays(year);
        const isDynamicHoliday = currentYearDynamicHolidays.some(holiday =>
            holiday.month === month && holiday.date === date
        );
        if (isDynamicHoliday) {
            return true;
        }
    
        // 4. Check for Substitute Holiday (振替休日) 
        // Only check if it's a Monday 
        if (dateObj.getDay() === DayOfWeek.MONDAY) {
            const previousDay = new Date(year, month - 1, date - 1);
            const previousDayYear = previousDay.getFullYear();
            const previousDayMonth = previousDay.getMonth() + 1;
            const previousDayDate = previousDay.getDate();
    
            // Check if the previous day was a Sunday AND a fixed holiday 
            if (previousDay.getDay() === DayOfWeek.SUNDAY) {
                const isPreviousDayFixedHoliday = holidays.some(holiday =>
                    holiday.year === previousDayYear && holiday.month === previousDayMonth && holiday.date === previousDayDate
                );
    
                // Also check if the previous day was a Sunday AND a dynamically calculated holiday
                const previousYearDynamicHolidays = getJapaneseHolidays(previousDayYear);
                const isPreviousDayDynamicHoliday = previousYearDynamicHolidays.some(holiday =>
                    holiday.month === previousDayMonth && holiday.date === previousDayDate
                );
    
                if (isPreviousDayFixedHoliday || isPreviousDayDynamicHoliday) {
                    return true; // Previous day was a Sunday holiday, so this Monday is a substitute holiday
                }
            }
        }
    
        return false; // Not a Sunday, fixed holiday, dynamic holiday, or substitute holiday
    }
    
    
    // dayJudge function based on diaTypeJudge1501.txt 
    function dayJudge(year, month, date, day) { // day は 0:日曜, 1:月曜, ..., 6:土曜
    
        // 1. First, determine SPECIAL_DIA_1 and SPECIAL_DIA_2 (considering priority) 
        const isSpecialDay1 = (date === 12 && month === 10) || (date === 3 && month === 11) || (date === 24 && month === 11);
        if (isSpecialDay1) {
            return DiaType.SPECIAL1;
        }
    
        const isSpecialDay2 = (date === 9 && month === 10) || (date === 3 && month === 12);
        if (isSpecialDay2) {
            return DiaType.SPECIAL2;
        }
    
    
        // 2. Prioritize individual date schedules (OCT_XX, NOV_XX, etc.) 
        switch (month) {
            case 10: // October processing 
                switch (date) {
                    case 1: return DiaType.OCT_01;
                    case 2: return DiaType.OCT_02;
                    case 3: return DiaType.OCT_03;
                    case 31: return DiaType.OCT_31;
                    default: break;
                }
                break;
            case 11: // November processing 
                switch (date) {
                    case 1: return DiaType.NOV_01;
                    case 2: return DiaType.NOV_02;
                    case 3: return DiaType.NOV_03;
                    case 30: return DiaType.NOV_30;
                    default: break;
                }
                break;
            default:
                break;
        }
    
        // 3. Determine if it's a Sunday or a Holiday (including both fixed and dynamic holidays) 
        // 3. 日曜日または祝日であるかどうかの判定(holidays配列と日曜日の両方を含む)
        const isWeekday = day >= DayOfWeek.MONDAY && day <= DayOfWeek.FRIDAY;
        const isSaturday = day === DayOfWeek.SATURDAY;
        const isSunday = day === DayOfWeek.SUNDAY;
        const isHoliday = holidays.some(holiday => holiday.year === year && holiday.month === month && holiday.date === date);
        // 特殊ダイヤ、平日ダイヤ、土曜日ダイヤ、日曜日ダイヤを判定
        if (isWeekday && !isHoliday) {
            return "weekday";
        } else if (isSaturday) {
            return "saturday";
        } else if (isSunday || isHoliday) {
            return "sunday";
        } else {
            // その他の場合は平日ダイヤとして扱う
            return "weekday";
        }
    }
    ```ですね。
    
  12. ご提示のコードで diaTypeJudge.js を差し替えましたが、やはりスクリーンショットで提示される部分の表示は切り替わります。

    問題が上手く伝わっていないのかもしれません。
    もしかして、『ここの部分が切り替わらない』という言葉は、「ここの部分の表示が切り替わらない」という意味ではない、とかでしょうか?

  13. @sembokulove

    Questioner

    お返事が遅くなり申し訳なかったことと、また、お時間をおさきいただきありがとうございます。
    問題は、

    function judgeTrainRunningDay(value) {
        if (value === "全日") return true;
        if ((value === "休日")||(value === "休日運転")) {
            if ((diaDay === DiaType.HOLIDAY)||
               ((diaDay === DiaType.OCT_01 && isSunday(setYear, 10, 1)) ||
                (diaDay === DiaType.OCT_02 && isSunday(setYear, 10, 2)) ||
                (diaDay === DiaType.OCT_03 && isSunday(setYear, 10, 3)) ||
                (diaDay === DiaType.NOV_30 && isSunday(setYear, 11, 30)))) {
                   return true; // 水曜日運休の場合
            }
        }
        return false; // その他の場合
    }
    

    が日曜日しか判定しておらないことです。
    理由はわかっておりまして、

    function isSunday(year, month, day) {
        const date = new Date(year, month - 1, day);
        return date.getDay() === 0;
    }
    

    とすることにより、0は日曜日を表し、日曜日だけというようになってしまうからなのです。
    なので、変えるとすれば、
    const date = new Date(year, month - 1, day);
    return date.getDay() === 0;
    の部分だと思います。
    これを先ほどのdiatymejudgeファイルで指定した休日の値を反映させたいということなのです。
    それとも

    function isSunday(year, month, day) {
        const date = new Date(year, month - 1, day);
        return date.getDay() === 0;
    }
    

    というやり方を抜本的に見直す必要がありますかねぇ。

  14. 質問に書かれている表示の切り替えは問題ではない、ということでいいですか?

    その『日曜日しか判定しておらない』という問題は、

    • どのような操作をすると起きますか?
    • その問題が起こったことは、どのようにすれば確認できますか?
    • その際に、本来はどのような動作であってほしいですか?
  15. @sembokulove

    Questioner

    画面左側に平日か土曜休日かもしくは、日付のダイヤの表示が出ません。
    また、アニメーションは動きますけれども、切り替えができません。
    本来は本日6月18日をdaytimejudgeファイルのconst holidaysに対し、6月18日を設定すると、土曜祝日ダイヤ扱いとさせていただきたいのですが、それができないです。
    恐らく初期値のままです。
    結論といたしまして、ダイヤ設定表示がないこと、切り替えができないこと、初期値のままだということです。

  16. @sembokulove

    Questioner

    当初の目的である、土曜日以外の祝祭日判定はできるようになりました。
    本当はそれよりももっと踏み込んだ内容、平日ダイヤと土休日ダイヤと、10月11月ダイヤの切り替えがしたかったのですけれども、ここではあいにくながら、期待した内容のご会合が1日たってもいまだ返事を頂戴いただけないため、締め切り扱いとさせていただきます。

日付の判定ということでしたら、ここで執り行っております。

function judgeDiaDay() {
    let nowDateSet = new Date(); // 現在の日付を取得
    let nowHour = nowDateSet.getHours();
    let nowMinute = nowDateSet.getMinutes();
    let nowSecond = nowDateSet.getSeconds();
    let nowDay = nowDateSet.getDay();
    
    // 現在の年、月、日を取得
    let nowYear = nowDateSet.getFullYear();
    let nowMonth = nowDateSet.getMonth() + 1; // 月は0から始まるため1を加算
    let nowDate = nowDateSet.getDate();

    // 日付変更時刻と現在時刻を比較
    if (HHMMSSToSecond(nowHour, nowMinute, nowSecond) < dayChangeTime) {
        nowDateSet.setDate(nowDateSet.getDate() - 1); // 前日の日付に変更
        nowYear = nowDateSet.getFullYear();
        nowMonth = nowDateSet.getMonth() + 1;
        nowDate = nowDateSet.getDate();
        nowDay = nowDateSet.getDay();
    }

    if (nowYear < 2000) nowYear += 1900; // 年の補正

    setYear = nowYear; // ここでsetYearに現在の年を設定
    setMonth = nowMonth;
    setDate = nowDate;
    setDay = nowDay;


    switch (setMonth) {
        case 10:
            switch (setDate) {
                case 01: diaDay = DiaType.OCT_01; break;
                case 02: diaDay = DiaType.OCT_02; break;
                case 03: diaDay = DiaType.OCT_03; break;
                case 31: diaDay = DiaType.OCT_31; break;
                default: 
                    if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.SUNDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.MONDAY;  // 週末の処理
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.TUESDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.WEDNESDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.THURSDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.FRIDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.SATURDAY;
                    } else if (isWeekend(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.WEEKEND;  // 週末の処理
                    } else {
                        diaDay = DiaType.HOLIDAY;
                    }
            }
            break;
        case 11:
            switch (setDate) {
                case 01: diaDay = DiaType.NOV_01; break;
                case 02: diaDay = DiaType.NOV_02; break;
                case 03: diaDay = DiaType.NOV_03; break;
                case 30: diaDay = DiaType.NOV_30; break;
                default: 
                    if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.SUNDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.MONDAY;  // 週末の処理
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.TUESDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.WEDNESDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.THURSDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.FRIDAY;
                    } else if (dayJudge(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.SATURDAY;
                    } else if (isWeekend(setYear, setMonth, setDate, setDay)) {
                        diaDay = DiaType.WEEKEND;  // 週末の処理
                    } else {
                        diaDay = DiaType.HOLIDAY;
                    }
            }
                break;
            default: 
                diaDay = dayJudge(setYear, setMonth, setDate, setDay) === "weekday" ? DiaType.WEEKDAY : DiaType.HOLIDAY;
    }

    updateDisplayDiaDay();
    return diaDay === DiaType.WEEKDAY;
}```にて、作ったものが呼び起こされるようです。
0Like

Comments

  1. judgeDiaDayはどこから呼ばれているのですか?

  2. @sembokulove

    Questioner

    function main()
    {
    //現在時刻を1秒ごとに更新して表示する
    nowTimeDisplay();
    judgeDiaDay(); //今日が平日ダイヤか休日ダイヤか
    setInterval("nowTimeDisplay()",1000);

    //時刻表データを取得、整える
    getTimeTable();
    
    //現在日時の取得	
    
    //路線図を描く
    drawRouteMap();
    adjustRouteMap();
    
    
    //最初に列車を描くスペースを作っておく
    makeDrawTrainSpace();
    
    
    //駅から発車する列車の時刻を取得する
    //getStationTimetable(34);
    
    
    //設定時刻を12時に設定
    //setSecondSum = 12 * 60 * 60;
    //設定時刻を表示
    //document.getElementById("setDateDisplaySpan").innerHTML = "設定日時 " +digitAdjuster(secondToHour(setSecondSum), " ")+":"+digitAdjuster(secondToMinute(setSecondSum), "0")+":"+digitAdjuster(secondToSecond(setSecondSum), "0");	
    
    //各列車の在線位置を割り出す
    //getTrainPosition();
    
    //路線図に列車を配置していく
    //drawTrain();
    
    //リアルタイムで表示更新する
    changeUpdateInterval();
    
    //表示枠をウインドウの大きさに合わせる
    setDisplayArea();
    

    }ではないでしょうか。

function changeDiaType() {
    switch (diaDay) {
        case DiaType.WEEKDAY: diaDay = DiaType.HOLIDAY; break;
        case DiaType.HOLIDAY: diaDay = DiaType.OCT_01; break;
        case DiaType.OCT_01: diaDay = DiaType.OCT_02; break;
        case DiaType.OCT_02: diaDay = DiaType.OCT_03; break;
        case DiaType.OCT_03: diaDay = DiaType.OCT_04; break;
        case DiaType.NOV_30: diaDay = DiaType.WEEKDAY; break;
    }

    updateDisplayDiaDay();
    getTimeTable();
    setNewTime(setSecondSum);
    drawTrain();
    resetTimetableSpace();
}

このコードを見る限り、diaDayがWEEKDAY,HOLIDAY,OCT_01,OCT_02,OCT_03,NOV_30以外のDiaTypeの場合は表示は当然切り替わらないわけですが、それであってますか?

0Like

Comments

  1. @sembokulove

    Questioner

    function changeDiaType() {自体は、現状維持です。

  2. 君の方針は全く訊いてない.
    changeDiaTypeは想定した通りのロジックで動いているか?? っていうことを聞いてる.読めないんだろうけど.

    judgeDiaDayはどこから呼ばれているのですか?

    の意味も理解してないと見えるし,ソースコードを引っ張ってきて改造する前に もっとまともに勉強してほしい .じゃないとやり取りに意味がない.

    何回も言われたかもしれないけどガイドライン読んでね.

    とりあえず問題を特定できるまで最小コードで検証するのは鉄則.

  3. 現状維持したら、単にエラーが直らないだけですよ。
    発生している問題の画像で「ここの部分が切り替わらない」と言って指している部分を切り替えているのが、このchangeDiaType関数です。
    元々のサイトの場合はここで、「平日ダイヤ(DiaDay=0)」「土・休日ダイヤ(DiaDay=1)」を切り替えていたのを、複数を順番に切り替えるように変更したいわけですよね?
    バグってるとしたら、まず疑うべきなのはこの関数ですよ。
    case DiaType.OCT_03からcase DiaType.NOV_30の間は「長くなるから省略しているのかな?」とも思いますが(なんで肝心のこの関数を省略して、他のところをそのまま載せているのかは疑問ですが)、例えばdayJudge関数が下記で返しているDiaType.SATURDAYとかDiaType.SPECIAL1とかの対応はしていますか?

    DiaType.SATURDAY
        // 4. 土曜日であるかどうかの判定
        if (day === DayOfWeek.SATURDAY) {
            return DiaType.SATURDAY;
        }
    
    DiaType.SPECIAL1
        if (isSpecialDay1) {
            return DiaType.SPECIAL1;
        }
    

    そもそもDiaTypeの宣言が下のようになってますから、DiaType.SATURDAYとか代入されたdiaDayはundefinedとかになってませんか?

    DiaType宣言部分
    const DiaType = {
        OCT_01: 0,
        OCT_02: 1,
        OCT_03: 2,,
        NOV_30: 60,
        WEEKDAY: 61,
        HOLIDAY: 62
    };
    

    問題箇所の表示内容を返すgetDiaTypeString関数にもDiaType.SATURDAYやDiaType.SPECIAL1は入っているように見えませんから(DiaType.OCT_31とDiaType.NOV_01の間に入っているとかよく分からない実装じゃなければですが)こちらの返り値は空文字列になっちゃっているんじゃありませんか?

    getDiaTypeString(diaType)
    function getDiaTypeString(diaType) {
        switch (diaType) {
            case DiaType.WEEKDAY: return " 平日ダイヤ ";
            case DiaType.HOLIDAY: return "土・休日ダイヤ";
            case DiaType.OCT_01: return "10月01日ダイヤ";
            case DiaType.OCT_02: return "10月02日ダイヤ";
            case DiaType.OCT_03: return "10月03日ダイヤ";
    
            case DiaType.NOV_30: return "11月30日ダイヤ";
            default: return "";
        }
    }
    

    それで正しい動作なんでしょうか?
    もしそれで正しいのであれば、そもそも直すところがどこか分かりませんね。

  4. @sembokulove

    Questioner

    changediatypeに関しては、全容はこのような感じなります。

    function changeDiaType() {
        switch (diaDay) {
            case DiaType.WEEKDAY: diaDay = DiaType.HOLIDAY; break;
            case DiaType.HOLIDAY: diaDay = DiaType.OCT_01; break;
            case DiaType.OCT_01: diaDay = DiaType.OCT_02; break;
            case DiaType.OCT_02: diaDay = DiaType.OCT_03; break;
            case DiaType.OCT_03: diaDay = DiaType.OCT_04; break;
            case DiaType.OCT_04: diaDay = DiaType.OCT_05; break;
            case DiaType.OCT_05: diaDay = DiaType.OCT_06; break;
            case DiaType.OCT_06: diaDay = DiaType.OCT_07; break;
            case DiaType.OCT_07: diaDay = DiaType.OCT_08; break;
            case DiaType.OCT_08: diaDay = DiaType.OCT_09; break;
            case DiaType.OCT_09: diaDay = DiaType.OCT_10; break;
            case DiaType.OCT_10: diaDay = DiaType.OCT_11; break;
            case DiaType.OCT_11: diaDay = DiaType.OCT_12; break;
            case DiaType.OCT_12: diaDay = DiaType.OCT_13; break;
            case DiaType.OCT_13: diaDay = DiaType.OCT_14; break;
            case DiaType.OCT_14: diaDay = DiaType.OCT_15; break;
            case DiaType.OCT_15: diaDay = DiaType.OCT_16; break;
            case DiaType.OCT_16: diaDay = DiaType.OCT_17; break;
            case DiaType.OCT_17: diaDay = DiaType.OCT_18; break;
            case DiaType.OCT_18: diaDay = DiaType.OCT_19; break;
            case DiaType.OCT_19: diaDay = DiaType.OCT_20; break;
            case DiaType.OCT_20: diaDay = DiaType.OCT_21; break;
            case DiaType.OCT_21: diaDay = DiaType.OCT_22; break;
            case DiaType.OCT_22: diaDay = DiaType.OCT_23; break;
            case DiaType.OCT_23: diaDay = DiaType.OCT_24; break;
            case DiaType.OCT_24: diaDay = DiaType.OCT_25; break;
            case DiaType.OCT_25: diaDay = DiaType.OCT_26; break;
            case DiaType.OCT_26: diaDay = DiaType.OCT_27; break;
            case DiaType.OCT_27: diaDay = DiaType.OCT_28; break;
            case DiaType.OCT_28: diaDay = DiaType.OCT_29; break;
            case DiaType.OCT_29: diaDay = DiaType.OCT_30; break;
            case DiaType.OCT_30: diaDay = DiaType.OCT_31; break;
            case DiaType.OCT_31: diaDay = DiaType.NOV_01; break;
            case DiaType.NOV_01: diaDay = DiaType.NOV_02; break;
            case DiaType.NOV_02: diaDay = DiaType.NOV_03; break;
            case DiaType.NOV_03: diaDay = DiaType.NOV_04; break;
            case DiaType.NOV_04: diaDay = DiaType.NOV_05; break;
            case DiaType.NOV_05: diaDay = DiaType.NOV_06; break;
            case DiaType.NOV_06: diaDay = DiaType.NOV_07; break;
            case DiaType.NOV_07: diaDay = DiaType.NOV_08; break;
            case DiaType.NOV_08: diaDay = DiaType.NOV_09; break;
            case DiaType.NOV_09: diaDay = DiaType.NOV_10; break;
            case DiaType.NOV_10: diaDay = DiaType.NOV_11; break;
            case DiaType.NOV_11: diaDay = DiaType.NOV_12; break;
            case DiaType.NOV_12: diaDay = DiaType.NOV_13; break;
            case DiaType.NOV_13: diaDay = DiaType.NOV_14; break;
            case DiaType.NOV_14: diaDay = DiaType.NOV_15; break;
            case DiaType.NOV_15: diaDay = DiaType.NOV_16; break;
            case DiaType.NOV_16: diaDay = DiaType.NOV_17; break;
            case DiaType.NOV_17: diaDay = DiaType.NOV_18; break;
            case DiaType.NOV_18: diaDay = DiaType.NOV_19; break;
            case DiaType.NOV_19: diaDay = DiaType.NOV_20; break;
            case DiaType.NOV_20: diaDay = DiaType.NOV_21; break;
            case DiaType.NOV_21: diaDay = DiaType.NOV_22; break;
            case DiaType.NOV_22: diaDay = DiaType.NOV_23; break;
            case DiaType.NOV_23: diaDay = DiaType.NOV_24; break;
            case DiaType.NOV_24: diaDay = DiaType.NOV_25; break;
            case DiaType.NOV_25: diaDay = DiaType.NOV_26; break;
            case DiaType.NOV_26: diaDay = DiaType.NOV_27; break;
            case DiaType.NOV_27: diaDay = DiaType.NOV_28; break;
            case DiaType.NOV_28: diaDay = DiaType.NOV_29; break;
            case DiaType.NOV_29: diaDay = DiaType.NOV_30; break;
            case DiaType.NOV_30: diaDay = DiaType.WEEKDAY; break;
        }
    
        updateDisplayDiaDay();
        getTimeTable();
        setNewTime(setSecondSum);
        drawTrain();
        resetTimetableSpace();
    }
    
  5. この changeDiaType関数だと、diaDayがDiaType.SATURDAYとかDiaType.SPECIAL1のときは切り替わらなくなってますよ。switch文のcaseに出てきてませんよね?
    changeDiaType関数かupdateDisplayDiaDay関数の1行目に

    console.log("diaDay = ", diaDay);
    

    って入れて、コンソールを見ればdiaDayがどうなっているか確認できますから、まずそれをやってみてください。


    ちなみに、DiaTypeが最小値から最大値まで1ずつ増えているなら、こんなswitch文で力技でやるより

    const DiaTypeMin = Object.values(DiaType).reduce((a, b) => a < b ? a : b); 
    const DiaTypeMax = Object.values(DiaType).reduce((a, b) => a > b ? a : b);
    diaDay = diaDay === DiaTypeMax ? DiaTypeMin : diaDay + 1;
    

    ってした方が楽ですよ。
    0から始まってる今回のような場合は下記のようにしてもいいですが。

    diaDay = (diaDay + 1) % Object.keys(DiaType).length;
    
  6. @sembokulove

    Questioner

    ご助言ありがとうございます。
    先ほどの
    function isSunday(year, month, day) {ですが、
    案外シンプルに解決しました。
    まずmainのファイルで、以下の関数を実行してあげることと、

    function isSunday(year, month, day) {
      return isHolidayOrSunday(year, month, day); // ← 呼び先を差し替え
    }
    

    これは初出なのですが、
    htmlのほうで、
    従来、mainをdiatypejudgeよりも先に出しておりましたが、
    それを逆にすることにより、
    diatypejudgeで設定したisHolidayOrSunday関数が無駄にならずに済みました。
    しかし、新たな問題が発生しました。
    diatypejudgeで設定したisholidaysですが、新たに追加しようとすると、動かなくなります。
    本日は6月18日は水曜日です。
    平日ダイヤを返すことは正しいのですが、
    ここに新しいholidaysを設置しようとすると、動かないことになります。
    問題のコードをお出しします。

    // DayOfWeek enum
    // holidays 配列: 毎年固定の祝日をここに定義します。
    // 春分の日、秋分の日、天皇誕生日、山の日も固定日付として追加。
    const holidays = [
        { month: 1, date: 1 },  // 元日
        { month: 2, date: 11 }, // 建国記念の日
        { month: 2, date: 23 }, // 天皇誕生日 (現在の天皇誕生日。過去の異なる日付は考慮しない)
        { month: 3, date: 21 }, // 春分の日 (年間の変動を考慮せず固定)
        { month: 4, date: 29 }, // 昭和の日
        { month: 5, date: 3 },  // 憲法記念日
        { month: 5, date: 4 },  // みどりの日
        { month: 5, date: 5 },  // こどもの日
        { month: 8, date: 11 }, // 山の日 (2016年施行だが、ここでは毎年固定として扱う)
        { month: 9, date: 23 }, // 秋分の日 (年間の変動を考慮せず固定)
        { month: 11, date: 3 }, // 文化の日
        { month: 11, date: 23 }, // 勤労感謝の日
        { month: 12, date: 31 }, // 大晦日 (固定の祝日として扱う場合)
    ];
    // Helper function to get the Nth day of a specific day of the week in a month
    function getNthDayOfMonth(year, month, dayOfWeek, n) {
        let count = 0;
        let day = 1;
        let targetDate = null;
        while (true) {
            const dateObj = new Date(year, month - 1, day);
            if (dateObj.getMonth() !== month - 1) { // Stop if month changes
                break;
            }
            if (dateObj.getDay() === dayOfWeek) {
                count++;
                if (count === n) {
                    targetDate = dateObj;
                    break;
                }
            }
            day++;
        }
        if (targetDate) {
            return { year: targetDate.getFullYear(), month: targetDate.getMonth() + 1, date: targetDate.getDate() };
        }
        return null; // Not found
    }
    
    // Function to get dynamically calculated Japanese Holidays for a given year
    // ここでは「第N週の月曜日」の祝日のみを扱います。
    function getJapaneseHolidaysDynamic(year) {
        const dynamicHolidays = [];
    
        // --- Happy Monday Holidays ---
        // Coming-of-Age Day (成人の日 - 1月第2月曜)
        const comingOfAgeDay = getNthDayOfMonth(year, 1, DayOfWeek.MONDAY, 2);
        if (comingOfAgeDay) dynamicHolidays.push(comingOfAgeDay);
    
        // Marine Day (海の日 - 7月第3月曜)
        const marineDay = getNthDayOfMonth(year, 7, DayOfWeek.MONDAY, 3);
        if (marineDay) dynamicHolidays.push(marineDay);
    
        // Respect for the Aged Day (敬老の日 - 9月第3月曜)
        const respectAgedDay = getNthDayOfMonth(year, 9, DayOfWeek.MONDAY, 3);
        if (respectAgedDay) dynamicHolidays.push(respectAgedDay);
    
        // Sports Day (スポーツの日 - 10月第2月曜)
        const sportsDay = getNthDayOfMonth(year, 10, DayOfWeek.MONDAY, 2);
        if (sportsDay) dynamicHolidays.push(sportsDay);
    
        return dynamicHolidays.filter(h => h !== null); // null を除外
    }
    
    
    // Modified isHolidayOrSunday function
    function isHolidayOrSunday(year, month, date) {
        const dateObj = new Date(year, month - 1, date); // month is 0-indexed for Date object
    
        // 1. Check if it's a Sunday
        if (dateObj.getDay() === DayOfWeek.SUNDAY) {
            return true;
        }
    
        // 2. Check against the predefined fixed holidays array (holidays array - year-independent)
        const isFixedHolidayAlways = holidays.some(holiday =>
            holiday.month === month && holiday.date === date
        );
        if (isFixedHolidayAlways) {
            return true;
        }
    
        // 3. Get dynamically calculated holidays for the given year (Happy Monday only)
        const currentYearDynamicHolidays = getJapaneseHolidaysDynamic(year);
        const isDynamicHoliday = currentYearDynamicHolidays.some(holiday =>
            holiday.year === year && holiday.month === month && holiday.date === date
        );
        if (isDynamicHoliday) {
            return true;
        }
    
        // 4. Check for Substitute Holiday (振替休日)
        // Only check if it's a Monday
        if (dateObj.getDay() === DayOfWeek.MONDAY) {
            const previousDay = new Date(year, month - 1, date - 1);
            const previousDayYear = previousDay.getFullYear();
            const previousDayMonth = previousDay.getMonth() + 1;
            const previousDayDate = previousDay.getDate();
    
            if (previousDay.getDay() === DayOfWeek.SUNDAY) {
                // Check if the previous day was a holiday (from either fixed list or dynamic calculation)
                const isPreviousDayFixedHolidayAlways = holidays.some(holiday =>
                    holiday.month === previousDayMonth && holiday.date === previousDayDate
                );
                const isPreviousDayDynamicHoliday = getJapaneseHolidaysDynamic(previousDayYear).some(holiday =>
                    holiday.year === previousDayYear && holiday.month === previousDayMonth && holiday.date === previousDayDate
                );
    
                if (isPreviousDayFixedHolidayAlways || isPreviousDayDynamicHoliday) {
                    return true; // Previous day was a Sunday holiday, so this Monday is a substitute holiday
                }
            }
        }
    
        // 5. Check for Citizen's Holiday (国民の休日 - Kokumin no Kyujitsu)
        // Applies if a weekday falls between two national holidays (excluding Saturday/Sunday/already holiday).
        // This needs to check against ALL holidays (fixed + dynamic).
        // Build a temporary comprehensive list of all holidays for the given year for this check.
        const allHolidaysForYear = [
            ...holidays.map(h => ({ year: year, month: h.month, date: h.date })), // Convert year-independent to year-specific
            ...currentYearDynamicHolidays
        ];
    
        // Ensure we don't apply Citizen's Holiday rule to Saturdays, Sundays, or days already identified as holidays.
        // Also, simplify the cross-year check for simplicity, assuming consecutive holidays generally within same year.
        // For very robust cross-year citizen's holiday like Dec 31 -> Jan 1 with Jan 2 as citizen, more complex logic needed.
        if (dateObj.getDay() !== DayOfWeek.SATURDAY && dateObj.getDay() !== DayOfWeek.SUNDAY && !isFixedHolidayAlways && !isDynamicHoliday) {
            const dayBefore = new Date(year, month - 1, date - 1);
            const dayAfter = new Date(year, month - 1, date + 1);
    
            // Check if the day before and day after are holidays within this year's context.
            // We ensure the year for previous/next day doesn't change significantly, avoiding complex cross-year edge cases for simplicity.
            const isDayBeforeHoliday = (dayBefore.getFullYear() === year || (month === 1 && dayBefore.getFullYear() === year - 1)) && // Allow prev year for Jan
                                        allHolidaysForYear.some(holiday =>
                                            holiday.year === dayBefore.getFullYear() && holiday.month === dayBefore.getMonth() + 1 && holiday.date === dayBefore.getDate()
                                        );
            const isDayAfterHoliday = (dayAfter.getFullYear() === year || (month === 12 && dayAfter.getFullYear() === year + 1)) && // Allow next year for Dec
                                       allHolidaysForYear.some(holiday =>
                                           holiday.year === dayAfter.getFullYear() && holiday.month === dayAfter.getMonth() + 1 && holiday.date === dayAfter.getDate()
                                       );
    
            if (isDayBeforeHoliday && isDayAfterHoliday) {
                return true;
            }
        }
    
        return false; // Not a Sunday, fixed holiday, dynamic holiday, substitute holiday, or citizen's holiday
    }
    
    // dayJudge function remains the same
    function dayJudge(year, month, date, day) { // day は 0:日曜, 1:月曜, ..., 6:土曜
    
        // 2. Prioritize individual date schedules (OCT_XX, NOV_XX, etc.)
        switch (month) {
            case 10: // October processing
                switch (date) {
                    case 1: return DiaType.OCT_01; case 2: return DiaType.OCT_02; case 3: return DiaType.OCT_03;
                    case 4: return DiaType.OCT_04; case 5: return DiaType.OCT_05; case 6: return DiaType.OCT_06;
                    case 7: return DiaType.OCT_07; case 8: return DiaType.OCT_08; case 9: return DiaType.OCT_09;
                    case 10: return DiaType.OCT_10; case 11: return DiaType.OCT_11; case 12: return DiaType.OCT_12;
                    case 13: return DiaType.OCT_13; case 14: return DiaType.OCT_14; case 15: return DiaType.OCT_15;
                    case 16: return DiaType.OCT_16; case 17: return DiaType.OCT_17; case 18: return DiaType.OCT_18;
                    case 19: return DiaType.OCT_19; case 20: return DiaType.OCT_20; case 21: return DiaType.OCT_21;
                    case 22: return DiaType.OCT_22; case 23: return DiaType.OCT_23; case 24: return DiaType.OCT_24;
                    case 25: return DiaType.OCT_25; case 26: return DiaType.OCT_26; case 27: return DiaType.OCT_27;
                    case 28: return DiaType.OCT_28; case 29: return DiaType.OCT_29; case 30: return DiaType.OCT_30;
                    case 31: return DiaType.OCT_31; default: break;
                }
                break;
            case 11: // November processing
                switch (date) {
                    case 1: return DiaType.NOV_01; case 2: return DiaType.NOV_02; case 3: return DiaType.NOV_03;
                    case 4: return DiaType.NOV_04; case 5: return DiaType.NOV_05; case 6: return DiaType.NOV_06;
                    case 7: return DiaType.NOV_07; case 8: return DiaType.NOV_08; case 9: return DiaType.NOV_09;
                    case 10: return DiaType.NOV_10; case 11: return DiaType.NOV_11; case 12: return DiaType.NOV_12;
                    case 13: return DiaType.NOV_13; case 14: return DiaType.NOV_14; case 15: return DiaType.NOV_15;
                    case 16: return DiaType.NOV_16; case 17: return DiaType.NOV_17; case 18: return DiaType.NOV_18;
                    case 19: return DiaType.NOV_19; case 20: return DiaType.NOV_20; case 21: return DiaType.NOV_21;
                    case 22: return DiaType.NOV_22; case 23: return DiaType.NOV_23; case 24: return DiaType.NOV_24;
                    case 25: return DiaType.NOV_25; case 26: return DiaType.NOV_26; case 27: return DiaType.NOV_27;
                    case 28: return DiaType.NOV_28; case 29: return DiaType.NOV_29; case 30: return DiaType.NOV_30;
                    default: break;
                }
                break;
            default:
                break;
        }
    
        // 3. Determine if it's a Sunday or a Holiday (fixed, dynamic, substitute, citizen's)
        if (isHolidayOrSunday(year, month, date)) {
            return DiaType.SUNDAY_HOLIDAY;
        } else if (day === DayOfWeek.SATURDAY) {
            return DiaType.SATURDAY;
        } else { // It's a weekday and not a holiday
            return DiaType.NORMAL_WEEKDAY;
        }
    }
    

    恐らく、const holidays関数以外の個所でエラーが発生しているものと思われます。

Your answer might help someone💌