JSFiddle - React, Tailwind, and code Playground

by pellepim

HTML

<h1>Automatic Timezone Detection Using JavaScript</h3>
<p class="info">This script is open source and hosted as <a href="https://bitbucket.org/pellepim/jstimezonedetect"/>jsTimezoneDetect @ Bitbucket</a>.</p>
<div id="content">
<p id="tz_info"></p>
</div>
<h3>How do I test this script?</h3>
<p class="instructions">To test the detection script, simply change your system timezone and refresh this page. In Chrome you will have to open a new tab for the new timezone to be detected, and Safari needs to be restarted (unfortunately nothing that JavaScript can solve).</p>
<h3>What is the Olson Database?</h3>
<p class="instructions">The Olson database, also known as the <strong>tz database</strong>. Is a public domain collaborative compilation of information about the world's timezones.</p>
<p class="instructions">It is widely used as basis for timezone information in operating systems and software. Most platforms and programming languages have libraries that support it.</p>
<p class="instructions"><a href="http://en.wikipedia.org/wiki/Tz_database">More at Wikipedia!</a></p>
<h3 class="omg">I don't like the timezone this script gives me!</h3>
<p class="instructions">This script does not do geolocation. It simply picks the most populated timezone among several roughly identical ones.</p>
<p class="instructions">For example, it is impossible to distinguish between different cities in Europe. This script will return Europe/Berlin regardless of where you live in the Central European timezone.</p>
<p class="instructions"><a href="https://bitbucket.org/pellepim/jstimezonedetect/wiki/Detection_List">Click here for the list of timezones this script is able to detect</a>.</p>
<h3 class="omg">NO CAN HAZ TIMEZONEZ?!?11</h3>
<p class="instructions">If this script fails to correctly determine your timezone, <a href="https://bitbucket.org/pellepim/jstimezonedetect/issues/new">Please report it!</a></p>
<p class="instructions">When you report an issue. Please tell us </p>
<ul>
   ...

CSS

body {
    font-family: helvetica, sans-serif;
    background-color: #ddd;
    color: #333;
    text-shadow:1px 1px 1px #fff;
  }
  
  div#content {
    background-color: #ccf;
    width: 550px;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid #fff;
    -moz-border-radius:5px 5px 5px 5px;
    border-bottom-left-radius: 5px 5px;
    border-bottom-right-radius: 5px 5px;
    border-top-left-radius: 5px 5px;
    border-top-right-radius: 5px 5px;
    -box-shadow: 5px 5px 3px #aaa;
    -moz-box-shadow: 5px 5px 3px #aaa;
    -webkit-box-shadow: 5px 5px 3px #aaa;
  }
  
  div#content p {
    padding: 3px 10px 3px 10px;
    text-align: left;
    font-size: 20px;
    line-height: 30px;
    font-weight: normal;
  }
  
  p.info {
    width: 730px;
    margin-left: auto;
    margin-right: auto;
    font-size: 11px;
    font-style: italic;
    font-weight: normal;
    text-align: right;
    letter-spacing: 1px;
  }
  
  p.instructions {
    width: 520px;
    margin-left: auto;
    margin-right: auto;
    font-size: 13px;
    text-align: left;
    letter-spacing: 1px;
    line-height: 15px;
  }
  
  ul {
    width: 520px;
    margin-left: auto;
    margin-right: auto;
    font-size: 13px;
    letter-spacing: 1px;
    line-height: 17px;
  }
  
  h1 {
    text-align: center;
    margin-bottom: 0px;
  }
  
  h3 {
    width: 550px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px;
    margin-bottom: -5px;
  }
  
  h3.omg {
    color: green;
  }
  
  a {
    border-bottom:1px solid #A7A7A7;
    color:#333;
    line-height:20px;
    white-space:nowrap;
    text-decoration: none;
  }
  
  a:hover {
    border-color: #000;
  }

JavaScript

/* 
 * Original script by Josh Fraser (http://www.onlineaspect.com)
 * Continued by Jon Nylander, (jon at pageloom dot com)
 * According to both of us, you are absolutely free to do whatever 
 * you want with this code.
 * 
 * This code is  maintained at bitbucket.org as jsTimezoneDetect.
 */

var HEMISPHERE_SOUTH = 'SOUTH';
var HEMISPHERE_NORTH = 'NORTH';
var HEMISPHERE_UNKNOWN = 'N/A';
var olson = {}

/**
 * The keys in this dictionary are comma separated as such:
 * 
 * First the offset compared to UTC time in minutes.
 *  
 * Then a flag which is 0 if the timezone does not take daylight savings into account and 1 if it does.
 * 
 * Thirdly an optional 's' signifies that the timezone is in the southern hemisphere, only interesting for timezones with DST.
 * 
 * The values of the dictionary are TimeZone objects.
 */
olson.timezones = {
    '-720,0'   : new TimeZone('-12:00','Etc/GMT+12', false),
    '-660,0'   : new TimeZone('-11:00','Pacific/Pago_Pago', false),
    '-600,1'   : new TimeZone('-11:00','America/Adak',true),
    '-660,1,s' : new TimeZone('-11:00','Pacific/Apia', true),
    '-600,0'   : new TimeZone('-10:00','Pacific/Honolulu', false),
    '-570,0'   : new TimeZone('-10:30','Pacific/Marquesas',false),
    '-540,0'   : new TimeZone('-09:00','Pacific/Gambier',false),
    '-540,1'   : new TimeZone('-09:00','America/Anchorage', true),
    '-480,1'   : new TimeZone('-08:00','America/Los_Angeles', true),
    '-480,0'   : new TimeZone('-08:00','Pacific/Pitcairn',false),
    '-420,0'   : new TimeZone('-07:00','America/Phoenix', false),
    '-420,1'   : new TimeZone('-07:00','America/Denver', true),
    '-360,0'   : new TimeZone('-06:00','America/Guatemala', false),
    '-360,1'   : new TimeZone('-06:00','America/Chicago', true),
    '-360,1,s' : new TimeZone('-06:00','Pacific/Easter',true),
    '-300,0'   : new TimeZone('-05:00','America/Bogota', false),
    '-300,1'   : new TimeZone('-05:00','America/New_York', true),
    '-270,0'   : new...