fix: errors for positive time zones (#961)
This commit is contained in:
19
src/utils.js
19
src/utils.js
@@ -267,24 +267,7 @@ export const convertToDateFromString = (dateStr) => {
|
|||||||
|
|
||||||
const stripTimeZone = (stringValue) => stringValue.substring(0, 19);
|
const stripTimeZone = (stringValue) => stringValue.substring(0, 19);
|
||||||
|
|
||||||
const differenceDueToDST = (date) => {
|
return moment(stripTimeZone(String(dateStr))).toDate();
|
||||||
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();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const convertToStringFromDate = (date) => {
|
export const convertToStringFromDate = (date) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user