Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove end date check if not specified (better 32-bit support) #902

Merged
merged 2 commits into from
Jun 15, 2016

Conversation

Sogl
Copy link
Contributor

@Sogl Sogl commented Jun 15, 2016

Related to #898

I can't find better way to remove it with DRY principle 😑
With smaller code we need to check a value for each $this->items iteration.

Also it can be used with PHP_INT_MAX with previous version of this code.

Artyom Mezin added 2 commits June 15, 2016 11:29
Related to getgrav#898

I can't find better way to remove it with DRY principle 😑
With smaller code we need to check a value for each `$this->items` iteration.

Also it can be used with `PHP_INT_MAX` with previous version of this code.
@flaviocopes
Copy link
Contributor

Want to try this solution? (moved the if inside the loop)

    public function dateRange($startDate, $endDate = false, $field = false)
    {
        $start = Utils::date2timestamp($startDate);
        $end = $endDate ? Utils::date2timestamp($endDate) : false;

        $date_range = [];

        foreach ($this->items as $path => $slug) {
            $page = $this->pages->get($path);
            $add = false;

            if ($page !== null) {
                $date = $field ? strtotime($page->value($field)) : $page->date();

                if ($end) {
                    if ($date >= $start && $date <= $end) {
                        $add = true;
                    }
                } else {
                    if ($date >= $start) {
                        $add = true;
                    }
                }

                if ($add) {
                    $date_range[$path] = $slug;
                }
            }
        }

        $this->items = $date_range;

        return $this;
    }

@Sogl
Copy link
Contributor Author

Sogl commented Jun 15, 2016

It looks better, but brings 3 if conditions on each item iteration...

@flaviocopes flaviocopes merged commit f8964ab into getgrav:develop Jun 15, 2016
@flaviocopes
Copy link
Contributor

Merged yours

Sommerregen added a commit to Sommerregen/grav that referenced this pull request Jun 16, 2016
@Sommerregen Sommerregen mentioned this pull request Jun 16, 2016
flaviocopes pushed a commit that referenced this pull request Jun 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants