PluginProbe
Stream – Activity Log & Audit Trail / 3.1
Stream – Activity Log & Audit Trail v3.1
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
stream / classes / class-date-interval.php

class-date-interval.php in Stream – Activity Log & Audit Trail 3.1, at classes/class-date-interval.php

112 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WP_Stream;
3
4 // Load Carbon to Handle dates much easier
5 if ( ! class_exists( 'Carbon\Carbon' ) ) {
6 require_once wp_stream_get_instance()->locations['inc_dir'] . 'lib/Carbon.php';
7 }
8
9 use Carbon\Carbon;
10
11 class Date_Interval {
12 /**
13 * Contains an array of all available intervals
14 *
15 * @var array $intervals
16 */
17 public $intervals;
18
19 /**
20 * Class constructor
21 */
22 public function __construct() {
23 // Get all default intervals
24 $this->intervals = $this->get_predefined_intervals();
25 }
26
27 /**
28 * @return mixed|void
29 */
30 public function get_predefined_intervals() {
31 $timezone = get_option( 'timezone_string' );
32
33 if ( empty( $timezone ) ) {
34 $gmt_offset = (int) get_option( 'gmt_offset' );
35 $timezone = timezone_name_from_abbr( null, $gmt_offset * 3600, true );
36 if ( false === $timezone ) {
37 $timezone = timezone_name_from_abbr( null, $gmt_offset * 3600, false );
38 }
39 if ( false === $timezone ) {
40 $timezone = null;
41 }
42 }
43
44 return apply_filters(
45 'wp_stream_predefined_date_intervals',
46 array(
47 'today' => array(
48 'label' => esc_html__( 'Today', 'stream' ),
49 'start' => Carbon::today( $timezone )->startOfDay(),
50 'end' => Carbon::today( $timezone )->endOfDay(),
51 ),
52 'yesterday' => array(
53 'label' => esc_html__( 'Yesterday', 'stream' ),
54 'start' => Carbon::today( $timezone )->startOfDay()->subDay(),
55 'end' => Carbon::today( $timezone )->startOfDay()->subSecond(),
56 ),
57 'last-7-days' => array(
58 'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 7 ),
59 'start' => Carbon::today( $timezone )->subDays( 7 ),
60 'end' => Carbon::today( $timezone ),
61 ),
62 'last-14-days' => array(
63 'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 14 ),
64 'start' => Carbon::today( $timezone )->subDays( 14 ),
65 'end' => Carbon::today( $timezone ),
66 ),
67 'last-30-days' => array(
68 'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 30 ),
69 'start' => Carbon::today( $timezone )->subDays( 30 ),
70 'end' => Carbon::today( $timezone ),
71 ),
72 'this-month' => array(
73 'label' => esc_html__( 'This Month', 'stream' ),
74 'start' => Carbon::today( $timezone )->startOfMonth(),
75 'end' => Carbon::today( $timezone )->endOfMonth(),
76 ),
77 'last-month' => array(
78 'label' => esc_html__( 'Last Month', 'stream' ),
79 'start' => Carbon::today( $timezone )->startOfMonth()->subMonth(),
80 'end' => Carbon::today( $timezone )->startOfMonth()->subSecond(),
81 ),
82 'last-3-months' => array(
83 'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 3 ),
84 'start' => Carbon::today( $timezone )->subMonths( 3 ),
85 'end' => Carbon::today( $timezone ),
86 ),
87 'last-6-months' => array(
88 'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 6 ),
89 'start' => Carbon::today( $timezone )->subMonths( 6 ),
90 'end' => Carbon::today( $timezone ),
91 ),
92 'last-12-months' => array(
93 'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 12 ),
94 'start' => Carbon::today( $timezone )->subMonths( 12 ),
95 'end' => Carbon::today( $timezone ),
96 ),
97 'this-year' => array(
98 'label' => esc_html__( 'This Year', 'stream' ),
99 'start' => Carbon::today( $timezone )->startOfYear(),
100 'end' => Carbon::today( $timezone )->endOfYear(),
101 ),
102 'last-year' => array(
103 'label' => esc_html__( 'Last Year', 'stream' ),
104 'start' => Carbon::today( $timezone )->startOfYear()->subYear(),
105 'end' => Carbon::today( $timezone )->startOfYear()->subSecond(),
106 ),
107 ),
108 $timezone
109 );
110 }
111 }
112