Drupal investigation

datetime.module 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @file
  4. * Field hooks to implement a simple datetime field.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. /**
  8. * Defines the timezone that dates should be stored in.
  9. */
  10. const DATETIME_STORAGE_TIMEZONE = 'UTC';
  11. /**
  12. * Defines the format that date and time should be stored in.
  13. */
  14. const DATETIME_DATETIME_STORAGE_FORMAT = 'Y-m-d\TH:i:s';
  15. /**
  16. * Defines the format that dates should be stored in.
  17. */
  18. const DATETIME_DATE_STORAGE_FORMAT = 'Y-m-d';
  19. /**
  20. * Implements hook_help().
  21. */
  22. function datetime_help($route_name, RouteMatchInterface $route_match) {
  23. switch ($route_name) {
  24. case 'help.page.datetime':
  25. $output = '';
  26. $output .= '<h3>' . t('About') . '</h3>';
  27. $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>.', [':field' => \Drupal::url('help.page', ['name' => 'field']), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#', ':datetime_do' => 'https://www.drupal.org/documentation/modules/datetime']) . '</p>';
  28. $output .= '<h3>' . t('Uses') . '</h3>';
  29. $output .= '<dl>';
  30. $output .= '<dt>' . t('Managing and displaying date fields') . '</dt>';
  31. $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.', [':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#']) . '</dd>';
  32. $output .= '<dt>' . t('Displaying dates') . '</dt>';
  33. $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.', [':date_format_list' => \Drupal::url('entity.date_format.collection')]) . '</dd>';
  34. $output .= '</dl>';
  35. return $output;
  36. }
  37. }
  38. /**
  39. * Sets a consistent time on a date without time.
  40. *
  41. * The default time for a date without time can be anything, so long as it is
  42. * consistently applied. If we use noon, dates in most timezones will have the
  43. * same value for in both the local timezone and UTC.
  44. *
  45. * @param $date
  46. */
  47. function datetime_date_default_time($date) {
  48. $date->setTime(12, 0, 0);
  49. }