Day.php
2 years ago
Factory.php
2 years ago
Month.php
2 years ago
PeriodValidator.php
2 years ago
Range.php
2 years ago
Week.php
2 years ago
Year.php
2 years ago
Day.php
99 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | * |
| 9 | */ |
| 10 | namespace Piwik\Period; |
| 11 | |
| 12 | use Exception; |
| 13 | use Piwik\Date; |
| 14 | use Piwik\Period; |
| 15 | /** |
| 16 | */ |
| 17 | class Day extends Period |
| 18 | { |
| 19 | const PERIOD_ID = 1; |
| 20 | protected $label = 'day'; |
| 21 | /** |
| 22 | * Returns the day of the period as a string |
| 23 | * |
| 24 | * @return string |
| 25 | */ |
| 26 | public function getPrettyString() |
| 27 | { |
| 28 | $out = $this->getDateStart()->toString(); |
| 29 | return $out; |
| 30 | } |
| 31 | /** |
| 32 | * Returns the day of the period as a localized short string |
| 33 | * |
| 34 | * @return string |
| 35 | */ |
| 36 | public function getLocalizedShortString() |
| 37 | { |
| 38 | //"Mon 15 Aug" |
| 39 | $date = $this->getDateStart(); |
| 40 | $out = $date->getLocalized(Date::DATE_FORMAT_DAY_MONTH); |
| 41 | return $out; |
| 42 | } |
| 43 | /** |
| 44 | * Returns the day of the period as a localized long string |
| 45 | * |
| 46 | * @return string |
| 47 | */ |
| 48 | public function getLocalizedLongString() |
| 49 | { |
| 50 | //"Mon 15 Aug" |
| 51 | $date = $this->getDateStart(); |
| 52 | $out = $date->getLocalized(Date::DATE_FORMAT_LONG); |
| 53 | return $out; |
| 54 | } |
| 55 | /** |
| 56 | * Returns the number of subperiods |
| 57 | * Always 0, in that case |
| 58 | * |
| 59 | * @return int |
| 60 | */ |
| 61 | public function getNumberOfSubperiods() |
| 62 | { |
| 63 | return 0; |
| 64 | } |
| 65 | /** |
| 66 | * Adds a subperiod |
| 67 | * Not supported for day periods |
| 68 | * |
| 69 | * @param $date |
| 70 | * @throws Exception |
| 71 | */ |
| 72 | public function addSubperiod($date) |
| 73 | { |
| 74 | throw new Exception("Adding a subperiod is not supported for Day"); |
| 75 | } |
| 76 | /** |
| 77 | * Returns the day of the period in the given format |
| 78 | * |
| 79 | * @param string $format |
| 80 | * @return string |
| 81 | */ |
| 82 | public function toString($format = "Y-m-d") |
| 83 | { |
| 84 | return $this->date->toString($format); |
| 85 | } |
| 86 | public function __toString() |
| 87 | { |
| 88 | return $this->toString(); |
| 89 | } |
| 90 | public function getImmediateChildPeriodLabel() |
| 91 | { |
| 92 | return null; |
| 93 | } |
| 94 | public function getParentPeriodLabel() |
| 95 | { |
| 96 | return 'week'; |
| 97 | } |
| 98 | } |
| 99 |