PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.13.5
Independent Analytics – WordPress Analytics Plugin v2.13.5
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / IAWP / Date_Picker / Date_Picker.php
Date_Picker.php
41 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IAWP\Date_Picker;
4
5 use IAWP\Date_Range\Relative_Date_Range;
6 use IAWP\Utils\Timezone;
7 /** @internal */
8 class Date_Picker
9 {
10 private $start;
11 private $end;
12 private $relative_range;
13 private $first_data;
14 public function __construct($start, $end, $relative_range)
15 {
16 $this->start = $start;
17 $this->end = $end;
18 $this->relative_range = $relative_range;
19 $this->first_data = Relative_Date_Range::beginning_of_time();
20 }
21 public function calendar_html()
22 {
23 return \IAWPSCOPED\iawp_blade()->run('date-picker.date-picker', ['months' => $this->months(), 'start_date' => $this->start, 'end_date' => $this->end, 'relative_range' => $this->relative_range, 'date_ranges' => Relative_Date_Range::ranges(), 'timezone' => Timezone::site_timezone(), 'user_format' => \get_option('date_format'), 'first_data' => $this->first_data->format('Y-m-d'), 'site_offset_in_seconds' => Timezone::site_offset_in_seconds($this->start)]);
24 }
25 private function months() : array
26 {
27 $first_day_last_year = new \DateTime('first day of January last year', Timezone::site_timezone());
28 $start = $this->first_data < $first_day_last_year ? clone $this->first_data : clone $first_day_last_year;
29 $start->modify('first day of this month')->setTime(0, 0, 0);
30 $end = (new \DateTime('last day of this month', Timezone::site_timezone()))->setTime(23, 59, 59);
31 $interval = new \DateInterval('P1M');
32 // 1 month interval
33 $period = new \DatePeriod($start, $interval, $end);
34 $months = [];
35 foreach ($period as $month) {
36 $months[] = new \IAWP\Date_Picker\Month($month, $start);
37 }
38 return $months;
39 }
40 }
41