PluginProbe
Bookit — Booking & Appointment Calendar / 2.6.0.5
Bookit — Booking & Appointment Calendar v2.6.0.5
2.6.0.5 2.6.0.4 2.6.0.3 2.6.0.2 2.6.0.1 2.6.0 trunk 1.2 1.2.2 1.2.3 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 All 62 releases
bookit / includes / helpers / TimeSlotHelper.php

TimeSlotHelper.php in Bookit — Booking & Appointment Calendar 2.6.0.5, at includes/helpers/TimeSlotHelper.php

65 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Bookit\Helpers;
4
5 use Bookit\Classes\Admin\SettingsController;
6
7 /**
8 * Bookit Time Slot Helper
9 */
10
11
12 class TimeSlotHelper {
13
14 /** slot length **/
15 const TIME_SLOT_POSSIBLE_VALUES = [
16 '15_minutes' => 15,
17 '20_minutes' => 20,
18 '30_minutes' => 30,
19 '45_minutes' => 45,
20 '1_hour' => 60
21 ];
22 const DAY_IN_SECONDS = 60 * 60 * 24;
23
24 /**
25 * @param integer $start - time in seconds
26 * @param integer $end - time in seconds
27 * @param string $type - possible values "default|admin"
28 */
29 public static function getTimeList($start, $end) {
30 $result = [];
31 $time_slot_duration = get_option_by_path('bookit_settings.time_slot_duration') ?: SettingsController::$time_slot_default_duration;
32
33 while ( $start <= $end ) {
34 $slot = [
35 'value' => self::timeFromSeconds($start),
36 'label' => self::timeFormat( $start ),
37 ];
38 $result[] = $slot;
39 $start += ( (int)$time_slot_duration * 60 );
40 }
41
42 return $result;
43 }
44
45 public static function timeFormat($time) {
46 return date_i18n( get_option( 'time_format' ), is_numeric( $time ) ? $time : strtotime( $time, current_time( 'timestamp' ) ) );
47 }
48
49 /**
50 * Build time string from seconds
51 *
52 * @param int $seconds
53 * @return string
54 */
55 public static function timeFromSeconds( $seconds ) {
56 $seconds = abs( $seconds );
57 $hours = (int) ( $seconds / 3600 );
58 $seconds -= $hours * 3600;
59 $minutes = (int) ( $seconds / 60 );
60 $seconds -= $minutes * 60;
61
62 return sprintf( '%s%02d:%02d:%02d', $seconds < 0 ? '-' : '', $hours, $minutes, $seconds );
63 }
64
65 }