You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: timeperiods.go
    path of file: ./repos/gocryptotrader/common/timeperiods
    
    the code of the file until where you have to start completion: package timeperiods

import (
	"errors"
	"sort"
	"time"

	"github.com/thrasher-corp/gocryptotrader/common"
)

// FindTimeRangesContainingData will break the start and end into time periods using the provided period
// it will then check whether any comparisonTim
    
func (t *TimePeriodCalculator) calculateRanges() {
	var tr TimeRange
	for i := range t.TimePeriods {
		if i != 0 {
			if (t.TimePeriods[i].dataInRange && !t.TimePeriods[i-1].dataInRange) ||
				(!t.TimePeriods[i].dataInRange && t.TimePeriods[i-1].dataInRange) {
				// the status has changed and therefore a range has ended
				tr.HasDataInRange = t.TimePeriods[i-1].dataInRange
				tr.EndOfRange = t.TimePeriods[i].Time
				t.TimeRanges = append(t.TimeRanges, tr)
				tr = TimeRange{}
			}
		}
		if tr.StartOfRange.IsZero() {
			// start of new time range
			tr.StartOfRange = t.TimePeriods[i].Time
		}
	}
	if !tr.StartOfRange.IsZero() {
		if tr.EndOfRange.IsZero() {
			tr.EndOfRange = t.end
		}
		tr.HasDataInRange = t.TimePeriods[len(t.TimePeriods)-1].dataInRange
		t.TimeRanges = append(t.TimeRanges, tr)
	}
}