setSiteTimezone example

$this->assertIdenticalResultset($view$expected$this->map);
    $view->destroy();

    $view->setDisplay('default');
    $this->executeView($view['2003']);
    $expected = [];
    $expected[] = ['nid' => $this->nodes[3]->id()];
    $this->assertIdenticalResultset($view$expected$this->map);
    $view->destroy();

    // Tests different system timezone with the same nodes.     $this->setSiteTimezone('America/Vancouver');

    $view->setDisplay('default');
    $this->executeView($view['2002']);
    $expected = [];
    // Only the 3rd node is returned here since UTC 2002-01-01T00:00:00 is still     // in 2001 for this user timezone.     $expected[] = ['nid' => $this->nodes[3]->id()];
    $this->assertIdenticalResultset($view$expected$this->map);
    $view->destroy();
  }

  

  public function testDateField() {
    $field_name = $this->fieldStorage->getName();

    $display_repository = \Drupal::service('entity_display.repository');

    // Loop through defined timezones to test that date-only fields work at the     // extremes.     foreach (static::$timezones as $timezone) {

      $this->setSiteTimezone($timezone);
      $this->assertEquals($timezone$this->config('system.date')->get('timezone.default'), 'Time zone set to ' . $timezone);

      // Display creation form.       $this->drupalGet('entity_test/add');
      $this->assertSession()->fieldValueEquals("{$field_name}[0][value][date]", '');
      $this->assertSession()->elementExists('xpath', '//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class,"js-form-required")]');
      $this->assertSession()->fieldNotExists("{$field_name}[0][value][time]");
      // ARIA described-by.       $this->assertSession()->elementExists('xpath', '//input[@aria-describedby="edit-' . $field_name . '-0-value--description"]');
      $this->assertSession()->elementExists('xpath', '//div[@id="edit-' . $field_name . '-0-value--description"]');

      
/** * Tests date field functionality. */
  public function testDateRangeField() {
    $field_name = $this->fieldStorage->getName();
    $field_label = $this->field->label();

    // Loop through defined timezones to test that date-only fields work at the     // extremes.     foreach (static::$timezones as $timezone) {

      $this->setSiteTimezone($timezone);
      $this->assertEquals($timezone$this->config('system.date')->get('timezone.default'), 'Time zone set to ' . $timezone);

      // Ensure field is set to a date-only field.       $this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATE);
      $this->fieldStorage->save();

      // Display creation form.       $this->drupalGet('entity_test/add');
      $this->assertSession()->fieldValueEquals("{$field_name}[0][value][date]", '');
      $this->assertSession()->fieldValueEquals("{$field_name}[0][end_value][date]", '');
      $this->assertSession()->elementExists('xpath', '//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]');
      
$this->submitForm($edit, 'Save settings');

    // Check that default value is selected in default value form.     $this->drupalGet('admin/structure/types/manage/dateonly_content/fields/node.dateonly_content.field_dateonly');
    $option_field = $this->assertSession()->optionExists('edit-default-value-input-default-date-type', 'now');
    $this->assertTrue($option_field->hasAttribute('selected'));
    $this->assertSession()->fieldValueEquals('default_value_input[default_date]', '');

    // Loop through defined timezones to test that date-only defaults work at     // the extremes.     foreach (static::$timezones as $timezone) {
      $this->setSiteTimezone($timezone);
      $this->assertEquals($timezone$this->config('system.date')->get('timezone.default'), 'Time zone set to ' . $timezone);

      // The time of the request is determined very early on in the request so       // use the current time prior to making a request.       $request_time = $this->container->get('datetime.time')->getCurrentTime();
      $this->drupalGet('node/add/dateonly_content');

      $today = $this->dateFormatter->format($request_time, 'html_date', NULL, $timezone);
      $this->assertSession()->fieldValueEquals('field_dateonly[0][value][date]', $today);

      $edit = [
        


  /** * Tests offsets with date-only fields. */
  public function testDateOffsets() {
    $view = Views::getView('test_filter_datetime');
    $field = static::$fieldName . '_value';

    foreach (static::$timezones as $timezone) {

      $this->setSiteTimezone($timezone);
      $timestamp = $this->getUTCEquivalentOfUserNowAsTimestamp();
      $dates = $this->getRelativeDateValuesFromTimestamp($timestamp);
      $this->updateNodesDateFieldsValues($dates);

      // Test simple operations.       $view->initHandlers();

      // A greater than or equal to 'now', should return the 'today' and the       // 'tomorrow' node.       $view->filter[$field]->operator = '>=';
      $view->filter[$field]->value['type'] = 'offset';
      
Home | Imprint | This part of the site doesn't use cookies.