1

So to clarify why I want to do this: I need to send push notifications to users when it's 7pm in their timezone.

For each registered device, I have a timezone string, like "Europe/Paris".

I'm creating a background job which will run every hour. It should fetch the list of users for which it's 7pm, and send them a notification.

So the question I'd like to answer is:

"Where in the world is it 7pm now"

Edit The important thing is to get the timezone, even if it's not formatted like "Europe/Paris", I can do that conversion manually with an array.

Julien
  • 9,312
  • 10
  • 63
  • 86

2 Answers2

0

There may be an easier way to do this, but have a database of users, who have a timezone. Then have a hour difference between your notification server, and that time zone. So your server is in pacific time, and the timezone is eastern, it will have a difference of 3.

Use the difference of the time you want, and what it is on your server, to determine the timezone. You want 16:xx it is 13:xx you get +3 hour difference, use that to look up the time zone, then push to all users associated with that time zone.

There may be an easier way, but that way is real simple solution with a db and a little sql knowledge.

EDIT: Also if you dont mind the time delay of using a web api, you should check this out: https://developers.google.com/maps/documentation/timezone/

Whoops numbers were off with the time-zones, Thanks Trent

Mr. MonoChrome
  • 1,383
  • 3
  • 17
  • 39
0

There's no built-in support in Javascript for converting the "standard" timezone names (e.g. Europe/London) to timezone offsets.

You mention push notifications so that suggests you're not running in a browser. If you're using Node.js there's a good library I've used called timezone which uses a local set of timezone spec files to handle conversion between timezones.

Note that timezone specs do sometimes change, for example when a national government decides with little notice that they're not doing daylight savings this year. It's vital that your local mappings are kept up to date accordingly.

Alnitak
  • 334,560
  • 70
  • 407
  • 495