Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: fix timezone

Nevo David326c1b60c663
diff --git a/apps/frontend/src/components/layout/set.timezone.tsx b/apps/frontend/src/components/layout/set.timezone.tsx
index 0e406ef9b..e0a3a6043 100644
--- a/apps/frontend/src/components/layout/set.timezone.tsx
+++ b/apps/frontend/src/components/layout/set.timezone.tsx
@@ -6,22 +6,12 @@ import utc from 'dayjs/plugin/utc';
dayjs.extend(timezone);
dayjs.extend(utc);
-const {utc: originalUtc} = dayjs;
-
-dayjs.utc = new Proxy(originalUtc, {
- apply(target, thisArg, args) {
- const result = target.apply(thisArg, args);
-
- // Attach `.local()` method to the returned Dayjs object
- result.local = function () {
- return result.tz(getTimezone());
- };
-
- return result;
- },
-});
+const { utc: originalUtc } = dayjs;
export const getTimezone = () => {
+ if (typeof window === 'undefined') {
+ return dayjs.tz.guess();
+ }
return localStorage.getItem('timezone') || dayjs.tz.guess();
};
@@ -31,6 +21,18 @@ export const newDayjs = (config?: ConfigType) => {
const SetTimezone: FC = () => {
useEffect(() => {
+ dayjs.utc = new Proxy(originalUtc, {
+ apply(target, thisArg, args) {
+ const result = target.apply(thisArg, args);
+
+ // Attach `.local()` method to the returned Dayjs object
+ result.local = function () {
+ return result.tz(getTimezone());
+ };
+
+ return result;
+ },
+ });
if (localStorage.getItem('timezone')) {
dayjs.tz.setDefault(getTimezone());
}