Fix date handling on train page
This commit is contained in:
parent
c672495a5f
commit
fb540c7a46
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "owlboard-svelte",
|
"name": "owlboard-svelte",
|
||||||
"version": "2024.03.2",
|
"version": "2024.11.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
export const version: string = "2024.11.3";
|
export const version: string = "2024.11.4";
|
||||||
export const versionTag: string = "";
|
export const versionTag: string = "";
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
import toast from "svelte-french-toast";
|
import toast from "svelte-french-toast";
|
||||||
import TimeBar from "$lib/navigation/TimeBar.svelte";
|
import TimeBar from "$lib/navigation/TimeBar.svelte";
|
||||||
import { IconArrowLeft, IconArrowRight, IconCheck } from "@tabler/icons-svelte";
|
import { IconArrowLeft, IconArrowRight, IconCheck } from "@tabler/icons-svelte";
|
||||||
|
import Error from "../+error.svelte";
|
||||||
|
|
||||||
let title = "Timetable Results";
|
let title = "Timetable Results";
|
||||||
let id = "";
|
let id = "";
|
||||||
@ -17,8 +18,7 @@
|
|||||||
let error = false;
|
let error = false;
|
||||||
let errMsg = "";
|
let errMsg = "";
|
||||||
|
|
||||||
let dateInput: Date = new Date();
|
let formattedDate = new Date().toISOString().split('T')[0];
|
||||||
$: formattedDate = dateInput.toISOString().split('T')[0];
|
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -33,13 +33,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function incrementDate() {
|
function incrementDate() {
|
||||||
|
let dateInput = new Date(formattedDate)
|
||||||
dateInput.setDate(dateInput.getDate() + 1);
|
dateInput.setDate(dateInput.getDate() + 1);
|
||||||
dateInput = new Date(dateInput);
|
formattedDate = dateInput.toISOString().split('T')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function decrementDate() {
|
function decrementDate() {
|
||||||
|
let dateInput = new Date(formattedDate)
|
||||||
dateInput.setDate(dateInput.getDate() - 1);
|
dateInput.setDate(dateInput.getDate() - 1);
|
||||||
dateInput = new Date(dateInput);
|
formattedDate = dateInput.toISOString().split('T')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
@ -53,6 +55,16 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
|
error = false;
|
||||||
|
const selectedDate = new Date(formattedDate);
|
||||||
|
const currentDate = new Date();
|
||||||
|
const difference: number = currentDate.getTime() - selectedDate.getTime();
|
||||||
|
const differenceDays: number = difference / (1000 * 60 * 60 * 24)
|
||||||
|
if (differenceDays > 7) {
|
||||||
|
toast.error("Timetable data is not available for dates older than a week")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
toast.promise(
|
toast.promise(
|
||||||
fetchData(id),
|
fetchData(id),
|
||||||
{
|
{
|
||||||
@ -108,7 +120,6 @@
|
|||||||
type="date"
|
type="date"
|
||||||
id="dateInput"
|
id="dateInput"
|
||||||
bind:value={formattedDate}
|
bind:value={formattedDate}
|
||||||
on:input={(e) => dateInput = new Date(e.target.value)}
|
|
||||||
/>
|
/>
|
||||||
<button on:click={incrementDate}><IconArrowRight /></button>
|
<button on:click={incrementDate}><IconArrowRight /></button>
|
||||||
<button on:click={load}><IconCheck /></button>
|
<button on:click={load}><IconCheck /></button>
|
||||||
@ -121,7 +132,7 @@
|
|||||||
|
|
||||||
{#each data as service}
|
{#each data as service}
|
||||||
{#if service}
|
{#if service}
|
||||||
<TrainDetail {service} date={dateInput} />
|
<TrainDetail {service} date={new Date(formattedDate)} />
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
@ -136,15 +147,13 @@
|
|||||||
|
|
||||||
#dateInput {
|
#dateInput {
|
||||||
height: 25px;
|
height: 25px;
|
||||||
transform: translateY(-7px);
|
transform: translateY(-30px);
|
||||||
}
|
|
||||||
#dateSelector {
|
|
||||||
transform: translateY(3px);
|
|
||||||
transform: translateX(20px);
|
transform: translateX(20px);
|
||||||
}
|
}
|
||||||
button {
|
button {
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
color: white;
|
color: white;
|
||||||
|
transform: translateX(20px);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user