0

I have a list of locations. Here are example locations:

Los Angeles, California
London, United Kingdom
New York, New York
Calgary, Alberta
Toronto, Ontario
Sydney, Australia
Phoenix, Arizona
Chicago, Illinois
Las Vegas, Nevada
Miami, Florida
Mexico City, Mexico
Houston, Texas
San Diego, California
Manchester, United Kingdom
San Antonio, Texas
Atlanta, Georgia
Dallas, Texas
Brisbane, Queensland, Australia
Montreal, Quebec
Orlando, Florida
Edmonton, Alberta
Manila, Philippines
Paris, France
Melbourne, Victoria, Australia
Nashville, Tennessee
Minneapolis, Minnesota
Perth, Western Australia
Brooklyn, New York
Columbus, Ohio
Seattle, Washington

What I need is the closest/best matching PHP timezone.

I'm currently using a set of regular expressions:

  $location_pregs = array(
    "'.*(California|Nevada)'si" => "America/Los_Angeles",
    "'.*United Kingdom'si" => "Europe/London",
    "'.*New York'si" => "America/New_York",
    "'.*Alberta'si" => "America/Edmonton",
    "'.*Ontario'si" => "America/Toronto",
    "'Sydney, Australia'si" => "Australia/Sydney",
    "'.*Arizona'si" => "America/Phoenix",
    "'.*Illinois'si" => "America/Chicago",
    "'.*Mexico'si" => "America/Mexico_City",
    "'(El Paso, Texas|.*Colorado)'si" => "America/Denver"
  );
  function getTimezoneAt ($location) {
    global $location_pregs;
    foreach ($location_pregs as $pn => $pc) {
      if (preg_match($pn, $location)) {
        return $pc;
      }
    }
    return false;
  }

The code above presently covers 27.157% of the locations I need to look up (factoring for popularity). I'd like to get that to 80% with minimal effort. I'm running into trouble in some places:

  • Miami, Florida. As far as I can tell, the closest relevant timezone is 'America/New_York'. But how can I be sure?

  • Houston, Texas. As far as I can tell, this should be 'America/Denver'. But again, how can I tell quickly if this is right?

What I need it a map of the PHP timezones and the geographic areas they cover so I can map the remaining location values quickly. I generally know the timezone in an area, however I do not know which PHP timezone to pick.

azoundria
  • 940
  • 1
  • 8
  • 24
  • 1
    This is really hard to read. Remember, try and keep it short and concise. – Derek Pollard Feb 12 '16 at 15:54
  • Maybe even try and give some mock code and explain what you ultimately want it to give you – Derek Pollard Feb 12 '16 at 15:55
  • 2
    Have you looked at ( and possibly discounted ) the google Timezone API? https://developers.google.com/maps/documentation/timezone/intro ( requires a lat/lng rather than city ) or perhaps https://timezonedb.com/ – Professor Abronsius Feb 12 '16 at 15:57
  • This is the typical question that when answered spoils owns reputation due to the bad questioning. – digitai Feb 12 '16 at 16:03
  • Majorly rewrote the question to highlight the real issue, which is getting the best PHP timezone name, which is the closest city in PHP's list with a matching timezone year-round. – azoundria Feb 12 '16 at 16:42
  • I think I know what I specifically need. It's a full city/area for each of the timezones in that PHP list. For example, if I just search 'Creston' in, for example Map Customizer, it comes up with 'Creston, North Carolina'. How could I know that this is Creston, BC, and ideally the full geographic area which matches this zone? Ideally a master list with this information without having to do a separate search on each zone. – azoundria Feb 12 '16 at 17:18
  • How closely does the PHP timezone list map to the IANA list? Are they equivalent? In which case I found a really handy map here if it only had labels: https://upload.wikimedia.org/wikipedia/commons/8/88/Tz_world_mp-color.svg – azoundria Feb 12 '16 at 17:31

0 Answers0