Daily.php
2 years ago
Hourly.php
5 months ago
Interval.php
1 year ago
Intervals.php
2 years ago
Monthly.php
1 year ago
Weekly.php
2 years ago
Weekly.php
40 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Statistics\Intervals; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class Weekly extends \IAWP\Statistics\Intervals\Interval |
| 7 | { |
| 8 | public function id() : string |
| 9 | { |
| 10 | return 'weekly'; |
| 11 | } |
| 12 | public function label() : string |
| 13 | { |
| 14 | return \__('Weekly', 'independent-analytics'); |
| 15 | } |
| 16 | public function date_interval() : \DateInterval |
| 17 | { |
| 18 | return new \DateInterval('P7D'); |
| 19 | } |
| 20 | public function calculate_start_of_interval_for(\DateTime $original_date_time) : \DateTime |
| 21 | { |
| 22 | $date_time = clone $original_date_time; |
| 23 | $date_time->setTime(0, 0, 0); |
| 24 | $start_of_week = \intval(\get_option('iawp_dow', 0)); |
| 25 | $day_of_week = \intval($date_time->format('w')); |
| 26 | $days_to_subtract = $day_of_week - $start_of_week; |
| 27 | if ($days_to_subtract < 0) { |
| 28 | $days_to_subtract = 7 - \abs($days_to_subtract); |
| 29 | } |
| 30 | $interval_to_subtract = new \DateInterval('P' . $days_to_subtract . "D"); |
| 31 | $date_time->sub($interval_to_subtract); |
| 32 | return $date_time; |
| 33 | } |
| 34 | public function get_label_for(\DateTime $date_time) : array |
| 35 | { |
| 36 | $in_six_days = (clone $date_time)->add(new \DateInterval('P6D')); |
| 37 | return ['tick' => $this->format($date_time, 'M j'), 'tooltipLabel' => $this->format($date_time, 'F jS') . ' - ' . $this->format($in_six_days, 'F jS')]; |
| 38 | } |
| 39 | } |
| 40 |