🐛 Fix time zone conversion for dst dates (#895)

This commit is contained in:
Luke Vella 2023-10-02 19:20:26 +03:00 committed by GitHub
parent 557612b9b3
commit fc87ac9cf1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 18 deletions

View file

@ -39,7 +39,7 @@
"cmdk": "^0.2.0",
"color-hash": "^2.0.2",
"crypto": "^1.0.1",
"dayjs": "^1.11.8",
"dayjs": "^1.11.10",
"i18next": "^22.4.9",
"i18next-icu": "^2.3.0",
"ics": "^3.1.0",

View file

@ -104,24 +104,20 @@ export const parseTimeSlotOption = (
targetTimeZone: string,
timeFormat: TimeFormat,
): ParsedTimeSlotOption => {
const adjustTimeZone = (date: Date | dayjs.Dayjs) => {
const d = dayjs(date).utc();
const adjustTimeZone = (date: string) => {
if (!timeZone) {
return d;
return dayjs(date);
}
const t = d.tz(timeZone, true);
if (targetTimeZone !== timeZone) {
return t.tz(targetTimeZone);
} else {
return t;
}
return dayjs.tz(date, timeZone).tz(targetTimeZone);
};
const startDate = adjustTimeZone(option.start);
const start = dayjs(option.start).utc().format("YYYY-MM-DD HH:mm");
const startDate = adjustTimeZone(start);
const endDate = adjustTimeZone(
dayjs(option.start).add(option.duration, "minute"),
dayjs(start).add(option.duration, "minute").format("YYYY-MM-DD HH:mm"),
);
return {

View file

@ -5242,16 +5242,16 @@ date-arithmetic@^4.1.0:
resolved "https://registry.npmjs.org/date-arithmetic/-/date-arithmetic-4.1.0.tgz"
integrity sha512-QWxYLR5P/6GStZcdem+V1xoto6DMadYWpMXU82ES3/RfR3Wdwr3D0+be7mgOJ+Ov0G9D5Dmb9T17sNLQYj9XOg==
dayjs@^1.11.10:
version "1.11.10"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.10.tgz#68acea85317a6e164457d6d6947564029a6a16a0"
integrity sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==
dayjs@^1.11.7:
version "1.11.7"
resolved "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz"
integrity sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==
dayjs@^1.11.8:
version "1.11.8"
resolved "https://registry.npmjs.org/dayjs/-/dayjs-1.11.8.tgz"
integrity sha512-LcgxzFoWMEPO7ggRv1Y2N31hUf2R0Vj7fuy/m+Bg1K8rr+KAs1AEy4y9jd5DXe8pbHgX+srkHNS7TH6Q6ZhYeQ==
debug@4, debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz"