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