From 039b57efe7a2409aac5bf81cd1f71f1315b087be Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 7 Jul 2023 11:15:49 +0100 Subject: [PATCH] More work on staff version --- .eslintrc.cjs | 32 +++++++++++-------- src/lib/ldb/staff-ldb.svelte | 59 +++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 27 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 29c1d31..7c78d82 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,14 +1,22 @@ module.exports = { - root: true, - extends: ['eslint:recommended', 'plugin:svelte/recommended', 'prettier'], - parserOptions: { - sourceType: 'module', - ecmaVersion: 2020, - extraFileExtensions: ['.svelte'] - }, - env: { - browser: true, - es2017: true, - node: true - } + root: true, + extends: ['eslint:recommended', 'plugin:svelte/recommended', 'prettier'], + overrides: [ + { + "files": ["**/*.svelte"] + } + ], + parserOptions: { + sourceType: 'module', + ecmaVersion: 2020, + extraFileExtensions: ['.svelte'] + }, + env: { + browser: true, + es2017: true, + node: true + }, + rules: { + indent: ['error', 2, {SwitchCase: 2}], + } }; diff --git a/src/lib/ldb/staff-ldb.svelte b/src/lib/ldb/staff-ldb.svelte index 1dfeb66..562d72a 100644 --- a/src/lib/ldb/staff-ldb.svelte +++ b/src/lib/ldb/staff-ldb.svelte @@ -72,7 +72,7 @@ from: await parseLocation(service.origin), to: await parseLocation(service.destination), length: await getTrainLength(service), - platform: await parsePlatform(service?.platform), + platform: await parsePlatform(service?.platform || "undefined"), platformHidden: service?.platformIsHidden === "true", schArr: timeDetails.schArr, expArr: timeDetails.expArr, @@ -115,12 +115,14 @@ } async function parsePlatform(platform) { - if (platform === "TBC") { + if (!platform) { + return '-' + } + if (platform === "TBC" || platform == "undefined") { return '-' } return { - number: platform, - isHidden: false // Not Implemented + number: platform } } @@ -129,23 +131,50 @@ let expArr = new Date(service?.eta || service?.ata); let schDep = new Date(service?.std); let expDep = new Date(service?.etd || service?.atd); - let isEarlyArr = false, isDelayedArr = false - let isEarlyDep = false, isDelayedDep = false - if (expArr < schArr) { + let isEarlyArr = false, isDelayedArr = false, isArr = false + let isEarlyDep = false, isDelayedDep = false, isDep = false + const timeDifferenceThreshold = 60 * 1000; // 60 seconds in milliseconds + if (expArr - schArr < -timeDifferenceThreshold) { isEarlyArr = true; - } else if (expArr > schArr) { - isDelayedArr = true; // Only if the delay is more than 60 seconds. + isArr = true; + } else if (expArr - schArr > timeDifferenceThreshold) { + isDelayedArr = true; + isArr = true; } - if (expDep < schDep) { - isEarlyDep = true; // Only if the delay is more than 60 seconds. - } else if (expDep > schDep) { + + if (expDep - schDep < -timeDifferenceThreshold) { + isEarlyDep = true; + isDep = true; + } else if (expDep - schDep > timeDifferenceThreshold) { isDelayedDep = true; + isDep = true; } + let parsedExpArr; +if (expArr instanceof Date && !isNaN(expArr)) { + if (!isEarlyArr && !isDelayedArr) { + parsedExpArr = 'RT'; + } else { + parsedExpArr = parseIndividualTime(expArr); + } +} else { + parsedExpArr = '-'; +} + +let parsedExpDep; +if (expDep instanceof Date && !isNaN(expDep)) { + if (!isEarlyDep && !isDelayedDep) { + parsedExpDep = 'RT'; + } else { + parsedExpDep = parseIndividualTime(expDep); + } +} else { + parsedExpDep = '-'; +} return { schArr: parseIndividualTime(schArr), - expArr: parseIndividualTime(expArr), + expArr: parsedExpArr, schDep: parseIndividualTime(schDep), - expDep: parseIndividualTime(expDep), + expDep: parsedExpDep, earArr: isEarlyArr, delArr: isDelayedArr, earDep: isEarlyDep, @@ -216,7 +245,7 @@ {service.trainid} {serviceStats.from} {serviceStats.to} - {serviceStats.platform.number} + {serviceStats.platform.number || '-'} {serviceStats.schArr} {serviceStats.isArrDelayed ? 'LATE' : serviceStats.expArr} {serviceStats.schDep}