Skip to content

Instantly share code, notes, and snippets.

@mckelvey
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mckelvey/9262446 to your computer and use it in GitHub Desktop.
Save mckelvey/9262446 to your computer and use it in GitHub Desktop.
This tiny LiveWhale application module alters the time and meridian formatting from the PHP-based LiveWhale defaults.
<?php
$_LW->REGISTERED_APPS['time_formatter']=array(
'title'=>'Time Formatter',
'handlers'=>array('onWidgetFormat'),
);
class LiveWhaleApplicationTimeFormatter {
public function onWidgetFormat($type, $handler, $variables) { // alter widget variables
global $_LW;
if ($type === 'events' && $handler === 'onDisplay' && array_key_exists('time', $variables)) { // find events widgets with time output
$variables['time'] = preg_replace('~(\d+)(a|p)(m)~i', '$1 $2.$3.', $variables['time']); // reformat am, pm to have periods and always be lowercase
$variables['time'] = str_replace(':00', '', $variables['time']); // remove :00 from times
}
return $variables; // and return the variables
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment