Răsfoiți Sursa

Merge branch 'test_zyh' of United_Software/k_online_ui into test

Jack Zhou 7 luni în urmă
părinte
comite
ce108c03a1

+ 3 - 3
src/components/NotificationMessageCard/src/components/EventCard.vue

@@ -160,7 +160,7 @@ const jumpTracking = (data: EventCardPropsData) => {
         <span style="margin-right: 3px">{{
           dayjs(data.info.time).format('MMM DD, YYYY hh:mm')
         }}</span>
-        <span>{{ getTimezone(data.info.timezone) }}</span>
+        <span>{{ getTimezone(data.info.timezone, data.info.time) }}</span>
       </div>
       <!-- <div class="change-time" v-if="data.type === 'change' && data.info?.time">
         <span style="margin-left: 1px" class="font_family icon-icon_time_b"></span>
@@ -170,13 +170,13 @@ const jumpTracking = (data: EventCardPropsData) => {
         <span class="font_family icon-icon_time_b"></span>
         <span style="margin-right: 3px" v-if="data.timeLabel">{{ data.timeLabel }}:</span>
         <span style="margin-right: 3px">{{ dayjs(data.time).format('MMM DD, YYYY hh:mm') }}</span>
-        <span>{{ getTimezone(data.timezone) }}</span>
+        <span>{{ getTimezone(data.timezone, data.time) }}</span>
       </div>
       <div class="previous" v-if="data.previous">
         <span class="previous-icon"></span>
         <span
           >{{ data.previous.tag }}&nbsp;({{ data.previous.time }}
-          {{ getTimezone(data.previous.timezone) }})</span
+          {{ getTimezone(data.previous.timezone, data.previous.time) }})</span
         >
       </div>
     </div>

+ 6 - 4
src/utils/tools.ts

@@ -15,7 +15,8 @@ export const formatTimezone = (time: string, timezone?: string) => {
       return formattedTime
     }
     let utcOffset = ''
-    const timeZoneOffset = moment.tz(`${moment().year()}-01-01`, timezone).format('Z')
+
+    const timeZoneOffset = moment.tz(time, timezone).format('Z')
     // 替换 "+07:00" 为 "UTC+07"
     utcOffset = `(UTC${timeZoneOffset.slice(0, 3)})`
     return `${formattedTime} ${utcOffset}`
@@ -30,9 +31,10 @@ export const formatTimezone = (time: string, timezone?: string) => {
  * @param timezone
  * @returns
  */
-export const getTimezone = (timezone: string): string => {
+export const getTimezone = (timezone: string, time?: string): string => {
   if (!timezone) return ''
-  const offset = moment.tz(`${moment().year()}-01-01`, timezone).format('Z')
+  const computedTime = time ? time : moment(time).format(formatString.value)
+  const offset = moment.tz(computedTime, timezone).format('Z')
   return `UTC${offset.slice(0, 3)}`
 }
 
@@ -42,7 +44,7 @@ export const formatTimezoneByUTCorGMT = (time: string, timezone: string) => {
   formattedTime = moment(time).format(`${formatString.value} hh:mm A`)
   let gmtOffset = ''
   if (timezone != null) {
-    const timeZoneOffset = moment().tz(timezone).format('Z')
+    const timeZoneOffset = moment.tz(time, timezone).format('Z')
     // 替换 "+07:00" 为 "GMT+07"
     if (timezone.includes('Seoul')) {
       gmtOffset = `(UTC${timeZoneOffset.slice(0, 3)})`