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-07-05 22:47:35 +0300
committersgiehl <stefan@piwik.org>2015-09-25 21:07:48 +0300
commit175b5bd50dbb8da7fb718f09a69d6dca986b20cb (patch)
tree68c5268eb6f2c14fbe99468ac5dc7ced6fc3b7da /core/Period
parent8b5acf39f6fef0f36ff6758c41890203f25cf1ef (diff)
Improved range formats; fixed/added tests
Diffstat (limited to 'core/Period')
-rw-r--r--core/Period/Range.php13
-rw-r--r--core/Period/Week.php73
2 files changed, 4 insertions, 82 deletions
diff --git a/core/Period/Range.php b/core/Period/Range.php
index 0bac3aad81..706428162e 100644
--- a/core/Period/Range.php
+++ b/core/Period/Range.php
@@ -107,16 +107,7 @@ class Range extends Period
*/
public function getLocalizedShortString()
{
- //"30 Dec 08 - 26 Feb 09"
- $dateStart = $this->getDateStart();
- $dateEnd = $this->getDateEnd();
- $template = Date::DATE_FORMAT_SHORT;
-
- $shortDateStart = $dateStart->getLocalized($template);
- $shortDateEnd = $dateEnd->getLocalized($template);
-
- $out = "$shortDateStart - $shortDateEnd";
- return $out;
+ return $this->getTranslatedRange($this->getRangeFormat(true), $this->getDateStart(), $this->getDateEnd());
}
/**
@@ -126,7 +117,7 @@ class Range extends Period
*/
public function getLocalizedLongString()
{
- return $this->getLocalizedShortString();
+ return $this->getTranslatedRange($this->getRangeFormat(), $this->getDateStart(), $this->getDateEnd());
}
/**
diff --git a/core/Period/Week.php b/core/Period/Week.php
index 88072b4ba5..2e6219a049 100644
--- a/core/Period/Week.php
+++ b/core/Period/Week.php
@@ -24,13 +24,7 @@ class Week extends Period
*/
public function getLocalizedShortString()
{
- //"30 Dec - 6 Jan 09"
- $dateStart = $this->getDateStart();
- $dateEnd = $this->getDateEnd();
-
- $format = $this->translator->translate('Intl_Format_Interval_Week_Short_'.$this->getMinDifference($dateStart, $dateEnd));
- $string = $this->getTranslatedRange($format, $dateStart, $dateEnd);
- return $string;
+ return $this->getTranslatedRange($this->getRangeFormat(true), $this->getDateStart(), $this->getDateEnd());
}
/**
@@ -40,73 +34,10 @@ class Week extends Period
*/
public function getLocalizedLongString()
{
- //"30 Dec - 6 Jan 09"
- $dateStart = $this->getDateStart();
- $dateEnd = $this->getDateEnd();
-
- $format = $this->translator->translate('Intl_Format_Interval_Week_Long_'.$this->getMinDifference($dateStart, $dateEnd));
- $string = $this->getTranslatedRange($format, $dateStart, $dateEnd);
-
+ $string = $this->getTranslatedRange($this->getRangeFormat(), $this->getDateStart(), $this->getDateEnd());
return $this->translator->translate('Intl_PeriodWeek') . " " . $string;
}
- protected function getMinDifference($dateFrom, $dateEnd)
- {
- if ($dateFrom->toString('y') != $dateEnd->toString('y')) {
- return 'Y';
- } elseif ($dateFrom->toString('m') != $dateEnd->toString('m')) {
- return 'M';
- }
-
- return 'D';
- }
-
- /**
- * @param string $format
- * @param \Piwik\Date $dateStart
- * @param \Piwik\Date $dateEnd
- *
- * @return mixed
- */
- protected function getTranslatedRange($format, $dateStart, $dateEnd)
- {
- list($formatStart, $formatEnd) = $this->explodeFormat($format);
-
- $string = $dateStart->getLocalized($formatStart);
- $string .= $dateEnd->getLocalized($formatEnd);
-
- return $string;
- }
-
- /**
- * Explodes the given format into two pieces. One that can be user for start date and the other for end date
- *
- * @param $format
- * @return array
- */
- protected function explodeFormat($format)
- {
- $intervalTokens = array(
- array('d', 'E', 'C'),
- array('M', 'L'),
- array('y')
- );
-
- $offset = strlen($format);
-
- // search for first duplicate date field
- foreach ($intervalTokens AS $tokens) {
- if (preg_match_all('/['.implode('|', $tokens).']+/', $format, $matches, PREG_OFFSET_CAPTURE)) {
- if (count($matches[0]) > 1 && $offset > $matches[0][1][1]) {
- $offset = $matches[0][1][1];
- }
- }
-
- }
-
- return array(substr($format, 0, $offset), substr($format, $offset));
- }
-
/**
* Returns the current period as a string
*