Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unbiased Time System C#

Tags:

c#

time

client

zone

I am creating a reminder system for the software that we have. Currently I have the user give me the time they would like to be reminded and I store it in a database.

Then later, I have a service that periodically checks the database for reminder times. If the reminder time matches the server time, the system sends an email to the user.

I just now realized that this may not work because of time zone differences.

My question, what is the best way to handle time differences in the server and the client, so that the reminder is accurate?

For example..... our server is set for central time at say 6:00pm...... The user who is on the east coast wants a reminder at 7:00pm... this means my server would need to send the reminder at 6:00pm server time.

I hope the question is clear.

like image 265
DJ Burb Avatar asked Feb 22 '23 17:02

DJ Burb


2 Answers

I suggest handling everything in UTC internally, and having the client software do the region-specific translation. Then you can support any arbitrary time zone, and if you ever have to move the server elsewhere or your service gets popular enough to be multihomed, you are still OK.

like image 160
djdanlib Avatar answered Mar 03 '23 20:03

djdanlib


Store everything in universal time and update your clients based off that conversion.

So simply put, instead of having your clients send you a request for 6:00 EST, have them first calculate the conversion between EST and UTC and send you the UTC instead.

like image 43
George Johnston Avatar answered Mar 03 '23 20:03

George Johnston