DateTimeZone example

// whitespaces             'ideographic space' => ["' '", ' '],
            'ideographic space surrounded by characters' => ["'a b'", 'a b'],
        ];
    }

    /** * @dataProvider getTimestampTests */
    public function testParseTimestampAsUnixTimestampByDefault(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond)
    {
        $expectedDate = (new \DateTimeImmutable($yamlnew \DateTimeZone('UTC')))->format('U');
        $this->assertSame($microsecond ? (float) "$expectedDate.$microsecond" : (int) $expectedDate, Inline::parse($yaml));
    }

    /** * @dataProvider getTimestampTests */
    public function testParseTimestampAsDateTimeObject(string $yaml, int $year, int $month, int $day, int $hour, int $minute, int $second, int $microsecond, string $timezone)
    {
        $expected = (new \DateTimeImmutable($yaml))
            ->setTimeZone(new \DateTimeZone('UTC'))
            ->setDate($year$month$day)
            
'parent' => $expected_parent_normalization,
      'weight' => [
        ['value' => 0],
      ],
      'langcode' => [
        [
          'value' => 'en',
        ],
      ],
      'changed' => [
        [
          'value' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'default_langcode' => [
        [
          'value' => TRUE,
        ],
      ],
      'path' => [
        [
          'alias' => '/llama',
          

    public function testSign(int $time, string $bodyCanon, string $headerCanon, string $header)
    {
        ClockMock::withClockMock($time);

        $message = (new Email())
            ->from(new Address('fabien@testdkim.symfony.net', 'Fabién'))
            ->to('fabien.potencier@gmail.com')
            ->subject('Tést')
            ->text("Some body \n \n This \r\n\r\n is really interesting and at the same time very long line to see if everything works as expected, does it?\r\n\r\n\r\n\r\n")
            ->date(new \DateTimeImmutable('2005-10-15', new \DateTimeZone('Europe/Paris')));

        $signer = new DkimSigner(self::$pk, 'testdkim.symfony.net', 'sf');
        $signedMessage = $signer->sign($message[
            'header_canon' => $headerCanon,
            'body_canon' => $bodyCanon,
            'headers_to_ignore' => ['Message-ID'],
        ]);

        $this->assertSame($message->getBody()->toString()$signedMessage->getBody()->toString());
        $this->assertTrue($signedMessage->getHeaders()->has('DKIM-Signature'));
        $this->assertEquals($header$signedMessage->getHeaders()->get('DKIM-Signature')->getBody());
    }

  protected $allowedFormats = [
    'UNIX timestamp' => 'U',
    'ISO 8601' => \DateTime::ISO8601,
    'RFC 3339' => \DateTime::RFC3339,
  ];

  /** * {@inheritdoc} */
  protected function getNormalizationTimezone() {
    return new \DateTimeZone('UTC');
  }

  /** * {@inheritdoc} */
  public function denormalize($data$class$format = NULL, array $context = []): mixed {
    $denormalized = parent::denormalize($data$class$format$context);
    return $denormalized->getTimestamp();
  }

  /** * {@inheritdoc} */

        return $this->dateFormats;
    }

    /** * Sets the default timezone to be used by the date filter. * * @param \DateTimeZone|string $timezone The default timezone string or a \DateTimeZone object */
    public function setTimezone($timezone)
    {
        $this->timezone = $timezone instanceof \DateTimeZone ? $timezone : new \DateTimeZone($timezone);
    }

    /** * Gets the default timezone to be used by the date filter. * * @return \DateTimeZone The default timezone currently in use */
    public function getTimezone()
    {
        if (null === $this->timezone) {
            $this->timezone = new \DateTimeZone(date_default_timezone_get());
        }
'type' => 'menu_link_content--menu_link_content',
        'links' => [
          'self' => ['href' => $self_url->toString()],
        ],
        'attributes' => [
          'bundle' => 'menu_link_content',
          'link' => [
            'uri' => 'https://nl.wikipedia.org/wiki/Llama',
            'title' => NULL,
            'options' => [],
          ],
          'changed' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'default_langcode' => TRUE,
          'description' => 'Llama Gabilondo',
          'enabled' => TRUE,
          'expanded' => FALSE,
          'external' => FALSE,
          'langcode' => 'en',
          'menu_name' => 'main',
          'parent' => NULL,
          'rediscover' => FALSE,
          'title' => 'Llama Gabilondo',
          'weight' => 0,
          
if (0 < $us = $seconds - $s) {
            usleep((int) ($us * 1E6));
        }
    }

    /** * @throws \DateInvalidTimeZoneException When $timezone is invalid */
    public function withTimeZone(\DateTimeZone|string $timezone)static
    {
        if (\PHP_VERSION_ID >= 80300 && \is_string($timezone)) {
            $timezone = new \DateTimeZone($timezone);
        } elseif (\is_string($timezone)) {
            try {
                $timezone = new \DateTimeZone($timezone);
            } catch (\Exception $e) {
                throw new \DateInvalidTimeZoneException($e->getMessage()$e->getCode()$e);
            }
        }

        $clone = clone $this;
        $clone->timezone = $timezone;

        
return $file;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    return [
      'changed' => [
        [
          'value' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'created' => [
        [
          'value' => (new \DateTime())->setTimestamp((int) $this->entity->getCreatedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'fid' => [
        [
          
'empty_data' => $emptyData,
        ]);
        $form->submit(null);

        $this->assertSame($emptyData$form->getViewData());
        $this->assertSame($expectedData$form->getNormData());
        $this->assertSame($expectedData$form->getData());
    }

    public function testDateTimeZoneInput()
    {
        $form = $this->factory->create(static::TESTED_TYPE, new \DateTimeZone('America/New_York')['input' => 'datetimezone']);

        $this->assertSame('America/New_York', $form->createView()->vars['value']);

        $form->submit('Europe/Amsterdam');

        $this->assertEquals(new \DateTimeZone('Europe/Amsterdam')$form->getData());

        $form = $this->factory->create(static::TESTED_TYPE, [new \DateTimeZone('America/New_York')]['input' => 'datetimezone', 'multiple' => true]);

        $this->assertSame(['America/New_York']$form->createView()->vars['value']);

        
public function testSupportsDenormalization() {
    $this->assertTrue($this->normalizer->supportsDenormalization($this->data->reveal(), Timestamp::class));
  }

  /** * @covers ::normalize */
  public function testNormalize() {
    $random_rfc_3339_string = $this->randomMachineName();

    $drupal_date_time = $this->prophesize(TimestampNormalizerTestDrupalDateTime::class);
    $drupal_date_time->setTimezone(new \DateTimeZone('UTC'))
      ->willReturn($drupal_date_time->reveal());
    $drupal_date_time->format(\DateTime::RFC3339)
      ->willReturn($random_rfc_3339_string);

    $this->data->getDateTime()
      ->willReturn($drupal_date_time->reveal());

    $normalized = $this->normalizer->normalize($this->data->reveal());
    $this->assertSame($random_rfc_3339_string$normalized);
  }

  
$timeZone = $connection->executeQuery('SELECT @@SESSION.time_zone')->fetchOne();

            if ($timeZone === 'SYSTEM') {
                $timeZone = $connection->executeQuery('SELECT @@system_time_zone')->fetchOne();
            }
        } catch (PDOException $e) {
        }

        if (!empty($timeZone)) {
            $databaseZone = null;
            if (\in_array($timeZone[0]['-', '+'], true)) {
                $databaseZone = new DateTimeZone($timeZone);
            } else {
                $timeZoneFromAbbr = timezone_name_from_abbr($timeZone);
                if (\is_string($timeZoneFromAbbr)) {
                    $databaseZone = timezone_open($timeZoneFromAbbr);
                    if (!$databaseZone instanceof DateTimeZone) {
                        $databaseZone = null;
                    }
                }
            }

            $phpZone = timezone_open(date_default_timezone_get());
            

          'value' => static::$entityTypeId,
        ],
      ],
      'name' => [
        [
          'value' => 'Llama',
        ],
      ],
      'created' => [
        [
          'value' => (new \DateTime())->setTimestamp((int) $this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'user_id' => [
        [
          'target_id' => (int) $author->id(),
          'target_type' => 'user',
          'target_uuid' => $author->uuid(),
          'url' => $author->toUrl()->toString(),
        ],
      ],
      

        parent::tearDown();

        date_default_timezone_set($this->previousTimezone);
    }

    /** * @dataProvider provideDateTimes */
    public function testDumpDateTime($time$timezone$xDate$xTimestamp)
    {
        $date = new \DateTime($timenew \DateTimeZone($timezone));

        $xDump = <<<EODUMP DateTime @$xTimestamp { date: $xDate } EODUMP;

        $this->assertDumpEquals($xDump$date);
    }

    /** * @dataProvider provideDateTimes */
$form->submit([
            'day' => '',
            'month' => '',
            'year' => '',
        ]);

        $this->assertTrue($form->isSynchronized());
    }

    public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyFilled()
    {
        $form = $this->factory->create(static::TESTED_TYPE, new \DateTime('now', new \DateTimeZone('UTC'))[
            'model_timezone' => 'UTC',
            'view_timezone' => 'UTC',
            'widget' => 'choice',
        ]);

        $form->submit([
            'day' => '1',
            'month' => '6',
            'year' => '2010',
        ]);

        
return $formattedErrors;
    }

    private function getTimezone(array $context): ?\DateTimeZone
    {
        $dateTimeZone = $context[self::TIMEZONE_KEY] ?? $this->defaultContext[self::TIMEZONE_KEY];

        if (null === $dateTimeZone) {
            return null;
        }

        return $dateTimeZone instanceof \DateTimeZone ? $dateTimeZone : new \DateTimeZone($dateTimeZone);
    }
}
Home | Imprint | This part of the site doesn't use cookies.