- Updated FelicaHistoryPage to use dayjs for formatting scannedAt timestamps. - Refactored ResearchToolsSettings to utilize dayjs for date formatting. - Modified VoicepeakDebugLogSection to replace Date with dayjs for createdAt timestamps. - Changed settings component to use dayjs for scannedAt timestamps. - Updated ExGridSimpleView and ExGridView to use dayjs for time parsing and formatting. - Refactored ExGridSimpleViewItem and ExGridViewItem to utilize dayjs for time formatting. - Adjusted ListView and ListViewItem to use dayjs for time handling. - Updated EachData to use dayjs for train time calculations. - Refactored LED_vidion to remove redundant getServiceMinute function. - Replaced Date with dayjs in trainRecorder for exportedAt timestamps. - Updated appLifecycleCrashSentinel to use dayjs for timestamp handling. - Refactored operationInfoSchedule to use dayjs for fetchedAt timestamp. - Updated trainTimeFiltering to utilize dayjs for time comparisons. - Refactored useWebViewRemount to handle timeouts with dayjs. - Updated voicepeak and voicepeakDebugLog to use dayjs for timestamp handling. - Introduced timeUtils module for consistent time parsing and formatting using dayjs.
91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
import { useState, useEffect } from "react";
|
|
import { useStationList } from "@/stateBox/useStationList";
|
|
import { findReversalPoints } from "@/lib/eachTrainInfoCoreLib/findReversalPoints";
|
|
import { StationProps } from "@/lib/CommonTypes";
|
|
import { trainDataType } from "@/lib/trainPositionTextArray";
|
|
import dayjs from "dayjs";
|
|
import { getServiceTimeDifference } from "@/lib/timeUtils";
|
|
|
|
/**
|
|
* 次駅と着駅を計算するカスタムフック
|
|
* 棒線駅の判定と遅延時間を考慮
|
|
*/
|
|
export const useNextStationCalculator = (
|
|
currentPosition: string[],
|
|
trainDataWithThrough: string[],
|
|
stopStationIDList: string[][],
|
|
train: trainDataType | null
|
|
) => {
|
|
const { getStationDataFromName } = useStationList();
|
|
|
|
const [nextStationData, setNextStationData] = useState<StationProps[]>([]);
|
|
const [untilStationData, setUntilStationData] = useState<string[]>([]);
|
|
const [probably, setProbably] = useState(false);
|
|
|
|
useEffect(() => {
|
|
// 棒線駅判定を入れて、棒線駅なら時間を見て分数がマイナスならcontinue
|
|
const points = findReversalPoints(currentPosition, stopStationIDList);
|
|
if (!points || points.length == 0) return;
|
|
|
|
const searchCountFirst = points.findIndex((d) => d == true);
|
|
const searchCountLast = points.findLastIndex((d) => d == true);
|
|
|
|
const delayTime = train?.delay == "入線" ? 0 : train?.delay || 0;
|
|
let additionalSkipCount = 0;
|
|
|
|
// 次駅を検索
|
|
for (let searchCount = searchCountFirst; searchCount < points.length; searchCount++) {
|
|
const nextPos = trainDataWithThrough[searchCount];
|
|
if (!nextPos) continue;
|
|
|
|
const [station, se, time] = nextPos.split(",");
|
|
|
|
// 始発駅と終着駅が同じ場合
|
|
if (searchCountFirst == searchCountLast) {
|
|
if (se.includes("通")) continue;
|
|
setNextStationData(getStationDataFromName(station));
|
|
break;
|
|
}
|
|
|
|
// 棒線駅判定(時刻がある場合)
|
|
let distanceMinute = 0;
|
|
if (time != "") {
|
|
const now = dayjs();
|
|
distanceMinute = getServiceTimeDifference(now, time, delayTime) ?? -1;
|
|
}
|
|
|
|
// 時間が未来の場合のみ次駅として設定
|
|
if (distanceMinute >= 0) {
|
|
if (!se.includes("通")) {
|
|
setNextStationData(getStationDataFromName(station));
|
|
break;
|
|
}
|
|
} else {
|
|
additionalSkipCount++;
|
|
}
|
|
}
|
|
|
|
// 着駅までのリストを作成
|
|
let trainList = [];
|
|
for (let searchCount = searchCountFirst - 1; searchCount < points.length; searchCount++) {
|
|
trainList.push(trainDataWithThrough[searchCount]);
|
|
}
|
|
|
|
// 通過済み駅をスキップ
|
|
if (additionalSkipCount > 0) {
|
|
trainList = trainList.slice(additionalSkipCount);
|
|
setProbably(true);
|
|
} else {
|
|
setProbably(false);
|
|
}
|
|
|
|
setUntilStationData(trainList);
|
|
}, [currentPosition, trainDataWithThrough, stopStationIDList, train, getStationDataFromName]);
|
|
|
|
return {
|
|
nextStationData,
|
|
untilStationData,
|
|
probably,
|
|
};
|
|
};
|