eZ\Publish\Core\Persistence\Legacy\Tests\Content\FieldValue\Converter\DateAndTimeTest::testToFieldDefinitionWithAdjustmentNoSeconds PHP Method

testToFieldDefinitionWithAdjustmentNoSeconds() public method

    public function testToFieldDefinitionWithAdjustmentNoSeconds()
    {
        $fieldDef = new PersistenceFieldDefinition();
        $seconds = 34;
        $dateInterval = DateInterval::createFromDateString("2 years, 1 month, -4 days, 2 hours, 0 minute, {$seconds} seconds");
        $date = new DateTime();
        $date->add($dateInterval);
        // Removing $seconds as they're not supposed to be taken into account
        $timestamp = $date->getTimestamp() - $seconds;
        $storageDef = new StorageFieldDefinition(array('dataInt1' => DateAndTimeType::DEFAULT_CURRENT_DATE_ADJUSTED, 'dataInt2' => 0, 'dataText5' => $this->getXMLStringFromDateInterval($dateInterval)));
        $this->converter->toFieldDefinition($storageDef, $fieldDef);
        self::assertInternalType('array', $fieldDef->defaultValue->data);
        self::assertCount(2, $fieldDef->defaultValue->data);
        self::assertNull($fieldDef->defaultValue->data['rfc850']);
        self::assertGreaterThanOrEqual($timestamp, $fieldDef->defaultValue->data['timestamp']);
        // Giving a margin of 1 second for test execution
        self::assertLessThanOrEqual($timestamp + 1, $fieldDef->defaultValue->data['timestamp']);
    }