Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send reminders at correct time for users in different timezones?

Tags:

c#

sql

asp.net

I have never created a reminder application. Here is how I see it. Please let me know if I'm on the right way.

So I have users from different timezones.

ID         DateTimeUTC               TimeZoneID            

1          2011-07-12 02:15:15.000   TimeZneID1
2          2011-07-13 16:00:00.000   TimeZneID2
3          2013-11-03 17:00:00.000   TimeZneID3
4          2011-08-22 03:00:00.000   TimeZneID4
5          2011-07-16 22:00:00.000   TimeZneID5

Create a scheduled process to run every 15 mins and do the steps below:

  1. Get records;
  2. The second is to convert DateTimeUTC to Time for the right timezone
  3. Compare if it's match
    a. Send Reminder
    var tzi = TimeZoneInfo.FindSystemTimeZoneById(TimeZneID1);
    var local = TimeZoneInfo.ConvertTimeFromUtc(DateTimeUTC, tzi);
    var timeNow = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now, tzi);
    if(local == timeNow)
    SendReminder();

Is it efficient way? is it the right way?

like image 480
Michael Born Avatar asked Dec 22 '22 11:12

Michael Born


1 Answers

If date/time values are already in UTC in the database, you don't need to perform any conversions, surely... you just need to see whether the current UTC instant is a match, and if so, send the reminder.

That's assuming you really mean it's UTC in the database, i.e. you've converted it from the user's local time when they entered the reminder (assuming they did so to start with).

like image 152
Jon Skeet Avatar answered Dec 24 '22 00:12

Jon Skeet