You are here

public function DateTimePlusTest::testTimestamp in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testTimestamp()

Tests creating dates from timestamps, and manipulating timezones.

@dataProvider providerTestTimestamp

Parameters

int $input: Input argument for DateTimePlus::createFromTimestamp().

array $initial: An array containing:

  • 'timezone_initial' - Timezone argument for DateTimePlus.
  • 'format_initial' - Format argument for DateTimePlus.
  • 'expected_initial_date' - Expected output from DateTimePlus::format().
  • 'expected_initial_timezone' - Expected output from DateTimePlus::getTimeZone()::getName().
  • 'expected_initial_offset' - Expected output from DateTimePlus::getOffset().

array $transform: An array containing:

  • 'timezone_transform' - Argument to transform date to another timezone via DateTimePlus::setTimezone().
  • 'format_transform' - Format argument to use when transforming date to another timezone.
  • 'expected_transform_date' - Expected output from DateTimePlus::format(), after timezone transform.
  • 'expected_transform_timezone' - Expected output from DateTimePlus::getTimeZone()::getName(), after timezone transform.
  • 'expected_transform_offset' - Expected output from DateTimePlus::getOffset(), after timezone transform.

File

core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php, line 160

Class

DateTimePlusTest
@coversDefaultClass \Drupal\Component\Datetime\DateTimePlus @group Datetime

Namespace

Drupal\Tests\Component\Datetime

Code

public function testTimestamp($input, array $initial, array $transform) {

  // Initialize a new date object.
  $date = DateTimePlus::createFromTimestamp($input, $initial['timezone']);
  $this
    ->assertDateTimestamp($date, $input, $initial, $transform);
}