Interesting, I had issues with the history aggregation but for different reasons.
Looks like @nader.chinichian mentioned that the aggregation worked if it was for just a single time period. Would looping through and calculating the range (one period at a time) help? If so, perhaps the code mentioned here could be applied to this scenario:
Note, this code was used to help resolve issues with daylight savings calculations and did so by looping through day by day (instead of using the history aggregation functions).