Form
2 years ago
Frontend
2 years ago
Gateways
4 years ago
ArrayDataSet.php
1 year ago
Call.php
3 years ago
Date.php
4 years ago
EnqueueScript.php
4 years ago
Hooks.php
4 years ago
Html.php
4 years ago
IntlTelInput.php
2 years ago
Language.php
1 year ago
Table.php
4 years ago
Utils.php
1 year ago
Date.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Helpers; |
| 4 | |
| 5 | /** |
| 6 | * @since 2.20.0 |
| 7 | */ |
| 8 | class Date { |
| 9 | |
| 10 | /** |
| 11 | * Returns human readable date. |
| 12 | * |
| 13 | * @param string $datetime A date/time string |
| 14 | * @since 2.20.0 |
| 15 | * |
| 16 | * @return string |
| 17 | */ |
| 18 | public static function getDateTime($datetime) { |
| 19 | $dateTimestamp = strtotime($datetime); |
| 20 | $currentTimestamp = current_time('timestamp'); |
| 21 | $todayTimestamp = strtotime('today', $currentTimestamp); |
| 22 | $yesterdayTimestamp = strtotime('yesterday', $currentTimestamp); |
| 23 | |
| 24 | if ($dateTimestamp >= $todayTimestamp) { |
| 25 | return sprintf( |
| 26 | '%1$s %2$s %3$s', |
| 27 | esc_html__('Today', 'give'), |
| 28 | esc_html__('at', 'give'), |
| 29 | date_i18n(get_option('time_format'), $dateTimestamp) |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | if ($dateTimestamp >= $yesterdayTimestamp) { |
| 34 | return sprintf( |
| 35 | '%1$s %2$s %3$s', |
| 36 | esc_html__('Yesterday', 'give'), |
| 37 | esc_html__('at', 'give'), |
| 38 | date_i18n(get_option('time_format'), $dateTimestamp) |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | return sprintf( |
| 43 | '%1$s %2$s %3$s', |
| 44 | date_i18n(get_option('date_format'), $dateTimestamp), |
| 45 | esc_html__('at', 'give'), |
| 46 | date_i18n(get_option('time_format'), $dateTimestamp) |
| 47 | ); |
| 48 | } |
| 49 | } |
| 50 |