Created
June 24, 2010 10:02
-
-
Save xrado/451267 to your computer and use it in GitHub Desktop.
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
<?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