From 7881508a7ba8c618187d63643d687ea94de9a65e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simon=20Pocrnji=C4=8D?=
Date: Tue, 14 Apr 2026 17:41:05 +0200
Subject: [PATCH] Fixed dates
---
app/Http/Controllers/DashboardController.php | 4 ++--
...lter_field_jobs_timestamps_to_datetime.php | 21 ++++++++++++++++++
.../Partials/CompletedFieldJobsTrend.vue | 4 ++--
resources/js/Pages/FieldJob/Index.vue | 12 ++++++----
resources/js/Pages/Phone/Index.vue | 22 +++++++++----------
resources/js/Utilities/functions.js | 12 ++++++----
6 files changed, 52 insertions(+), 23 deletions(-)
create mode 100644 database/migrations/2026_04_14_171538_alter_field_jobs_timestamps_to_datetime.php
diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php
index ec9d766..cf7c2eb 100644
--- a/app/Http/Controllers/DashboardController.php
+++ b/app/Http/Controllers/DashboardController.php
@@ -80,14 +80,14 @@ public function __invoke(SmsService $sms): Response
->map(fn ($i) => now()->subDays(6 - $i)->format('Y-m-d'));
$fieldJobTrendRaw = FieldJob::whereBetween(DB::raw('COALESCE(assigned_at, created_at)'), [$start, $end])
- ->selectRaw('DATE(COALESCE(assigned_at, created_at)) as d, COUNT(*) as c')
+ ->selectRaw("DATE(COALESCE(assigned_at, created_at) AT TIME ZONE 'Europe/Ljubljana') as d, COUNT(*) as c")
->groupBy('d')
->pluck('c', 'd');
// Completed field jobs last 7 days
$fieldJobCompletedRaw = FieldJob::whereNotNull('completed_at')
->whereBetween('completed_at', [$start, $end])
- ->selectRaw('DATE(completed_at) as d, COUNT(*) as c')
+ ->selectRaw("DATE(completed_at AT TIME ZONE 'Europe/Ljubljana') as d, COUNT(*) as c")
->groupBy('d')
->pluck('c', 'd');
diff --git a/database/migrations/2026_04_14_171538_alter_field_jobs_timestamps_to_datetime.php b/database/migrations/2026_04_14_171538_alter_field_jobs_timestamps_to_datetime.php
new file mode 100644
index 0000000..c8f2327
--- /dev/null
+++ b/database/migrations/2026_04_14_171538_alter_field_jobs_timestamps_to_datetime.php
@@ -0,0 +1,21 @@
+ {
}
return props.trends.labels.map((label, i) => ({
- date: new Date(label),
+ date: new Date(label + "T00:00:00"),
dateLabel: label,
completed: props.trends.field_jobs_completed[i] || 0,
assigned: props.trends.field_jobs[i] || 0,
@@ -140,7 +140,7 @@ const crosshairLabelFormatter = (value) => {
type="x"
:tick-line="false"
:grid-line="false"
- :num-ticks="7"
+ :tick-values="chartData.map((d) => d.date)"
:tick-format="
(d) => {
const date = new Date(d);
diff --git a/resources/js/Pages/FieldJob/Index.vue b/resources/js/Pages/FieldJob/Index.vue
index e5cb0c0..ca7d704 100644
--- a/resources/js/Pages/FieldJob/Index.vue
+++ b/resources/js/Pages/FieldJob/Index.vue
@@ -263,10 +263,14 @@ function formatDate(value) {
if (isNaN(d)) {
return value;
}
- const dd = String(d.getDate()).padStart(2, "0");
- const mm = String(d.getMonth() + 1).padStart(2, "0");
- const yyyy = d.getFullYear();
- return `${dd}.${mm}.${yyyy}`;
+ const parts = new Intl.DateTimeFormat("en-GB", {
+ timeZone: "Europe/Ljubljana",
+ day: "2-digit",
+ month: "2-digit",
+ year: "numeric",
+ }).formatToParts(d);
+ const map = Object.fromEntries(parts.map((p) => [p.type, p.value]));
+ return `${map.day}.${map.month}.${map.year}`;
}
function formatCurrencyEUR(value) {
diff --git a/resources/js/Pages/Phone/Index.vue b/resources/js/Pages/Phone/Index.vue
index 783afec..1e01dbf 100644
--- a/resources/js/Pages/Phone/Index.vue
+++ b/resources/js/Pages/Phone/Index.vue
@@ -30,6 +30,7 @@ import {
Phone,
Wallet,
} from "lucide-vue-next";
+import { fmtDateDMY } from "@/Utilities/functions";
const props = defineProps({
jobs: { type: Object, required: true },
@@ -89,17 +90,16 @@ function clearSearch() {
function formatDateDMY(d) {
if (!d) return "-";
- if (/^\d{4}-\d{2}-\d{2}/.test(d)) {
- const [y, m, rest] = d.split("-");
- const day = (rest || "").slice(0, 2) || "01";
- return `${day}.${m}.${y}`;
- }
const dt = new Date(d);
if (Number.isNaN(dt.getTime())) return String(d);
- const dd = String(dt.getDate()).padStart(2, "0");
- const mm = String(dt.getMonth() + 1).padStart(2, "0");
- const yyyy = dt.getFullYear();
- return `${dd}.${mm}.${yyyy}`;
+ const parts = new Intl.DateTimeFormat("en-GB", {
+ timeZone: "Europe/Ljubljana",
+ day: "2-digit",
+ month: "2-digit",
+ year: "numeric",
+ }).formatToParts(dt);
+ const map = Object.fromEntries(parts.map((p) => [p.type, p.value]));
+ return `${map.day}.${map.month}.${map.year}`;
}
function formatAmount(val) {
@@ -412,7 +412,7 @@ function changePage(url) {
Dodeljeno
- {{ formatDateDMY(job.assigned_at) }}
+ {{ fmtDateDMY(job.assigned_at) }}
@@ -430,7 +430,7 @@ function changePage(url) {
Zadnja aktivnost
- {{ formatDateDMY(job.last_activity) || "—" }}
+ {{ fmtDateDMY(job.last_activity) || "—" }}
diff --git a/resources/js/Utilities/functions.js b/resources/js/Utilities/functions.js
index e0efa4f..85561c5 100644
--- a/resources/js/Utilities/functions.js
+++ b/resources/js/Utilities/functions.js
@@ -33,8 +33,12 @@ export function fmtDateDMY(value) {
if (!value) return "-";
const d = new Date(value);
if (isNaN(d)) return "-";
- const dd = String(d.getDate()).padStart(2, "0");
- const mm = String(d.getMonth() + 1).padStart(2, "0");
- const yyyy = d.getFullYear();
- return `${dd}.${mm}.${yyyy}`;
+ const parts = new Intl.DateTimeFormat("en-GB", {
+ timeZone: "Europe/Ljubljana",
+ day: "2-digit",
+ month: "2-digit",
+ year: "numeric",
+ }).formatToParts(d);
+ const map = Object.fromEntries(parts.map((p) => [p.type, p.value]));
+ return `${map.day}.${map.month}.${map.year}`;
}
\ No newline at end of file