/** * Converts a value from its database representation to its PHP representation * * @param mixed $value The value to convert * @param AbstractPlatform $platform The currently used database platform * * @return mixed * * @throws ConversionException When the conversion fails */ public function convertToPHPValue($value, AbstractPlatform $platform) { if (empty($value)) { return null; } if ($value instanceof Timezone) { return $value; } try { $timezone = Timezone::create($value); } catch (Exception $exception) { throw ConversionException::conversionFailed($value, static::TYPE_NAME); } return $timezone; }
/** * {@inheritdoc} */ public function compareTo($object) : int { if ($this === $object) { return 0; } assert(Validate::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class)); $thisStamp = $this->timestamp(); $thatStamp = $object->timestamp(); if ($thisStamp > $thatStamp) { return 1; } if ($thisStamp < $thatStamp) { return -1; } return $this->timezone->compareTo($object->timezone); }
/** * @expectedException Novuso\System\Exception\DomainException */ public function test_that_constructor_throws_exception_for_invalid_timezone() { Timezone::create('Universal'); }
/** * @expectedException \AssertionError */ public function test_that_compare_to_throws_exception_for_invalid_argument() { $timezone = Timezone::create('UTC'); $timezone->compareTo('America/Chicago'); }