Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsgiehl <stefan@piwik.org>2015-10-28 01:52:30 +0300
committersgiehl <stefan@piwik.org>2015-10-28 01:52:30 +0300
commitdb969cd453646632118afcfc0e3b7b1c8724611b (patch)
tree4601d117ab7c63d31566e67ac3b464734807f63f /core/Date.php
parent4251fad091e917c06a070797bd50506827ffbe6c (diff)
added new DateTimeFormatProvider to provide date, time and interval formats
Diffstat (limited to 'core/Date.php')
-rw-r--r--core/Date.php60
1 files changed, 12 insertions, 48 deletions
diff --git a/core/Date.php b/core/Date.php
index 849f50973a..cbbe866708 100644
--- a/core/Date.php
+++ b/core/Date.php
@@ -11,6 +11,7 @@ namespace Piwik;
use Exception;
use Piwik\Container\StaticContainer;
+use Piwik\Intl\Data\Provider\DateTimeFormatProvider;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
/**
@@ -42,15 +43,15 @@ class Date
/** The default date time string format. */
const DATE_TIME_FORMAT = 'Y-m-d H:i:s';
- const DATETIME_FORMAT_LONG = 'Intl_Format_DateTime_Long';
- const DATETIME_FORMAT_SHORT = 'Intl_Format_DateTime_Short';
- const DATE_FORMAT_LONG = 'Intl_Format_Date_Long';
- const DATE_FORMAT_DAY_MONTH = 'Intl_Format_Date_Day_Month';
- const DATE_FORMAT_SHORT = 'Intl_Format_Date_Short';
- const DATE_FORMAT_MONTH_SHORT = 'Intl_Format_Month_Short';
- const DATE_FORMAT_MONTH_LONG = 'Intl_Format_Month_Long';
- const DATE_FORMAT_YEAR = 'Intl_Format_Year';
- const TIME_FORMAT = 'Intl_Format_Time';
+ const DATETIME_FORMAT_LONG = DateTimeFormatProvider::DATE_FORMAT_LONG;
+ const DATETIME_FORMAT_SHORT = DateTimeFormatProvider::DATETIME_FORMAT_SHORT;
+ const DATE_FORMAT_LONG = DateTimeFormatProvider::DATE_FORMAT_LONG;
+ const DATE_FORMAT_DAY_MONTH = DateTimeFormatProvider::DATE_FORMAT_DAY_MONTH;
+ const DATE_FORMAT_SHORT = DateTimeFormatProvider::DATE_FORMAT_SHORT;
+ const DATE_FORMAT_MONTH_SHORT = DateTimeFormatProvider::DATE_FORMAT_MONTH_SHORT;
+ const DATE_FORMAT_MONTH_LONG = DateTimeFormatProvider::DATE_FORMAT_MONTH_LONG;
+ const DATE_FORMAT_YEAR = DateTimeFormatProvider::DATE_FORMAT_YEAR;
+ const TIME_FORMAT = DateTimeFormatProvider::TIME_FORMAT;
/**
* Max days for months (non-leap-year). See {@link addPeriod()} implementation.
@@ -612,38 +613,6 @@ class Date
return new Date($result, $this->timezone);
}
- protected static $use12HourClock;
-
- protected function getTimeFormat()
- {
- if (is_null(self::$use12HourClock)) {
- self::$use12HourClock = LanguagesManager::uses12HourClockForCurrentUser();
- }
-
- $timeFormat = 'Intl_Format_Time_24';
-
- if (self::$use12HourClock) {
- $timeFormat = 'Intl_Format_Time_12';
-
- }
-
- $translator = StaticContainer::get('Piwik\Translation\Translator');
- $template = $translator->translate($timeFormat);
-
- return $template;
- }
-
- /**
- * For testing purpose only: Overwrites time format
- *
- * @param bool $use12HourClock
- */
- public static function forceTimeFormat($use12HourClock = false)
- {
- self::$use12HourClock = $use12HourClock;
- }
-
-
/**
* Returns a localized date string using the given template.
* The template should contain tags that will be replaced with localized date strings.
@@ -655,14 +624,9 @@ class Date
{
$template = $this->replaceLegacyPlaceholders($template);
- if (substr($template, 0, 5) == 'Intl_') {
- $translator = StaticContainer::get('Piwik\Translation\Translator');
- $template = $translator->translate($template);
- }
+ $dateTimeFormatProvider = StaticContainer::get('Piwik\Intl\Data\Provider\DateTimeFormatProvider');
- if (strpos($template, '{time}') !== false) {
- $template = str_replace('{time}', $this->getTimeFormat(), $template);
- }
+ $template = $dateTimeFormatProvider->getFormatPattern($template);
$tokens = self::parseFormat($template);