Create function to adjust for timezone difference between server and the client
[MAILPOET-5495]
This commit is contained in:
committed by
Aschepikov
parent
da190c5d06
commit
6e1462d4f4
@@ -20,6 +20,7 @@ export const MailPoetDate: {
|
|||||||
time: (date: MomentInput) => string;
|
time: (date: MomentInput) => string;
|
||||||
convertFormat: (format: string) => string;
|
convertFormat: (format: string) => string;
|
||||||
isInFuture: (dateString: string, currentTime: MomentInput) => boolean;
|
isInFuture: (dateString: string, currentTime: MomentInput) => boolean;
|
||||||
|
adjustForTimezoneDifference: (date: Date) => Date;
|
||||||
} = {
|
} = {
|
||||||
version: 0.1,
|
version: 0.1,
|
||||||
options: {},
|
options: {},
|
||||||
@@ -181,4 +182,16 @@ export const MailPoetDate: {
|
|||||||
},
|
},
|
||||||
isInFuture: (dateString: string, currentTime: MomentInput): boolean =>
|
isInFuture: (dateString: string, currentTime: MomentInput): boolean =>
|
||||||
Moment(dateString).isAfter(currentTime, 's'),
|
Moment(dateString).isAfter(currentTime, 's'),
|
||||||
|
adjustForTimezoneDifference: function adjustForTimezoneDifference(
|
||||||
|
date: Date,
|
||||||
|
): Date {
|
||||||
|
const serverOffsetMinutes = window.mailpoet_server_timezone_in_minutes || 0;
|
||||||
|
const browserOffsetMinutes = new Date().getTimezoneOffset();
|
||||||
|
const offsetDifference = browserOffsetMinutes - serverOffsetMinutes;
|
||||||
|
if (!offsetDifference) {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
date.setMinutes(date.getMinutes() - offsetDifference);
|
||||||
|
return date;
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
Reference in New Issue
Block a user