Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
#!/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
You can’t perform that action at this time.