245d0c4e63bf201028d51456d97adb4cc28e799d
[yaffs-website] / web / core / modules / datetime / datetime.module
1 <?php
2
3 /**
4  * @file
5  * Field hooks to implement a simple datetime field.
6  */
7
8 use Drupal\Core\Routing\RouteMatchInterface;
9
10 /**
11  * Defines the timezone that dates should be stored in.
12  *
13  * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use
14  * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::STORAGE_TIMEZONE
15  * instead.
16  *
17  * @see https://www.drupal.org/node/2912980
18  */
19 const DATETIME_STORAGE_TIMEZONE = 'UTC';
20
21 /**
22  * Defines the format that date and time should be stored in.
23  *
24  * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use
25  * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATETIME_STORAGE_FORMAT
26  * instead.
27  *
28  * @see https://www.drupal.org/node/2912980
29  */
30 const DATETIME_DATETIME_STORAGE_FORMAT = 'Y-m-d\TH:i:s';
31
32 /**
33  * Defines the format that dates should be stored in.
34  *
35  * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use
36  * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATE_STORAGE_FORMAT
37  * instead.
38  *
39  * @see https://www.drupal.org/node/2912980
40  */
41 const DATETIME_DATE_STORAGE_FORMAT = 'Y-m-d';
42
43 /**
44  * Implements hook_help().
45  */
46 function datetime_help($route_name, RouteMatchInterface $route_match) {
47   switch ($route_name) {
48     case 'help.page.datetime':
49       $output = '';
50       $output .= '<h3>' . t('About') . '</h3>';
51       $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>';
52       $output .= '<h3>' . t('Uses') . '</h3>';
53       $output .= '<dl>';
54       $output .= '<dt>' . t('Managing and displaying date fields') . '</dt>';
55       $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>';
56       $output .= '<dt>' . t('Displaying dates') . '</dt>';
57       $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>';
58       $output .= '</dl>';
59       return $output;
60   }
61 }
62
63 /**
64  * Sets a consistent time on a date without time.
65  *
66  * The default time for a date without time can be anything, so long as it is
67  * consistently applied. If we use noon, dates in most timezones will have the
68  * same value for in both the local timezone and UTC.
69  *
70  * @param $date
71  *
72  * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use
73  *   \Drupal\Component\Datetime\DateTimePlus::setDefaultDateTime() or
74  *   \Drupal\Core\Datetime\DrupalDateTime::setDefaultDateTime() instead.
75  *
76  * @see https://www.drupal.org/node/2880931
77  */
78 function datetime_date_default_time($date) {
79   @trigger_error('datetime_date_default_time() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Component\Datetime\DateTimePlus::setDefaultDateTime() or \Drupal\Core\Datetime\DrupalDateTime::setDefaultDateTime() instead. See https://www.drupal.org/node/2880931.', E_USER_DEPRECATED);
80
81   // For maximum BC before this method is removed, we do not use the
82   // recommendation from the deprecation method. Instead, we call the setTime()
83   // method directly. This allows the method to continue to work with
84   // \DateTime, DateTimePlus, and DrupalDateTime objects (and classes that
85   // may derive from them).
86   $date->setTime(12, 0, 0);
87 }