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 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) => {
|
||||
|
||||
Reference in New Issue
Block a user