0

I have a database of different users from different countries who had registered in our application. There might be the users having friends in different countries.

Say, there are 3 users A, B,C. A is in India, B is in San Francisco and C is in Italy and A, B, C all three are friends.

A's birthday is on 29/08/2014. So, on 29/08/2014 at 12:00:00 AM (A's time zone), i need to send B & C the A's birthday notification via server with respect to A's time zone.

In case if i had chosen to run a scheduler everyday at 12:00:00 AM server time, it might not be the same as A's time zone. It might be few minutes before or after the A's time zone. But i need to send the notification only at A's time zone.

I need to achieve this functionality. I would be very glad if someone can please help me.

Please help me in achieving this functionality

  • 1
    You didn't add what you had tried so far, but this may help with your thinking http://stackoverflow.com/questions/4331189/datetime-vs-datetimeoffset – Joe Aug 28 '14 at 11:44
  • My suggestion: convert everything to UTC and save the user's location, then use the schedule based on UTC and convert back to user's time zone. – Gustavo F Aug 28 '14 at 11:44

3 Answers3

0

save the birthday with time means if the a's birthday is at 1/1/89 then for the server his birthday may be 1/1/89 3:00PM according to server time then run the notification sender code after every 10 minuts so, that if user's birthday is occurred the message should be sent.

in the database birthdays would be like this according to server time. 1/1/89 2:00 PM 2/5/90 12: AM 6/7/92 02: AM etc. the notification sender will be continuously checking when event occurs it will send message as required.

Zeshan Khan
  • 294
  • 2
  • 15
  • is it helpful for you or you require anything else? – Zeshan Khan Aug 28 '14 at 12:20
  • But the requirement is as, if the birthday is on 1/1/89, then in database it can be saved as you mentioned like 1/1/89 . But i need to send the notifications on 1/1/89 at 12:00:00 AM with respect to user time zone...Lets say i am in India and my time is 6:00:00 PM... but our server time is 12:24:00 PM. As you said,if my birthday is on 29/08/2014, in database it will be saved as 29/08/2014 12:24 PM and when running a scheduler for every 10 mins, i will be sending the notifications on 29/08/2014 at 12:24 PM which is equal to my Indian time 6:00:00 PM. – Ravinder Reddy Gujjula Aug 28 '14 at 12:25
  • But the case is the notifications should be delivered on 29/08/2014 at 12:00:00 AM my Indian time...So this is the requirement i am looking for. So can you please suggest any other ways... Thanks – Ravinder Reddy Gujjula Aug 28 '14 at 12:28
  • But the time for your birthday would be saved according to your time zone. if the time is 6PM then the server will save your date of birth 29/08/2014 06:24PM or 28/08/2014 (according to the time zone) so that you will recieve the notification at 12:00 AM. – Zeshan Khan Aug 28 '14 at 12:31
  • Actually my time on my lappy is 6:05 PM and on my server it is 12:36 PM..so as you initially said, in database we will be saving as which will be saved as 29/08/2014 12:36 PM in database. which has nearly 6.5 hours difference. So, i am not able to get what you said that " if the time is 6PM then the server will save your date of birth 29/08/2014 06:24PM or 28/08/2014 (according to the time zone) ". So, can you be more clear please. – Ravinder Reddy Gujjula Aug 28 '14 at 12:40
  • No we will save like for your country 06:30 PM and date-1 – Zeshan Khan Aug 28 '14 at 12:43
  • Thanks for the response we will try this and will get back to u ...thanks again – Ravinder Reddy Gujjula Aug 28 '14 at 12:49
0

an idea:

  • in databases, dont store full b'days. just the date part. or store 00:00:00 in time part.
  • for each user store his timezone. you can infer this from other information like current-city or nation.
  • set your scheduler to run every hour. not every day.
  • every time the scheduler runs, fetch the list of eligible user. these will be the users who's b'dy is within one hour of his current time.
  • an user's current time can be calculated as current UTC time plus timezone.
  • the calculation and search can be made in one SQL, exact sql statement will depend on Oracle/MySQl/SQlServer.
  • most databases have methods to fetch current UTC time.
  • do note that this mechanism has a maximum error or 1-hour. but with happy-b'dy mail, this is not much of a problem.
  • also note that there are cities and countries where the timezone is not constant. for india it is connstant +5 1/2 but for US cities, it varies throughout the year. so your solution will not be perfect anyway.
inquisitive
  • 3,549
  • 2
  • 21
  • 47
0

It's really easy to do it. Please follow the below steps

  1. Create a scheduler that runs every 24 hour
  2. Use AWS Step function / Azure logical apps
  3. Create a lambda function that will read all the unique user timezones and generate a Waiting message based on the 12:00:00 AM (The AWS step function will process the message only when the waiting time is met)
  4. Invoke your API service (with input as 'UserTimeZone') then collect all the users having the specified 'UserTimeZone' and send birthday notifications. Please find the attached screenshot for your reference and the sample flow I created. sample work flow