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);
    }
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);
    }
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 ) ; }
Fills the gaps between returned time units in the response of Apigee Edge.

When there were no metric data for a time unit (hour, day, etc.) then those are missing from Apigee Edge response.
This utility function fixes this problem.

@param Period $period
Original time range from StatsQuery.
@param string $timeUnit
Time unit from StatsQuery.
@param bool $tsAscending

@throws \InvalidArgumentException
If time unit is not supported by the Moment library.
@throws \Moment\MomentException

@return array
Array of time units in the given period.
Fills the gaps between returned time units in the response of Apigee Edge .