Field hooks to implement a simple datetime field.

File

core/modules/datetime/datetime.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Field hooks to implement a simple datetime field.
  5. */
  6. use Drupal\Component\Utility\NestedArray;
  7. use Drupal\Core\Datetime\DrupalDateTime;
  8. use Drupal\Core\Form\FormStateInterface;
  9. use Drupal\Core\Routing\RouteMatchInterface;
  10. /**
  11. * Defines the timezone that dates should be stored in.
  12. */
  13. const DATETIME_STORAGE_TIMEZONE = 'UTC';
  14. /**
  15. * Defines the format that date and time should be stored in.
  16. */
  17. const DATETIME_DATETIME_STORAGE_FORMAT = 'Y-m-d\TH:i:s';
  18. /**
  19. * Defines the format that dates should be stored in.
  20. */
  21. const DATETIME_DATE_STORAGE_FORMAT = 'Y-m-d';
  22. /**
  23. * Implements hook_help().
  24. */
  25. function datetime_help($route_name, RouteMatchInterface $route_match) {
  26. switch ($route_name) {
  27. case 'help.page.datetime':
  28. $output = '';
  29. $output .= '<h3>' . t('About') . '</h3>';
  30. $output .= '<p>' . t('The Datetime module provides a Date field that stores dates and times. It also provides the Form API elements <em>datetime</em> and <em>datelist</em> for use in programming modules. See the <a href="!field">Field module help</a> and the <a href="!field_ui">Field UI module help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href="!datetime_do">online documentation for the Datetime module</a>.', array('!field' => \Drupal::url('help.page', array('name' => 'field')), '!field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#', '!datetime_do' => 'https://www.drupal.org/documentation/modules/datetime')) . '</p>';
  31. $output .= '<h3>' . t('Uses') . '</h3>';
  32. $output .= '<dl>';
  33. $output .= '<dt>' . t('Managing and displaying date fields') . '</dt>';
  34. $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the Date field can be configured separately. See the <a href="!field_ui">Field UI help</a> for more information on how to manage fields and their display.', array('!field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#')) . '</dd>';
  35. $output .= '<dt>' . t('Displaying dates') . '</dt>';
  36. $output .= '<dd>' . t('Dates can be displayed using the <em>Plain</em> or the <em>Default</em> formatter. The <em>Plain</em> formatter displays the date in the <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> format. If you choose the <em>Default</em> formatter, you can choose a format from a predefined list that can be managed on the <a href="!date_format_list">Date and time formats</a> page.', array('!date_format_list'=> \Drupal::url('entity.date_format.collection'))) . '</dd>';
  37. $output .= '</dl>';
  38. return $output;
  39. }
  40. }
  41. /**
  42. * Sets a consistent time on a date without time.
  43. *
  44. * The default time for a date without time can be anything, so long as it is
  45. * consistently applied. If we use noon, dates in most timezones will have the
  46. * same value for in both the local timezone and UTC.
  47. *
  48. * @param $date
  49. *
  50. */
  51. function datetime_date_default_time($date) {
  52. $date->setTime(12, 0, 0);
  53. }

Functions

Namesort descending Description
datetime_date_default_time Sets a consistent time on a date without time.
datetime_help Implements hook_help().

Constants

Namesort descending Description
DATETIME_DATETIME_STORAGE_FORMAT Defines the format that date and time should be stored in.
DATETIME_DATE_STORAGE_FORMAT Defines the format that dates should be stored in.
DATETIME_STORAGE_TIMEZONE Defines the timezone that dates should be stored in.