fightbulc / moment.php

Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Other
973 stars 154 forks source link

IsBetween error function #181

Open GrupoWebex opened 5 years ago

GrupoWebex commented 5 years ago

public function isBetween($minDateTime, $maxDateTime, $closed = true, $period = 'seconds')
{
        $isAfter = $this->isAfter($minDateTime, $period);
        $isBefore = $this->isBefore($maxDateTime, $period);
GrupoWebex commented 5 years ago

public function isBetween($minDateTime, $maxDateTime, $closed = true, $period = 'seconds')
{
        $isBefore = $this->isBefore($maxDateTime, $period);
        $isAfter = $this->isAfter($minDateTime, $period);

        // include endpoints
        if ($closed === true)
        {
            $isSameMin = $this->isSame($minDateTime, $period);
            $isSameMax = $this->isSame($maxDateTime, $period);

            return $isSameMin === true || $isSameMax === true 
                    || ($isBefore === true && $isAfter === true);
        }
        return $isBefore === true && $isAfter === true;
}
GrupoWebex commented 2 years ago

Update through composer, i my code stop working cause you dont fix this bug. Please, update on main branch.

Is before = date is before MAXdate, not MINdate Is After = date is after MINdate, not MAXdate

If you include endpoints ($closed = true), have to check if date is same as MINdate if date is same as MAXdate then return $isSameMin === true || $isSameMax === true || ($isBefore === true && $isAfter === true);