简体   繁体   中英

How to handle user's data stored in the database if user's timezone changes using PHP

If a user sets a reminder notification time exactly at 8 AM , he should get the notification exactly at 8 AM even after he moved to a different timezone .

I mean if he moved to any other country with different timezone even after that he should get the notification exactly at 8 AM on the morning of that country.

To send notifications, I'm using CRON which is running in UTC timezon e.

Consider this example, user's reminder time is 8 AM in IST (+5:30) , I'm storing 2:30 in UTC into the database. But what if he moved to EDT (-4:00) timezone area? But also I have a huge amount of data of the user.

Please suggest the solution considering that I have to perform that operation using PHP and the database is MySQL .

I would perform all my notifying operations on the server via CRON . Lets imagine a simple example:

1) You live in a Country A which has a GMT+3 timezone. It is now 14:00 GMT+3 . You have a meeting in Country B which is under GMT+1 .

2) Your meeting in this country is at 16:00 GMT+1 or 18:00 GMT+3 . So 4 more hours until the meeting.

3) You set up an appointment in your application for a meeting in 18:00 GMT+3 . All appointments in your server are saved as GMT+0 , thus this appointment is saved as 15:00 GMT+0 .

4) Let us imagine you teleport to the country of the meeting and the time is now 12:00 GMT+1 . After 4 hours have passed ( 16:00 GMT+1, 18:00 GMT+3, 15:00 GMT+0 ), you will still be notified by the server, regardless of your change in timezone. Since the server will have your appointment saved as GMT+0 and will be checking with a CRON job every, lets say 5 minutes`, if someone's appointment is due.

On the other hand, if you wanna perform the check on the client, you should always transform the client's datetime to whatever format is saved on the server and check with the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM