feat: better performance for timezone

This commit is contained in:
Nevo David 2025-08-07 21:31:15 +07:00
parent 9e87928045
commit d5979ed6c8
1 changed files with 8 additions and 10 deletions

View File

@ -21,18 +21,16 @@ export const newDayjs = (config?: ConfigType) => {
const SetTimezone: FC = () => {
useEffect(() => {
dayjs.utc = new Proxy(originalUtc, {
apply(target, thisArg, args) {
const result = target.apply(thisArg, args);
dayjs.utc = (config?: ConfigType, format?: string, strict?: boolean) => {
const result = originalUtc(config, format, strict);
// Attach `.local()` method to the returned Dayjs object
result.local = function () {
return result.tz(getTimezone());
};
// Attach `.local()` method to the returned Dayjs object
result.local = function () {
return result.tz(getTimezone());
};
return result;
},
});
return result;
};
if (localStorage.getItem('timezone')) {
dayjs.tz.setDefault(getTimezone());
}