Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Treat instances of DateTimeInterface as a value type throughout the API #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TimeToogo
Copy link
Owner

For instance:

$traversable = Traversable::from([
    ['date' => new \DateTime('1/1/2000'), 'message' => '...'],
    ['date' => new \DateTime('1/1/2000'), 'message' => '...'],
    ['date' => new \DateTime('2/1/2000'), 'message' => '...'],
]);

$results = $traversable
    ->groupBy(function ($row) { return $row['date']; })
    ->select(function (ITraversable $group, \DateTime $key) {
        return $key->format('d/m/Y') . ':' . $group->count(); 
    })
    ->asArray();

Due to strict comparisons on the group by this would yield some rather unexpected results:

['01/01/2000:1', '01/01/2000:1', '02/01/2000:1']

When what is actually wanted is:

['01/01/2000:2', '02/01/2000:1']

This PR changes the Identity::hash behaviour such that DateTimes are treated as a value type based on their timestamps (and class name) which would solve this problem.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) to 91.27% when pulling 562d0f1 on datetimes-as-value-type into 00514d8 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 91.24% when pulling e65ae5a on datetimes-as-value-type into e528d48 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) to 91.29% when pulling e65ae5a on datetimes-as-value-type into e528d48 on master.

@@ -4,8 +4,9 @@ dev
- Fix bug when attempting to parse function with a magic scope parameter type hint (eg `function (self $param) { ... }`.
- Implement `Analysis\TolerantExpressionAnalyser` which will convert analysis exceptions into the *mixed* type.
- Add `Providers\DSL\Compilation\Parameters\ParameterCollection::contains` to check whether the collection contains a parameter.
- Add `Providers\DSL\Compilation\Parameters\ParameterCollection::remove` to remove a previously added parameter.\
- Add `Providers\DSL\Compilation\Parameters\ParameterCollection::remove` to remove a previously added parameter.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note (and I know I'm against PHP conventions here), but I like how other languages distinguish :: and # for static/instance methods ;-)

… and timestamp hence treating it as a value type throughout the PINQ API
@coveralls
Copy link

coveralls commented Apr 22, 2015

Coverage Status

Coverage decreased (-1.5%) to 90.903% when pulling 2347367 on datetimes-as-value-type into ad76515 on master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants