BENderIsGr8te's avatar

Automatic Timezone detection and mutating

Hello All,

I have been working on a way to Automatically detect my users timezone so that I can display all date/times in their current timezone....most specifically when it comes to the diffForHumans() function on Carbon (which Moment.js can't compensate for).

I quickly realized that simply detecting wasn't going to help me. So I made a full fledged solution that detects, sets a cookie that the app can see to mutate dates out of the database from whatever the timezone of the database is to the current users timezone, then mutates back to the database timezone before persisting.

It does require some Javascript. But if anybody has been looking for something like this feel free to test it out. I have it running on two apps and so far so good. However, both apps are relatively low traffic so it really hasn't been tested hard.

Also, this is my first time sharing code in the community, so if you see any glaring mistakes please be gentle.

Otherwise, enjoy! https://github.com/eckenroed/LaravelTimezone

0 likes
0 replies

Please or to participate in this conversation.