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