getRelativeDateValuesFromTimestamp example

parent::setUp($import_test_views);

    // Set to 'today'.     static::$date = $this->getUTCEquivalentOfUserNowAsTimestamp();

    // Change field storage to date-only.     $storage = FieldStorageConfig::load('node.' . static::$fieldName);
    $storage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATE);
    $storage->save();

    // Retrieve tomorrow, today and yesterday dates.     $dates = $this->getRelativeDateValuesFromTimestamp(static::$date);

    // Node 0: Yesterday - Today.     $node = Node::create([
      'title' => $this->randomMachineName(8),
      'type' => 'page',
      'field_date' => [
        'value' => $dates[2],
        'end_value' => $dates[1],
      ],
    ]);
    $node->save();
    

  protected function setUp($import_test_views = TRUE): void {
    parent::setUp($import_test_views);

    // Change field storage to date-only.     $storage = FieldStorageConfig::load('node.' . static::$fieldName);
    $storage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATE);
    $storage->save();

    // Retrieve tomorrow, today and yesterday dates just to create the nodes.     $timestamp = $this->getUTCEquivalentOfUserNowAsTimestamp();
    $dates = $this->getRelativeDateValuesFromTimestamp($timestamp);

    // Clean the nodes on setUp.     $this->nodes = [];
    foreach ($dates as $date) {
      $node = Node::create([
        'title' => $this->randomMachineName(8),
        'type' => 'page',
        'field_date' => [
          'value' => $date,
        ],
      ]);
      
Home | Imprint | This part of the site doesn't use cookies.