Created
May 15, 2018 21:08
-
-
Save Zegnat/e36c8d5cc5d8dd6b65d8831adcbe7fe9 to your computer and use it in GitHub Desktop.
BitBar (https://getbitbar.com/) plugin for a variable drop-down of time zones. Also does unix epoch time, and copying of ISO timestamps to the clipboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/php | |
<?php | |
$now = new \DateTimeImmutable(null, new \DateTimeZone('UTC')); | |
$copy = getopt('c:'); | |
if (count($copy) > 0) { | |
// Make sure to use the local /bin/echo executable, exec() runs sh and native echo | |
// may not do what you expect. https://stackoverflow.com/a/40225695 | |
exec('/bin/echo -n ' . escapeshellarg($copy['c']) . ' | pbcopy', $devnull, $status); | |
exit($status); | |
} | |
$timezones = [ | |
// Central European Time | |
'Europe/Stockholm' => ['label' => 'Sweden', 'tabs' => 2], | |
// Indonesia Central Standard Time | |
'Asia/Makassar' => ['label' => 'Bali', 'tabs' => 3], | |
// Mountain Standard Time | |
'America/Denver' => ['label' => 'Ft. Collins', 'tabs' => 1], | |
// Pacific Standard Time | |
'America/Los_Angeles' => ['label' => 'Portland', 'tabs' => 2], | |
]; | |
define('END', "\n"); | |
echo $now->format('D G:i') . ' UTC | font=SFProText-Regular size=14' . END; | |
echo "---" . END; | |
echo $now->format('l, j F Y') . ' | font=SFProText-Regular size=14 terminal=false bash="' . __FILE__ . '" param1=-c param2=' . $now->format('c') . END; | |
echo 'Unix: ' . $now->format('U') . ' | alternate=true font=SFProText-Regular size=14 terminal=false bash="' . __FILE__ . '" param1=-c param2=' . $now->format('U') . END; | |
echo 'Week: ' . $now->format('W') . "\t" . 'Day: ' . strval(intval($now->format('z'))+1) . ' | font=SFProText-Regular size=14' . END; | |
echo "---" . END; | |
foreach ($timezones as $zone => $config) { | |
list('label' => $label, 'tabs' => $tabs) = $config; | |
$then = $now->setTimezone(new \DateTimeZone($zone)); | |
$day = $now->format('l') !== $then->format('l') ? ' (' . $then->format('l') . ')' : ''; | |
echo $label . str_repeat("\t", $tabs) . $then->format('G:i') . $day . ' | font=SFProText-Regular size=14' . END; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment