Overview

Namespaces

  • PhpCommon
    • Comparison
      • Equivalence
      • Hasher

Classes

  • DateTimeHasher
  • GenericHasher
  • IdentityHasher
  • ValueHasher
  • Overview
  • Namespace
  • Class

Class DateTimeHasher

An equivalence relation to determine whether two instances of DateTime have the same date, time and time zone.

PhpCommon\Comparison\Hasher\DateTimeHasher implements PhpCommon\Comparison\Hasher
Namespace: PhpCommon\Comparison\Hasher
Author: Marcos Passos marcos@croct.com
Located at Hasher/DateTimeHasher.php
Methods summary
public boolean
# equals( PhpCommon\Comparison\Equatable $other )

Checks whether the current relation is considered equal to another.

Checks whether the current relation is considered equal to another.

Since this class is stateless, its instances will always be considered equal if they are of the same type.

Parameters

$other
The value to compare to.

Returns

boolean

Returns true if the current object is equal to the specified object, false otherwise.

Implementation of

PhpCommon\Comparison\Equatable::equals()
public boolean
# equivalent( DateTimeInterface $left, mixed $right )

Checks whether the given values are considered equivalent.

Checks whether the given values are considered equivalent.

This equivalence relation considers two instances of DateTimeInterface to be equivalent if they have the same date, time and time zone.

Parameters

$left
The date/time to compare.
$right
The value to compare.

Returns

boolean

Returns true if the date/time are considered equivalent, false otherwise.

Throws

PhpCommon\Comparison\UnexpectedTypeException

If the type of the left-hand side does not match the expected type.


IncomparableException

If the given values are not comparable under the specified equivalence relation.

Implementation of

PhpCommon\Comparison\Equivalence::equivalent()
public integer
# hash( DateTimeInterface $value )

Returns a hash code for the given DateTime instance.

Returns a hash code for the given DateTime instance.

The resulting hash code is guaranteed to be coherent with the PhpCommon\Comparison\Hasher\DateTimeHasher::equivalent() method, which means that for any references $x and $y, if equivalent($x, $y), then hash($x) === hash($y). It is computed by summing the values returned by the methods \DateTimeInterface::getTimestamp() and \DateTimeInterface::getOffset(), as shown in the following expression:

$hashCode = $date->getTimestamp() + $date->getOffset();

Parameters

$value
The date/time to compare.

Returns

integer
The hash code.

Throws

PhpCommon\Comparison\UnexpectedTypeException

If the type of the specified value does not match the expected type.


InvalidArgumentException

If some property of the specified value prevents it from being hashed.

See

PhpCommon\Comparison\Hasher\DateTimeHasher::equivalent()

Implementation of

PhpCommon\Comparison\Hasher::hash()
protected
# assertDateTime( mixed $value )

Asserts the given value is an instance of DateTimeInterface.

Asserts the given value is an instance of DateTimeInterface.

Parameters

$value
The value to assert.

Throws

PhpCommon\Comparison\UnexpectedTypeException

If the given value is not an instance of DateTimeInterface.

PHPCommon Comparison API API documentation generated by ApiGen