2

I am looking for a way to obtain a list of timezones in which the current time is a variable (it has to be DST dependant as well).

For example I need to push messages to users for which the local time is 18:45. I can fetch from our database a list of users by timezone. So I plan a scheduled event that would wake up at every 15 minutes, it will need to check in which timezones it is currently 18:45 in order to be able to retrieve the right users.

Our environment is node js. The way I am thinking about is preferably a web service or some utility that does it all for me including the updates from iana timezones database. But I can handle less convenient ways if there's no such alternative.

Thanks in advance.

drorsun
  • 881
  • 1
  • 8
  • 22

1 Answers1

1

Here is one simple way to do it with moment-timezone (I believe it handles things like daylight savings time etc., not 100% sure -- but certainly will do it better than one could do starting from scratch alone.. see their github repo for issues -- its a complex topic):

var moment = require('moment-timezone');
var tm = moment();

var toFind = tm.format('h:mm a');

var userZones = ['America/Los_Angeles', 'America/New_York'];
for (var i=0; i<userZones.length; i++) {
  var fmt = tm.tz(userZones[i]).format('h:mm a');
  if (fmt === toFind) console.log('matched zone: ' + userZones[i]);
}
Jason Livesay
  • 6,317
  • 3
  • 25
  • 31
  • Yes, moment timezone implements the data from the IANA time zone DB, so DST is handled correctly. – Maggie Pint Sep 06 '16 at 04:58
  • Thanks, this was more or less what I did eventually. The annoying part with this was the need to obtain all possible timezones that might be relevant to my users in advance. And I used moment's .isBetween(...) as I needed to check if the time is in the space of 5 minutes. – drorsun Sep 11 '16 at 15:05