PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.1.3
Adminify – White Label, Admin Menu Editor, Login Customizer v4.1.3
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Notifications / Base / Date.php

Date.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.1.3, at Inc/Classes/Notifications/Base/Date.php

141 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPAdminify\Inc\Classes\Notifications\Base;
3
4 // No, Direct access Sir !!!
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 trait Date {
10
11 /**
12 * Current time
13 *
14 * @author Jewel Theme <support@jeweltheme.com>
15 */
16 public function current_time() {
17 return current_time( 'Y-m-d' );
18 }
19
20 /**
21 * Compare dates
22 *
23 * @param [type] $date_1 .
24 * @param [type] $date_2 .
25 * @param [type] $compare .
26 * @author Jewel Theme <support@jeweltheme.com>
27 */
28 public function date_compare( $date_1, $date_2 = null, $compare = null ) {
29 if ( ! $compare ) {
30 $compare = '==';
31 }
32
33 if ( ! $date_2 ) {
34 $date_2 = $this->current_time();
35 }
36
37 if ( '<' === $compare ) {
38 return strtotime( $date_1 ) < strtotime( $date_2 );
39 } elseif ( '>' === $compare ) {
40 return strtotime( $date_1 ) > strtotime( $date_2 );
41 } elseif ( '<=' === $compare ) {
42 return strtotime( $date_1 ) <= strtotime( $date_2 );
43 } elseif ( '>=' === $compare ) {
44 return strtotime( $date_1 ) >= strtotime( $date_2 );
45 } else {
46 return strtotime( $date_1 ) === strtotime( $date_2 );
47 }
48 }
49
50 /**
51 * Date Diff
52 *
53 * @param [type] $date_1 .
54 * @param [type] $date_2 .
55 *
56 * @author Jewel Theme <support@jeweltheme.com>
57 */
58 public function date_diff( $date_1, $date_2 = null ) {
59 if ( ! $date_2 ) {
60 $date_2 = $this->current_time();
61 }
62 $diff = date_diff( date_create( $date_2 ), date_create( $date_1 ) );
63
64 return $diff->format( '%R%a' );
65 }
66
67
68 /**
69 * Check Current date
70 *
71 * @param [type] $date_1 .
72 *
73 * @author Jewel Theme <support@jeweltheme.com>
74 */
75 public function date_is_current( $date_1 ) {
76 return $this->date_compare( $date_1 );
77 }
78
79 /**
80 * Check Prev date
81 *
82 * @param [type] $date_1 .
83 * @param [type] $date_2 .
84 *
85 * @author Jewel Theme <support@jeweltheme.com>
86 */
87 public function date_is_prev( $date_1, $date_2 = null ) {
88 return $this->date_compare( $date_1, $date_2, '<' );
89 }
90
91
92 /**
93 * Check current or previous date
94 *
95 * @param [type] $date_1 .
96 * @param [type] $date_2 .
97 *
98 * @author Jewel Theme <support@jeweltheme.com>
99 */
100 public function date_is_current_or_prev( $date_1, $date_2 = null ) {
101 return $this->date_compare( $date_1, $date_2, '<=' );
102 }
103
104
105 /**
106 * Date is next day
107 *
108 * @param [type] $date_1 .
109 * @param [type] $date_2 .
110 *
111 * @author Jewel Theme <support@jeweltheme.com>
112 */
113 public function date_is_next( $date_1, $date_2 = null ) {
114 return $this->date_compare( $date_1, $date_2, '>' );
115 }
116
117 /**
118 * Current date or next date
119 *
120 * @param [type] $date_1 .
121 * @param [type] $date_2 .
122 *
123 * @author Jewel Theme <support@jeweltheme.com>
124 */
125 public function date_is_current_or_next( $date_1, $date_2 = null ) {
126 return $this->date_compare( $date_1, $date_2, '>=' );
127 }
128
129
130 /**
131 * Date increament
132 *
133 * @param [type] $date .
134 * @param [type] $days .
135 *
136 * @author Jewel Theme <support@jeweltheme.com>
137 */
138 public function date_increment( $date, $days ) {
139 return gmdate( 'Y-m-d', strtotime( $date . " + $days days" ) );
140 }
141 }