• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Datetime\DrupalDateTime类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Drupal\Core\Datetime\DrupalDateTime的典型用法代码示例。如果您正苦于以下问题:PHP DrupalDateTime类的具体用法?PHP DrupalDateTime怎么用?PHP DrupalDateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DrupalDateTime类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: valueCallback

 /**
  * {@inheritdoc}
  *
  * Validates the date type to adjust 12 hour time and prevent invalid dates.
  * If the date is valid, the date is set in the form.
  */
 public static function valueCallback(&$element, $input, FormStateInterface $form_state)
 {
     $parts = $element['#date_part_order'];
     $increment = $element['#date_increment'];
     $date = NULL;
     if ($input !== FALSE) {
         $return = $input;
         if (isset($input['ampm'])) {
             if ($input['ampm'] == 'pm' && $input['hour'] < 12) {
                 $input['hour'] += 12;
             } elseif ($input['ampm'] == 'am' && $input['hour'] == 12) {
                 $input['hour'] -= 12;
             }
             unset($input['ampm']);
         }
         $timezone = !empty($element['#date_timezone']) ? $element['#date_timezone'] : NULL;
         $date = DrupalDateTime::createFromArray($input, $timezone);
         if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
             static::incrementRound($date, $increment);
         }
     } else {
         $return = array_fill_keys($parts, '');
         if (!empty($element['#default_value'])) {
             $date = $element['#default_value'];
             if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
                 static::incrementRound($date, $increment);
                 foreach ($parts as $part) {
                     switch ($part) {
                         case 'day':
                             $format = 'j';
                             break;
                         case 'month':
                             $format = 'n';
                             break;
                         case 'year':
                             $format = 'Y';
                             break;
                         case 'hour':
                             $format = in_array('ampm', $element['#date_part_order']) ? 'g' : 'G';
                             break;
                         case 'minute':
                             $format = 'i';
                             break;
                         case 'second':
                             $format = 's';
                             break;
                         case 'ampm':
                             $format = 'a';
                             break;
                         default:
                             $format = '';
                     }
                     $return[$part] = $date->format($format);
                 }
             }
         }
     }
     $return['object'] = $date;
     return $return;
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:66,代码来源:Datelist.php


示例2: hook_date_default_argument_alter

/**
 * Alter the default value for a date argument.
 *
 * @param object $argument
 *   The argument object.
 * @param string $value
 *   The default value created by the argument handler.
 */
function hook_date_default_argument_alter(&$argument, &$value)
{
    $style_options = $style_options = $argument->view->display_handler->get_option('style_options');
    if (!empty($style_options['track_date'])) {
        $default_date = new DrupalDateTime();
        $value = $default_date->format($argument->arg_format);
    }
}
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:16,代码来源:date.api.php


示例3: setDateTime

 /**
  * {@inheritdoc}
  */
 public function setDateTime(DrupalDateTime $dateTime, $notify = TRUE)
 {
     $this->value = $dateTime->getTimestamp();
     // Notify the parent of any changes.
     if ($notify && isset($this->parent)) {
         $this->parent->onChange($this->name);
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:11,代码来源:Timestamp.php


示例4: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::settingsForm($form, $form_state);
     $time = new DrupalDateTime();
     $format_types = $this->dateFormatStorage->loadMultiple();
     $options = [];
     foreach ($format_types as $type => $type_info) {
         $format = $this->dateFormatter->format($time->format('U'), $type);
         $options[$type] = $type_info->label() . ' (' . $format . ')';
     }
     $form['format_type'] = array('#type' => 'select', '#title' => t('Date format'), '#description' => t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."), '#options' => $options, '#default_value' => $this->getSetting('format_type'));
     return $form;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:16,代码来源:DateTimeDefaultFormatter.php


示例5: testDateTimezone

 /**
  * Test that DrupalDateTime can detect the right timezone to use.
  * Test with a variety of less commonly used timezone names to
  * help ensure that the system timezone will be different than the
  * stated timezones.
  */
 public function testDateTimezone()
 {
     global $user;
     $date_string = '2007-01-31 21:00:00';
     // Make sure no site timezone has been set.
     \Drupal::config('system.date')->set('timezone.user.configurable', 0)->set('timezone.default', NULL)->save();
     // Detect the system timezone.
     $system_timezone = date_default_timezone_get();
     // Create a date object with an unspecified timezone, which should
     // end up using the system timezone.
     $date = new DrupalDateTime($date_string);
     $timezone = $date->getTimezone()->getName();
     $this->assertTrue($timezone == $system_timezone, 'DrupalDateTime uses the system timezone when there is no site timezone.');
     // Create a date object with a specified timezone.
     $date = new DrupalDateTime($date_string, 'America/Yellowknife');
     $timezone = $date->getTimezone()->getName();
     $this->assertTrue($timezone == 'America/Yellowknife', 'DrupalDateTime uses the specified timezone if provided.');
     // Set a site timezone.
     \Drupal::config('system.date')->set('timezone.default', 'Europe/Warsaw')->save();
     // Create a date object with an unspecified timezone, which should
     // end up using the site timezone.
     $date = new DrupalDateTime($date_string);
     $timezone = $date->getTimezone()->getName();
     $this->assertTrue($timezone == 'Europe/Warsaw', 'DrupalDateTime uses the site timezone if provided.');
     // Create user.
     \Drupal::config('system.date')->set('timezone.user.configurable', 1)->save();
     $test_user = $this->drupalCreateUser(array());
     $this->drupalLogin($test_user);
     // Set up the user with a different timezone than the site.
     $edit = array('mail' => $test_user->getEmail(), 'timezone' => 'Asia/Manila');
     $this->drupalPostForm('user/' . $test_user->id() . '/edit', $edit, t('Save'));
     // Disable session saving as we are about to modify the global $user.
     \Drupal::service('session_manager')->disable();
     // Save the original user and then replace it with the test user.
     $real_user = $user;
     $user = user_load($test_user->id(), TRUE);
     // Simulate a Drupal bootstrap with the logged-in user.
     date_default_timezone_set(drupal_get_user_timezone());
     // Create a date object with an unspecified timezone, which should
     // end up using the user timezone.
     $date = new DrupalDateTime($date_string);
     $timezone = $date->getTimezone()->getName();
     $this->assertTrue($timezone == 'Asia/Manila', 'DrupalDateTime uses the user timezone, if configurable timezones are used and it is set.');
     // Restore the original user, and enable session saving.
     $user = $real_user;
     // Restore default time zone.
     date_default_timezone_set(drupal_get_user_timezone());
     \Drupal::service('session_manager')->enable();
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:55,代码来源:DrupalDateTimeTest.php


示例6: testTaxonomyLegacyNode

 /**
  * Test taxonomy functionality with nodes prior to 1970.
  */
 function testTaxonomyLegacyNode()
 {
     // Posts an article with a taxonomy term and a date prior to 1970.
     $date = new DrupalDateTime('1969-01-01 00:00:00');
     $edit = array();
     $edit['title[0][value]'] = $this->randomMachineName();
     $edit['created[0][value][date]'] = $date->format('Y-m-d');
     $edit['created[0][value][time]'] = $date->format('H:i:s');
     $edit['body[0][value]'] = $this->randomMachineName();
     $edit['field_tags[target_id]'] = $this->randomMachineName();
     $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
     // Checks that the node has been saved.
     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $this->assertEqual($node->getCreatedTime(), $date->getTimestamp(), 'Legacy node was saved with the right date.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:18,代码来源:LegacyTest.php


示例7: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $default_role_choices = user_role_names(TRUE);
     unset($default_role_choices[DRUPAL_AUTHENTICATED_RID]);
     $roles_config = $this->config('uc_role.settings');
     if (!count($default_role_choices)) {
         $form['no_roles'] = array('#markup' => $this->t('You need to <a href=":url">create new roles</a> before any can be added as product features.', [':url' => Url::fromRoute('user.role_add', [], ['query' => ['destination' => 'admin/store/config/products']])->toString()]), '#prefix' => '<p>', '#suffix' => '</p>');
         return $form;
     }
     $form['default_role'] = array('#type' => 'select', '#title' => $this->t('Default role'), '#default_value' => $roles_config->get('default_role'), '#description' => $this->t('The default role Ubercart grants on specified products.'), '#options' => _uc_role_get_choices());
     $form['default_role_choices'] = array('#type' => 'checkboxes', '#title' => $this->t('Product roles'), '#default_value' => $roles_config->get('default_role_choices'), '#multiple' => TRUE, '#description' => $this->t('These are roles that Ubercart can grant to customers who purchase specified products. If you leave all roles unchecked, they will all be eligible for adding to a product.'), '#options' => $default_role_choices);
     $form['role_lifetime'] = array('#type' => 'fieldset', '#title' => $this->t('Default role expiration'));
     $form['role_lifetime']['default_end_expiration'] = array('#type' => 'select', '#title' => $this->t('Expiration type'), '#options' => array('rel' => $this->t('Relative to purchase date'), 'abs' => $this->t('Fixed date')), '#default_value' => $roles_config->get('default_end_expiration'));
     $form['role_lifetime']['default_length'] = array('#type' => 'textfield', '#default_value' => $roles_config->get('default_granularity') == 'never' ? NULL : $roles_config->get('default_length'), '#size' => 4, '#maxlength' => 4, '#prefix' => '<div class="expiration">', '#suffix' => '</div>', '#states' => array('visible' => array('select[name="default_end_expiration"]' => array('value' => 'rel')), 'invisible' => array('select[name="default_granularity"]' => array('value' => 'never'))));
     $form['role_lifetime']['default_granularity'] = array('#type' => 'select', '#default_value' => $roles_config->get('default_granularity'), '#options' => array('never' => $this->t('never'), 'day' => $this->t('day(s)'), 'week' => $this->t('week(s)'), 'month' => $this->t('month(s)'), 'year' => $this->t('year(s)')), '#description' => $this->t('From the time the role was purchased.'), '#prefix' => '<div class="expiration">', '#suffix' => '</div>', '#states' => array('visible' => array('select[name="default_end_expiration"]' => array('value' => 'rel'))));
     $form['role_lifetime']['absolute'] = array('#type' => 'container', '#states' => array('visible' => array('select[name="default_end_expiration"]' => array('value' => 'abs'))));
     $date = (int) $roles_config->get('default_end_time');
     $date = !empty($date) ? DrupalDateTime::createFromTimestamp($date) : DrupalDateTime::createFromTimestamp(REQUEST_TIME);
     $form['role_lifetime']['absolute']['default_end_time'] = array('#type' => 'datetime', '#description' => $this->t('Expire the role at the beginning of this day.'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => $date);
     $form['role_lifetime']['default_by_quantity'] = array('#type' => 'checkbox', '#title' => $this->t('Multiply by quantity'), '#description' => $this->t('Check if the role duration should be multiplied by the quantity purchased.'), '#default_value' => $roles_config->get('default_by_quantity'));
     $form['reminder']['reminder_length'] = array('#type' => 'textfield', '#title' => $this->t('Time before reminder'), '#default_value' => $roles_config->get('reminder_granularity') == 'never' ? NULL : $roles_config->get('reminder_length'), '#size' => 4, '#maxlength' => 4, '#prefix' => '<div class="expiration">', '#suffix' => '</div>', '#states' => array('disabled' => array('select[name="reminder_granularity"]' => array('value' => 'never'))));
     $form['reminder']['reminder_granularity'] = array('#type' => 'select', '#default_value' => $roles_config->get('reminder_granularity'), '#options' => array('never' => $this->t('never'), 'day' => $this->t('day(s)'), 'week' => $this->t('week(s)'), 'month' => $this->t('month(s)'), 'year' => $this->t('year(s)')), '#description' => $this->t('The amount of time before a role expiration takes place that a customer is notified of its expiration.'), '#prefix' => '<div class="expiration">', '#suffix' => '</div>');
     $form['default_show_expiration'] = array('#type' => 'checkbox', '#title' => $this->t('Show expirations on user page'), '#default_value' => $roles_config->get('default_show_expiration'), '#description' => $this->t('If users have any role expirations they will be displayed on their account page.'));
     return parent::buildForm($form, $form_state);
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:28,代码来源:FeatureSettingsForm.php


示例8: massageFormValues

 /**
  * {@inheritdoc}
  */
 public function massageFormValues(array $values, array $form, FormStateInterface $form_state)
 {
     foreach ($values as &$item) {
         // @todo The structure is different whether access is denied or not, to
         //   be fixed in https://www.drupal.org/node/2326533.
         if (isset($item['value']) && $item['value'] instanceof DrupalDateTime) {
             $date = $item['value'];
         } elseif (isset($item['value']['object']) && $item['value']['object'] instanceof DrupalDateTime) {
             $date = $item['value']['object'];
         } else {
             $date = new DrupalDateTime();
         }
         $item['value'] = $date->getTimestamp();
     }
     return $values;
 }
开发者ID:318io,项目名称:318-io,代码行数:19,代码来源:TimestampDatetimeWidget.php


示例9: valueCallback

 /**
  * {@inheritdoc}
  */
 public static function valueCallback(&$element, $input, FormStateInterface $form_state)
 {
     if ($input !== FALSE) {
         $date_input = $element['#date_date_element'] != 'none' && !empty($input['date']) ? $input['date'] : '';
         $time_input = $element['#date_time_element'] != 'none' && !empty($input['time']) ? $input['time'] : '';
         $date_format = $element['#date_date_element'] != 'none' ? static::getHtml5DateFormat($element) : '';
         $time_format = $element['#date_time_element'] != 'none' ? static::getHtml5TimeFormat($element) : '';
         $timezone = !empty($element['#date_timezone']) ? $element['#date_timezone'] : NULL;
         // Seconds will be omitted in a post in case there's no entry.
         if (!empty($time_input) && strlen($time_input) == 5) {
             $time_input .= ':00';
         }
         try {
             $date_time_format = trim($date_format . ' ' . $time_format);
             $date_time_input = trim($date_input . ' ' . $time_input);
             $date = DrupalDateTime::createFromFormat($date_time_format, $date_time_input, $timezone);
         } catch (\Exception $e) {
             $date = NULL;
         }
         $input = array('date' => $date_input, 'time' => $time_input, 'object' => $date);
     } else {
         $date = $element['#default_value'];
         if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
             $input = array('date' => $date->format($element['#date_date_format']), 'time' => $date->format($element['#date_time_format']), 'object' => $date);
         } else {
             $input = array('date' => '', 'time' => '', 'object' => NULL);
         }
     }
     return $input;
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:33,代码来源:Datetime.php


示例10: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL)
 {
     $balance = uc_payment_balance($uc_order);
     $form['balance'] = array('#prefix' => '<strong>' . $this->t('Order balance:') . '</strong> ', '#markup' => uc_currency_format($balance));
     $form['order_id'] = array('#type' => 'hidden', '#value' => $uc_order->id());
     $form['amount'] = array('#type' => 'uc_price', '#title' => $this->t('Check amount'), '#default_value' => $balance);
     $form['comment'] = array('#type' => 'textfield', '#title' => $this->t('Comment'), '#description' => $this->t('Any notes about the check, like type or check number.'), '#size' => 64, '#maxlength' => 256);
     $form['clear_date'] = array('#type' => 'datetime', '#title' => $this->t('Expected clear date'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => DrupalDateTime::createFromTimestamp(REQUEST_TIME));
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Receive check'));
     return $form;
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:15,代码来源:ReceiveCheckForm.php


示例11: testDateTimezone

 /**
  * Test that DrupalDateTime can detect the right timezone to use.
  * Test with a variety of less commonly used timezone names to
  * help ensure that the system timezone will be different than the
  * stated timezones.
  */
 public function testDateTimezone()
 {
     $date_string = '2007-01-31 21:00:00';
     // Make sure no site timezone has been set.
     $this->config('system.date')->set('timezone.user.configurable', 0)->set('timezone.default', NULL)->save();
     // Detect the system timezone.
     $system_timezone = date_default_timezone_get();
     // Create a date object with an unspecified timezone, which should
     // end up using the system timezone.
     $date = new DrupalDateTime($date_string);
     $timezone = $date->getTimezone()->getName();
     $this->assertTrue($timezone == $system_timezone, 'DrupalDateTime uses the system timezone when there is no site timezone.');
     // Create a date object with a specified timezone.
     $date = new DrupalDateTime($date_string, 'America/Yellowknife');
     $timezone = $date->getTimezone()->getName();
     $this->assertTrue($timezone == 'America/Yellowknife', 'DrupalDateTime uses the specified timezone if provided.');
     // Set a site timezone.
     $this->config('system.date')->set('timezone.default', 'Europe/Warsaw')->save();
     // Create a date object with an unspecified timezone, which should
     // end up using the site timezone.
     $date = new DrupalDateTime($date_string);
     $timezone = $date->getTimezone()->getName();
     $this->assertTrue($timezone == 'Europe/Warsaw', 'DrupalDateTime uses the site timezone if provided.');
     // Create user.
     $this->config('system.date')->set('timezone.user.configurable', 1)->save();
     $test_user = $this->drupalCreateUser(array());
     $this->drupalLogin($test_user);
     // Set up the user with a different timezone than the site.
     $edit = array('mail' => $test_user->getEmail(), 'timezone' => 'Asia/Manila');
     $this->drupalPostForm('user/' . $test_user->id() . '/edit', $edit, t('Save'));
     // Reload the user and reset the timezone in AccountProxy::setAccount().
     \Drupal::entityManager()->getStorage('user')->resetCache();
     $this->container->get('current_user')->setAccount(User::load($test_user->id()));
     // Create a date object with an unspecified timezone, which should
     // end up using the user timezone.
     $date = new DrupalDateTime($date_string);
     $timezone = $date->getTimezone()->getName();
     $this->assertTrue($timezone == 'Asia/Manila', 'DrupalDateTime uses the user timezone, if configurable timezones are used and it is set.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:45,代码来源:DrupalDateTimeTest.php


示例12: datetimeRangeYears

 /**
  * Specifies the start and end year to use as a date range.
  *
  * Handles a string like -3:+3 or 2001:2010 to describe a dynamic range of
  * minimum and maximum years to use in a date selector.
  *
  * Centers the range around the current year, if any, but expands it far enough
  * so it will pick up the year value in the field in case the value in the field
  * is outside the initial range.
  *
  * @param string $string
  *   A min and max year string like '-3:+1' or '2000:2010' or '2000:+3'.
  * @param object $date
  *   (optional) A date object to test as a default value. Defaults to NULL.
  *
  * @return array
  *   A numerically indexed array, containing the minimum and maximum year
  *   described by this pattern.
  */
 protected static function datetimeRangeYears($string, $date = NULL)
 {
     $datetime = new DrupalDateTime();
     $this_year = $datetime->format('Y');
     list($min_year, $max_year) = explode(':', $string);
     // Valid patterns would be -5:+5, 0:+1, 2008:2010.
     $plus_pattern = '@[\\+|\\-][0-9]{1,4}@';
     $year_pattern = '@^[0-9]{4}@';
     if (!preg_match($year_pattern, $min_year, $matches)) {
         if (preg_match($plus_pattern, $min_year, $matches)) {
             $min_year = $this_year + $matches[0];
         } else {
             $min_year = $this_year;
         }
     }
     if (!preg_match($year_pattern, $max_year, $matches)) {
         if (preg_match($plus_pattern, $max_year, $matches)) {
             $max_year = $this_year + $matches[0];
         } else {
             $max_year = $this_year;
         }
     }
     // We expect the $min year to be less than the $max year. Some custom values
     // for -99:+99 might not obey that.
     if ($min_year > $max_year) {
         $temp = $max_year;
         $max_year = $min_year;
         $min_year = $temp;
     }
     // If there is a current value, stretch the range to include it.
     $value_year = $date instanceof DrupalDateTime ? $date->format('Y') : '';
     if (!empty($value_year)) {
         $min_year = min($value_year, $min_year);
         $max_year = max($value_year, $max_year);
     }
     return array($min_year, $max_year);
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:56,代码来源:DateElementBase.php


示例13: prepareValue

 /**
  * {@inheritdoc}
  */
 protected function prepareValue($delta, array &$values)
 {
     $date = FALSE;
     $value = trim($values['value']);
     if (is_numeric($value) || is_string($value) && ($value = strtotime($value))) {
         $date = DrupalDateTime::createFromTimestamp($value, DATETIME_STORAGE_TIMEZONE);
     } elseif ($value instanceof \DateTime) {
         $date = DrupalDateTime::createFromDateTime($value);
     }
     if ($date && !$date->hasErrors()) {
         $values['value'] = $date->format($this->storageFormat);
     } else {
         $values['value'] = '';
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:18,代码来源:DateTime.php


示例14: prepareValue

 /**
  * {@inheritdoc}
  */
 protected function prepareValue($delta, array &$values)
 {
     $value = trim($values['value']);
     // This is a year value.
     if (ctype_digit($value) && strlen($value) === 4) {
         $value = 'January ' . $value;
     }
     if (is_numeric($value) || ($value = strtotime($value))) {
         $date = DrupalDateTime::createFromTimestamp($value, DATETIME_STORAGE_TIMEZONE);
     }
     if (isset($date) && !$date->hasErrors()) {
         $values['value'] = $date->format($this->storageFormat);
     } else {
         $values['value'] = '';
     }
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:19,代码来源:DateTime.php


示例15: getValue

 /**
  * {@inheritdoc}
  */
 public function getValue($langcode = NULL)
 {
     if ($this->date !== NULL) {
         return $this->date;
     }
     $item = $this->getParent();
     $value = $item->{$this->definition->getSetting('date source')};
     $storage_format = $item->getFieldDefinition()->getSetting('datetime_type') == 'date' ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT;
     try {
         $date = DrupalDateTime::createFromFormat($storage_format, $value, DATETIME_STORAGE_TIMEZONE);
         if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
             $this->date = $date;
         }
     } catch (\Exception $e) {
         // @todo Handle this.
     }
     return $this->date;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:21,代码来源:DateTimeComputed.php


示例16: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $args = NULL)
 {
     if (!isset($args['start_date'])) {
         $args['start_date'] = REQUEST_TIME;
     }
     if (!isset($args['end_date'])) {
         $args['end_date'] = REQUEST_TIME;
     }
     if (!isset($args['statuses'])) {
         $args['statuses'] = uc_report_order_statuses();
     }
     $form['params'] = array('#type' => 'fieldset', '#title' => $this->t('Customize tax report parameters'), '#description' => $this->t('Adjust these values and update the report to build your sales tax report. Once submitted, the report may be bookmarked for easy reference in the future.'));
     $form['params']['start_date'] = array('#type' => 'datetime', '#title' => $this->t('Start date'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => DrupalDateTime::createFromTimestamp($args['start_date']));
     $form['params']['end_date'] = array('#type' => 'datetime', '#title' => $this->t('End date'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => DrupalDateTime::createFromTimestamp($args['end_date']));
     $form['params']['statuses'] = array('#type' => 'select', '#title' => $this->t('Order statuses'), '#description' => $this->t('Only orders with selected statuses will be included in the report.') . '<br />' . $this->t('Hold Ctrl + click to select multiple statuses.'), '#options' => OrderStatus::getOptionsList(), '#default_value' => $args['statuses'], '#multiple' => TRUE, '#size' => 5);
     $form['params']['actions'] = array('#type' => 'actions');
     $form['params']['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Update report'));
     return $form;
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:22,代码来源:ParametersForm.php


示例17: formatDate

 /**
  * Formats a date/time as a time interval.
  *
  * @param \Drupal\Core\Datetime\DrupalDateTime|object $date
  *   A date/time object.
  *
  * @return string
  *   The formatted date/time string using the past or future format setting.
  */
 protected function formatDate(DrupalDateTime $date)
 {
     $granularity = $this->getSetting('granularity');
     $timestamp = $date->getTimestamp();
     $options = ['granularity' => $granularity];
     if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
         return SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, $options)]);
     } else {
         return SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, $options)]);
     }
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:20,代码来源:DateTimeTimeAgoFormatter.php


示例18: getCreatedTime

 /**
  * {@inheritdoc}
  */
 public function getCreatedTime()
 {
     return DrupalDateTime::createFromTimestamp($this->get('created')->value);
 }
开发者ID:heddn,项目名称:content_entity_base,代码行数:7,代码来源:EntityBase.php


示例19: setTimeZone

 /**
  * Sets the proper time zone on a DrupalDateTime object for the current user.
  *
  * A DrupalDateTime object loaded from the database will have the UTC time
  * zone applied to it.  This method will apply the time zone for the current
  * user, based on system and user settings.
  *
  * @see drupal_get_user_timezone()
  *
  * @param \Drupal\Core\Datetime\DrupalDateTime $date
  *   A DrupalDateTime object.
  */
 protected function setTimeZone(DrupalDateTime $date)
 {
     $date->setTimeZone(timezone_open(drupal_get_user_timezone()));
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:16,代码来源:DateTimeFormatterBase.php


示例20: formatDate

 /**
  * Formats a date/time as a time interval.
  *
  * @param \Drupal\Core\Datetime\DrupalDateTime|object $date
  *   A date/time object.
  *
  * @return array
  *   The formatted date/time string using the past or future format setting.
  */
 protected function formatDate(DrupalDateTime $date)
 {
     $granularity = $this->getSetting('granularity');
     $timestamp = $date->getTimestamp();
     $options = ['granularity' => $granularity, 'return_as_object' => TRUE];
     if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
         $result = $this->dateFormatter->formatTimeDiffSince($timestamp, $options);
         $build = ['#markup' => SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $result->getString()])];
     } else {
         $result = $this->dateFormatter->formatTimeDiffUntil($timestamp, $options);
         $build = ['#markup' => SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $result->getString()])];
     }
     CacheableMetadata::createFromObject($result)->applyTo($build);
     return $build;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:24,代码来源:DateTimeTimeAgoFormatter.php



注:本文中的Drupal\Core\Datetime\DrupalDateTime类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP DependencyInjection\ContainerBuilder类代码示例发布时间:2022-05-23
下一篇:
PHP Datetime\DateFormatterInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap