Time Zones Are Hard - https://tz.rita.moe

Have a way to make it work without JS

+1 -1
css/styles.css
···
-
body{background-color:#efefef;color:#000;font-family:"Trebuchet MS","Lucida Sans Unicode","Lucida Grande","Lucida Sans",Arial,sans-serif;margin:0 auto;max-width:900px}header{background:#fff;border-radius:10px;margin:1rem .5rem 0;padding:1rem 1.5rem}header h1{font-size:1.5rem;margin:0}@media screen and (min-width: 500px){header h1{font-size:2rem}}header a{color:inherit;text-decoration:none}main{padding:1rem 2rem}main h2{font-size:1.5rem;margin:1rem 0;text-align:center}main h2 span{font-size:1.2rem}main form{line-height:2rem}main button{cursor:pointer}main .tz-table{display:flex;flex-wrap:wrap;justify-content:center;text-align:center}main .tz-table .tz-table-element{flex:0 0 calc(100% - 1rem);margin:.5rem}@media screen and (min-width: 440px){main .tz-table .tz-table-element{flex:0 0 calc(50% - 1rem)}}@media screen and (min-width: 630px){main .tz-table .tz-table-element{flex:0 0 calc(33% - 1rem)}}@media screen and (min-width: 820px){main .tz-table .tz-table-element{flex:0 0 calc(25% - 1rem)}}footer{color:gray;font-size:.7rem;margin-top:1rem;padding:1rem;text-align:center}@media screen and (prefers-color-scheme: dark){body{background-color:#111;color:#fff}header{background:#000}}/*# sourceMappingURL=styles.css.map */
+
body{background-color:#efefef;color:#000;font-family:"Trebuchet MS","Lucida Sans Unicode","Lucida Grande","Lucida Sans",Arial,sans-serif;margin:0 auto;max-width:900px}header{background:#fff;border-radius:10px;margin:1rem .5rem 0;padding:1rem 1.5rem}header h1{font-size:1.5rem;margin:0}@media screen and (min-width: 500px){header h1{font-size:2rem}}header a{color:inherit;text-decoration:none}main{padding:1rem 2rem}main h2{font-size:1.5rem;margin:1rem 0;text-align:center}main h2 span{font-size:1.2rem}main noscript small{font-size:small}main form{line-height:2rem}main button{cursor:pointer}main .tz-table{display:flex;flex-wrap:wrap;justify-content:center;text-align:center}main .tz-table .tz-table-element{flex:0 0 calc(100% - 1rem);margin:.5rem}@media screen and (min-width: 440px){main .tz-table .tz-table-element{flex:0 0 calc(50% - 1rem)}}@media screen and (min-width: 630px){main .tz-table .tz-table-element{flex:0 0 calc(33% - 1rem)}}@media screen and (min-width: 820px){main .tz-table .tz-table-element{flex:0 0 calc(25% - 1rem)}}footer{color:gray;font-size:.7rem;margin-top:1rem;padding:1rem;text-align:center}@media screen and (prefers-color-scheme: dark){body{background-color:#111;color:#fff}header{background:#000}}/*# sourceMappingURL=styles.css.map */
+1 -1
css/styles.css.map
···
-
{"version":3,"sourceRoot":"","sources":["styles.scss"],"names":[],"mappings":"AAAA,KACE,yBACA,WACA,gGACA,cACA,gBAGF,OACE,gBACA,mBACA,oBACA,oBAEA,UACE,iBACA,SAEA,qCAJF,UAKI,gBAIJ,SACE,cACA,qBAIJ,KACE,kBAEA,QACE,iBACA,cACA,kBAEA,aACE,iBAIJ,UACE,iBAGF,YACE,eAGF,eACE,aACA,eACA,uBACA,kBAIA,iCACE,2BACA,OAJQ,MAMR,qCAJF,iCAKI,2BAGF,qCARF,iCASI,2BAGF,qCAZF,iCAaI,2BAMR,OACE,WACA,gBACA,gBACA,aACA,kBAGF,+CACE,KACE,sBACA,WAGF,OACE","file":"styles.css"}
+
{"version":3,"sourceRoot":"","sources":["styles.scss"],"names":[],"mappings":"AAAA,KACE,yBACA,WACA,gGACA,cACA,gBAGF,OACE,gBACA,mBACA,oBACA,oBAEA,UACE,iBACA,SAEA,qCAJF,UAKI,gBAIJ,SACE,cACA,qBAIJ,KACE,kBAEA,QACE,iBACA,cACA,kBAEA,aACE,iBAIJ,oBACE,gBAGF,UACE,iBAGF,YACE,eAGF,eACE,aACA,eACA,uBACA,kBAIA,iCACE,2BACA,OAJQ,MAMR,qCAJF,iCAKI,2BAGF,qCARF,iCASI,2BAGF,qCAZF,iCAaI,2BAMR,OACE,WACA,gBACA,gBACA,aACA,kBAGF,+CACE,KACE,sBACA,WAGF,OACE","file":"styles.css"}
+4
css/styles.scss
···
}
}
+
noscript small {
+
font-size: small;
+
}
+
form {
line-height: 2rem;
}
+42 -1
index.php
···
'UTC'
];
+
// User sets timezone cookie
+
if (isset($_POST['user-tz'])) {
+
// Just check it's valid
+
if (in_array($_POST['user-tz'], timezone_identifiers_list(DateTimeZone::ALL))) {
+
setcookie('user-tz', $_POST['user-tz'], time() + 60 * 60 * 24 * 365);
+
$_COOKIE['user-tz'] = $_POST['user-tz'];
+
}
+
}
+
// Micro-routing
if (isset($_POST['datetime']) && isset($_POST['timezone'])) {
// -- Redirect to submitted date
···
</form>
<?php } else if (isset($dt)) { ?>
<h2 class="local">
-
<noscript>[Sorry, you'll need to allow javascript so I can use your local time]</noscript>
+
<noscript>
+
<?php
+
if (isset($_COOKIE['user-tz'])) {
+
echo toTZ($dt, $_COOKIE['user-tz']);
+
echo '<br/><small>(Enable JavaScript for better results.)</small>';
+
} else {
+
?>
+
Sorry, we need JavaScript to detect your local time.<br/>
+
Enable it or select your time zone:<br/>
+
<form method="post">
+
<select required id="user-tz" name="user-tz">
+
<option selected disabled>(pick one)</option>
+
<optgroup label="Popular">
+
<?php foreach($popTZ as $tz) { ?>
+
<option value="<?= $tz ?>">
+
<?= str_replace('_', ' ', $tz) ?> (<?= getOffset($tz) ?>)
+
</option>
+
<?php } ?>
+
</optgroup>
+
<optgroup label="All">
+
<?php foreach(timezone_identifiers_list(DateTimeZone::ALL) as $tz) { ?>
+
<option value="<?= $tz ?>">
+
<?= str_replace('_', ' ', $tz) ?> (<?= getOffset($tz) ?>)
+
</option>
+
<?php } ?>
+
</optgroup>
+
</select>
+
<button type="submit">Submit</button>
+
</form>
+
<?php
+
}
+
?>
+
</noscript>
</h2>
<br/>