Loading src/DateFormatter.php +16 −5 Original line number Diff line number Diff line Loading @@ -5,27 +5,37 @@ namespace Drupal\bookable_calendar; use Drupal\smart_date\SmartDateTrait; /** * Wrapper around the Smart Date Date Formatter as needed * Wrapper around the Smart Date Date Formatter as needed. */ class DateFormatter { use SmartDateTrait; /** * Take a start/end date and format it matching the * Smart Date Formatter * Take a start/end date and format it matching the Smart Date Formatter. * * @param string $start_ts * Start date timestamp. * @param string $end_ts * End date timestamp. * * @return string * Formatted date string. */ public static function formatDateToBooking($start_ts, $end_ts) { $service = \Drupal::service('entity_display.repository'); $view_display = $service->getViewDisplay('booking', 'booking', 'default'); $view_options = $view_display->get('content')['booking_date']; if (!is_null($view_options)) { $smart_date_format = \Drupal::entityTypeManager()->getStorage('smart_date_format') ->load($view_options['settings']['format']); $options = $smart_date_format->getOptions(); } else { $options = [ 'date_format' => 'l, F j, Y - H:i', ]; } $timezone = date_default_timezone_get(); $date = self::formatSmartDate($start_ts, $end_ts, $options, $timezone); $output = ''; Loading @@ -41,4 +51,5 @@ class DateFormatter { } return $output; } } Loading
src/DateFormatter.php +16 −5 Original line number Diff line number Diff line Loading @@ -5,27 +5,37 @@ namespace Drupal\bookable_calendar; use Drupal\smart_date\SmartDateTrait; /** * Wrapper around the Smart Date Date Formatter as needed * Wrapper around the Smart Date Date Formatter as needed. */ class DateFormatter { use SmartDateTrait; /** * Take a start/end date and format it matching the * Smart Date Formatter * Take a start/end date and format it matching the Smart Date Formatter. * * @param string $start_ts * Start date timestamp. * @param string $end_ts * End date timestamp. * * @return string * Formatted date string. */ public static function formatDateToBooking($start_ts, $end_ts) { $service = \Drupal::service('entity_display.repository'); $view_display = $service->getViewDisplay('booking', 'booking', 'default'); $view_options = $view_display->get('content')['booking_date']; if (!is_null($view_options)) { $smart_date_format = \Drupal::entityTypeManager()->getStorage('smart_date_format') ->load($view_options['settings']['format']); $options = $smart_date_format->getOptions(); } else { $options = [ 'date_format' => 'l, F j, Y - H:i', ]; } $timezone = date_default_timezone_get(); $date = self::formatSmartDate($start_ts, $end_ts, $options, $timezone); $output = ''; Loading @@ -41,4 +51,5 @@ class DateFormatter { } return $output; } }