private static function SmartDateTrait::timeFormat in Smart Date 3.x
Same name and namespace in other branches
- 8.2 src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::timeFormat()
- 8 src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::timeFormat()
- 3.0.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::timeFormat()
- 3.1.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::timeFormat()
- 3.2.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::timeFormat()
- 3.3.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::timeFormat()
- 3.4.x src/SmartDateTrait.php \Drupal\smart_date\SmartDateTrait::timeFormat()
Helper function to apply time formats.
Parameters
int $time: The timestamp to format.
array $settings: The settings that will be used for formatting.
string|null $timezone: An optional timezone override.
bool $is_start: If this is the start time in a range, it requires special treatment.
Return value
string The formatted time.
1 call to SmartDateTrait::timeFormat()
- SmartDateTrait::formatSmartDate in src/
SmartDateTrait.php - Creates a formatted date value as a string.
File
- src/
SmartDateTrait.php, line 427
Class
- SmartDateTrait
- Provides friendly methods for smart date range.
Namespace
Drupal\smart_dateCode
private static function timeFormat($time, array $settings, $timezone = NULL, $is_start = FALSE) {
$format = $settings['time_format'];
if (!empty($settings['time_hour_format']) && date('i', $time) == '00') {
$format = $settings['time_hour_format'];
}
if ($is_start) {
if ($settings['ampm_reduce']) {
// Remove am/pm if configured to.
$format = preg_replace('/\\s*(?<![\\\\])a/i', '', $format);
}
// Remove the timezone at the start of a time range.
$format = preg_replace('/\\s*(?<![\\\\])[eOPTZ]/i', '', $format);
}
return \Drupal::service('date.formatter')
->format($time, '', $format, $timezone);
}