Use strftime to format date with translated month names

This commit is contained in:
scambra 2012-06-07 14:44:59 +02:00
parent e7c9d5fe54
commit ec253f1354
5 changed files with 21 additions and 9 deletions

View File

@ -1,5 +1,5 @@
<?php <?php
$LOCALIZATIONS = array( $LOCALIZATIONS = array(
'date' => 'd.m.Y', 'date' => '%d.%m.%Y',
'datetime' => 'd.m.Y H:i:s', 'datetime' => '%d.%m.%Y %H:%M:%S',
'time' => 'H:i:s' ); 'time' => '%H:%M:%S' );

5
core/l10n/l10n-en.php Normal file
View File

@ -0,0 +1,5 @@
<?php
$LOCALIZATIONS = array(
'date' => '%B %e, %Y',
'datetime' => '%B %e, %Y %H:%M',
'time' => '%H:%M:%S' );

5
core/l10n/l10n-es.php Normal file
View File

@ -0,0 +1,5 @@
<?php
$LOCALIZATIONS = array(
'date' => '%e de %B de %Y',
'datetime' => '%e de %B de %Y %H:%M',
'time' => '%H:%M:%S' );

View File

@ -58,9 +58,9 @@ class OC_L10N{
* Localization * Localization
*/ */
private $localizations = array( private $localizations = array(
'date' => 'd.m.Y', 'date' => '%d.%m.%Y',
'datetime' => 'd.m.Y H:i:s', 'datetime' => '%d.%m.%Y %H:%M:%S',
'time' => 'H:i:s'); 'time' => '%H:%M:%S');
/** /**
* get an L10N instance * get an L10N instance
@ -216,7 +216,9 @@ class OC_L10N{
case 'time': case 'time':
if($data instanceof DateTime) return $data->format($this->localizations[$type]); if($data instanceof DateTime) return $data->format($this->localizations[$type]);
elseif(is_string($data)) $data = strtotime($data); elseif(is_string($data)) $data = strtotime($data);
return date($this->localizations[$type], $data); $language = self::findLanguage();
setlocale(LC_TIME, array($language, $language.'_'.strtoupper($language)));
return strftime($this->localizations[$type], $data);
break; break;
default: default:
return false; return false;

View File

@ -162,8 +162,8 @@ class OC_Util {
$offset=$clientTimeZone-$systemTimeZone; $offset=$clientTimeZone-$systemTimeZone;
$timestamp=$timestamp+$offset*60; $timestamp=$timestamp+$offset*60;
} }
$timeformat=$dateOnly?'F j, Y':'F j, Y, H:i'; $l=OC_L10N::get('lib');
return date($timeformat,$timestamp); return $l->l($dateOnly ? 'date' : 'datetime', $timestamp);
} }
/** /**