private function fillGapsInTimeUnitsData(Period $period, string $timeUnit, bool $tsAscending)
    {
        // Moment library does not validate time units that being passed just falls back to the default behavior
        // automatically. We do want to let this library's users know that they have provided an invalid time
        // unit to this function and they should rather use the "non-optimized" methods from the controller for
        // retrieving data for these time periods.
        if (in_array($timeUnit, ['decade', 'century', 'millennium'])) {
            throw new \InvalidArgumentException("The {$timeUnit} time unit is not supported by the https://github.com/fightbulc/moment.php library.");
        }
        $allTimeUnits = [];
        // Fix time unit for correct time interval calculation.
        $startDate = new Moment('@' . $period->getStartDate()->getTimestamp());
        $endDate = new Moment('@' . $period->getEndDate()->getTimestamp());
        // Returned intervals by Apigee Edge are always inclusive-inclusive.
        $startDate->startOf($timeUnit);
        $endDate->endOf($timeUnit);
        $period = new Period($startDate, $endDate);
        $timeUnit = '1 ' . $timeUnit;
        /** @var \DateTime $dateTime */
        foreach ($period->getDatePeriod($timeUnit) as $dateTime) {
            $allTimeUnits[] = $dateTime->getTimestamp() * 1000;
        }

        return $tsAscending ? $allTimeUnits : array_reverse($allTimeUnits);
    }