PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.6
VikBooking Hotel Booking Engine & PMS v1.8.6
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / libraries / adapter / html / classes / date.php

date.php in VikBooking Hotel Booking Engine & PMS 1.8.6, at libraries/adapter/html/classes/date.php

89 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikWP - Libraries
4 * @subpackage adapter.html
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Extended Utility class for handling date display.
16 *
17 * @since 10.1.19
18 */
19 abstract class JHtmlDate
20 {
21 /**
22 * Function to convert a static time into a relative measurement.
23 *
24 * @param mixed $date The date to convert.
25 * @param string $unit The optional unit of measurement to return
26 * if the value of the diff is greater than one.
27 * @param string $time An optional time to compare to, defaults to now.
28 * @param string $format An optional format for the JHtml::date output.
29 *
30 * @return string The converted time string.
31 */
32 public static function relative($date, $unit = null, $time = null, $format = null)
33 {
34 if ($time === null)
35 {
36 // get now
37 $time = new JDate('now');
38 }
39
40 // get the difference in seconds between now and the time
41 $diff = strtotime($time) - strtotime($date);
42
43 // less than a minute
44 if ($diff < 60)
45 {
46 return JText::translate('JLIB_HTML_DATE_RELATIVE_LESSTHANAMINUTE');
47 }
48
49 // round to minutes
50 $diff = round($diff / 60);
51
52 // 1 to 59 minutes
53 if ($diff < 60 || $unit === 'minute')
54 {
55 return JText::plural('JLIB_HTML_DATE_RELATIVE_MINUTES', $diff);
56 }
57
58 // round to hours
59 $diff = round($diff / 60);
60
61 // 1 to 23 hours
62 if ($diff < 24 || $unit === 'hour')
63 {
64 return JText::plural('JLIB_HTML_DATE_RELATIVE_HOURS', $diff);
65 }
66
67 // round to days
68 $diff = round($diff / 24);
69
70 // 1 to 6 days
71 if ($diff < 7 || $unit === 'day')
72 {
73 return JText::plural('JLIB_HTML_DATE_RELATIVE_DAYS', $diff);
74 }
75
76 // round to weeks
77 $diff = round($diff / 7);
78
79 // 1 to 4 weeks
80 if ($diff <= 4 || $unit === 'week')
81 {
82 return JText::plural('JLIB_HTML_DATE_RELATIVE_WEEKS', $diff);
83 }
84
85 // over a month, return the absolute time
86 return JHtml::fetch('date', $date, $format);
87 }
88 }
89