fix: timezone-related issue causing one hour less in date picker (#6359)

* fix: timezone-related issue causing one hour less in date picker

* fix: bug

* fix: build error
This commit is contained in:
Katherine 2025-03-06 18:16:08 +08:00 committed by GitHub
parent 24637d2e5f
commit f856b17f02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -82,6 +82,8 @@ const handleChangeOnFilter = (value, picker, showTime) => {
return value;
};
export const handleDateChangeOnForm = (value, dateOnly, utc, picker, showTime, gmt) => {
// @ts-ignore
const currentTimeZone = dayjs.tz.guess();
const format = showTime ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD';
if (!value) {
return value;
@ -97,7 +99,8 @@ export const handleDateChangeOnForm = (value, dateOnly, utc, picker, showTime, g
return dayjs(value).startOf(picker).toISOString();
}
const formattedDate = dayjs(value).format(format);
return dayjs(formattedDate).toISOString();
// @ts-ignore
return dayjs(formattedDate).tz(currentTimeZone, true).toISOString();
}
if (showTime) {
return dayjs(value).format(format);

View File

@ -81,7 +81,7 @@ const toMoment = (val: any, options?: Str2momentOptions) => {
if (!val) {
return;
}
const offset = options.utcOffset !== undefined ? options.utcOffset : -1 * new Date().getTimezoneOffset();
const offset = options.utcOffset;
const { gmt, picker, utc = true } = options;
if (dayjs(val).isValid()) {
if (!utc) {
@ -94,7 +94,7 @@ const toMoment = (val: any, options?: Str2momentOptions) => {
if (gmt) {
return dayjs(val).utcOffset(0);
}
return dayjs(val).utcOffset(offsetFromString(offset));
return offset ? dayjs(val).utcOffset(offsetFromString(offset)) : dayjs(val);
} else {
return convertQuarterToFirstDay(val);
}