fix: errors for positive time zones (#961)

This commit is contained in:
Raymond Zhou
2024-04-24 09:07:15 -07:00
committed by GitHub
parent e55f031c39
commit bef6796da4

View File

@@ -267,24 +267,7 @@ export const convertToDateFromString = (dateStr) => {
const stripTimeZone = (stringValue) => stringValue.substring(0, 19);
const differenceDueToDST = (date) => {
const isNowDST = moment(new Date()).isDST();
const isDateDST = moment(date).isDST();
if (isNowDST && !isDateDST) {
return 1;
}
if (!isNowDST && isDateDST) {
return -1;
}
return 0;
};
const timeZoneOffset = new Date().getTimezoneOffset();
const timeZoneHours = (Math.abs(timeZoneOffset) / 60) + differenceDueToDST(moment(dateStr));
const sign = timeZoneOffset < 0 ? '+' : '-';
const timeZone = `${sign}${String(timeZoneHours).padStart(2, '0')}00`;
return moment(stripTimeZone(String(dateStr)) + timeZone).toDate();
return moment(stripTimeZone(String(dateStr))).toDate();
};
export const convertToStringFromDate = (date) => {