From 77003a34530242ae84a0deb9f7a42e91ddaa9c3d Mon Sep 17 00:00:00 2001
From: Arth <65160206@go.buu.ac.th>
Date: Fri, 28 Mar 2025 09:23:40 +0700
Subject: [PATCH] fix date localhost

---
 src/components/GanttChart/GanttChart.vue | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/components/GanttChart/GanttChart.vue b/src/components/GanttChart/GanttChart.vue
index 077ad56..cd5b092 100644
--- a/src/components/GanttChart/GanttChart.vue
+++ b/src/components/GanttChart/GanttChart.vue
@@ -220,12 +220,23 @@ function clearOriginalMaps() {
 
 function convertToLocalTime(utcString: string): string {
   const d = new Date(utcString)
-  const iso = d.toISOString()
-  // 🟢 คืนแบบไม่แปลง timezone (แค่ตัดเวลาให้ format สวย)
-  return iso.slice(0, 16).replace('T', ' ')
+
+  const isLocalhost = ['localhost', '127.0.0.1'].includes(window.location.hostname)
+
+  if (isLocalhost) {
+    // 🟢 แปลงเป็น local time (Asia/Bangkok)
+    d.setHours(d.getHours() + 7) // ปรับ +7 ชั่วโมง
+    const iso = d.toISOString()
+    return iso.slice(0, 16).replace('T', ' ')
+  } else {
+    // 🔵 Prod → ไม่แปลง timezone, แค่ format สวย ๆ
+    const iso = d.toISOString()
+    return iso.slice(0, 16).replace('T', ' ')
+  }
 }
 
 
+
 // Pagination & Dialog
 const pages = computed(() => pageStore.pages.map((p) => p.pagenum))
 const pageToShowDelete = ref<number | null>(null)
-- 
GitLab