protected function fixRange($range, $lastTimestamp = null)
    {
        $fixedRange = [];
        $last = null;
        $open = false;

        foreach ($range as $point) {
            if ($this->isStartPoint($point)) {              // start of range
                // the last range could be still open...
                if ($last && $open) {
                    $fixedRange[] = $this->cloneTimePoint($point, TimePoint::TYPE_END);
                }
                $open = true;
            } else if ($this->isEndPoint($point)) {         // end of range
                // this range could not be started...
                if (!$open) {
                    $fixedRange[] = $this->cloneTimePoint($last ? $last : $point, TimePoint::TYPE_START);
                }
                $open = false;
            }
            $fixedRange[] = $point;
            $last = $point;
        }

        // the last range could be still open...
        if ($last && $open) {
            $fixedRange[] = $this->cloneTimePoint($last, TimePoint::TYPE_END, $lastTimestamp);
        }
        
        return $fixedRange;
    }