class YamlFormDateHelper in YAML Form 8
Helper class form date helper methods.
Hierarchy
- class \Drupal\yamlform\Utility\YamlFormDateHelper
Expanded class hierarchy of YamlFormDateHelper
2 files declare their use of YamlFormDateHelper
- yamlform.theme.inc in includes/
yamlform.theme.inc - Preprocessors and helper functions to make theming easier.
- yamlform.tokens.inc in ./
yamlform.tokens.inc - Builds placeholder replacement tokens for forms and submissions.
File
- src/
Utility/ YamlFormDateHelper.php, line 8
Namespace
Drupal\yamlform\UtilityView source
class YamlFormDateHelper {
/**
* Wrapper for DateFormatter that return an empty string for empty timestamps.
*
* @param int $timestamp
* A UNIX timestamp to format.
* @param string $type
* (optional) The data format to use.
* @param string $format
* (optional) If $type is 'custom', a PHP date format string suitable for
* element to date(). Use a backslash to escape ordinary text, so it does not
* get interpreted as date format characters.
* @param string|null $timezone
* (optional) Time zone identifier, as described at
* http://php.net/manual/timezones.php Defaults to the time zone used to
* display the page.
* @param string|null $langcode
* (optional) Language code to translate to. NULL (default) means to use
* the user interface language for the page.
*
* @return string
* A translated date string in the requested format. An empty string
* will be returned for empty timestamps.
*
* @see \Drupal\Core\Datetime\DateFormatterInterface::format
*/
public static function format($timestamp, $type = 'fallback', $format = '', $timezone = NULL, $langcode = NULL) {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
return $timestamp ? $date_formatter
->format($timestamp, $type) : '';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
YamlFormDateHelper:: |
public static | function | Wrapper for DateFormatter that return an empty string for empty timestamps. |