Skip to content

Instantly share code, notes, and snippets.

@xrado
Created June 24, 2010 10:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xrado/451267 to your computer and use it in GitHub Desktop.
Save xrado/451267 to your computer and use it in GitHub Desktop.
<?php defined('SYSPATH') or die('No direct script access.');
class Date extends Kohana_Date {
public static function format($date,$format='U',$offset=NULL)
{
if (empty($date) || $date == '0000-00-00 00:00:00' || $date == '0000-00-00') return NULL;
try
{
// Timestamp
if(ctype_digit($date)) $date = date('Y-m-d H:i:s',$date);
// Parse date
$d = new DateTime($date);
// Add offset
if ($offset) $d->modify($offset);
$formated = '';
foreach(str_split($format) as $f)
{
$part = $d->format($f);
// Translate
$formated.= ctype_digit($part) ? $part : __($part);
}
return $formated;
}
catch (Exception $e) {}
return NULL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment