diff options
author | diosmosis <benakamoorthi@fastmail.fm> | 2013-10-29 02:31:01 +0400 |
---|---|---|
committer | diosmosis <benakamoorthi@fastmail.fm> | 2013-10-29 02:31:04 +0400 |
commit | ceb09d167b9d207ba8ab62cb560a2576d1a8e021 (patch) | |
tree | d33b8e35386008e13cacd509551443ef1e093fa8 /core/Period.php | |
parent | 3079d0b1fef735c7486d9c952f869671b6ff808e (diff) |
Merge Period::factory and Period::advancedFactory.
Diffstat (limited to 'core/Period.php')
-rw-r--r-- | core/Period.php | 39 |
1 files changed, 11 insertions, 28 deletions
diff --git a/core/Period.php b/core/Period.php index 47103a232c..7962267a0a 100644 --- a/core/Period.php +++ b/core/Period.php @@ -78,13 +78,21 @@ abstract class Period * * Note: This method cannot create Range periods. * - * @param string $strPeriod `"day"`, `"week"`, `"month"`, `"year"` - * @param Date $date A date within the period. + * @param string $strPeriod `"day"`, `"week"`, `"month"`, `"year"`, `"range"` + * @param Date|string $date A date within the period or the range of dates. * @throws Exception If `$strPeriod` is invalid. * @return \Piwik\Period */ - static public function factory($strPeriod, Date $date) + static public function factory($strPeriod, $date) { + if (is_string($date)) { + if (Period::isMultiplePeriod($date, $strPeriod) || $strPeriod == 'range') { + return new Range($strPeriod, $date); + } + + $date = Date::factory($date); + } + switch ($strPeriod) { case 'day': return new Day($date); @@ -127,25 +135,6 @@ abstract class Period } /** - * The advanced factory method is easier to use from the API than the factory - * method above. It doesn't require an instance of Date and works for - * period=range. Generally speaking, anything that can be passed as period - * and range to the API methods can directly be forwarded to this factory - * method in order to get a suitable instance of Period. - * - * @param string $strPeriod `"day"`, `"week"`, `"month"`, `"year"`, `"range"` - * @param string $strDate The `'date'` query parameter value. - * @return \Piwik\Period - */ - public static function advancedFactory($strPeriod, $strDate) - { - if (Period::isMultiplePeriod($strDate, $strPeriod) || $strPeriod == 'range') { - return new Range($strPeriod, $strDate); - } - return Period::factory($strPeriod, Date::factory($strDate)); - } - - /** * Creates a period instance using a Site instance and two strings describing * the period & date. * @@ -313,12 +302,6 @@ abstract class Period return implode(",", $this->toString()); } - public function get($part = null) - { - $this->generate(); - return $this->date->toString($part); - } - /** * Returns a pretty string describing this period. * |