fix: improve time extraction by utilizing dayjs for ISO timestamp formatting
This commit is contained in:
@@ -2,6 +2,10 @@ import { useEffect, useState } from 'react';
|
|||||||
import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider } from 'antd';
|
import { Modal, Input, Typography, Switch, Button, ConfigProvider, Divider } from 'antd';
|
||||||
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
|
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
|
||||||
import { createShift, updateShift } from '../../../../api/master-shift';
|
import { createShift, updateShift } from '../../../../api/master-shift';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import utc from 'dayjs/plugin/utc';
|
||||||
|
|
||||||
|
dayjs.extend(utc);
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
@@ -198,16 +202,13 @@ const DetailShift = (props) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function to extract time from ISO timestamp
|
// Helper function to extract time from ISO timestamp using dayjs
|
||||||
const extractTime = (timeString) => {
|
const extractTime = (timeString) => {
|
||||||
if (!timeString) return '';
|
if (!timeString) return '';
|
||||||
|
|
||||||
// If it's ISO timestamp like "1970-01-01T08:00:00.000Z"
|
// If it's ISO timestamp like "1970-01-01T08:00:00.000Z"
|
||||||
if (timeString.includes('T')) {
|
if (timeString.includes('T')) {
|
||||||
const date = new Date(timeString);
|
return dayjs.utc(timeString).format('HH:mm');
|
||||||
const hours = String(date.getUTCHours()).padStart(2, '0');
|
|
||||||
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
|
|
||||||
return `${hours}:${minutes}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's already in HH:mm:ss format, remove seconds
|
// If it's already in HH:mm:ss format, remove seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user