Happy New Year, 

I've been trying to figure out a solution for the following,

How do I make sure to consolidate every four hours starting from 1am or ending at 9pm,

I've seen discussions advising the use of CalendarInfo but I don't know what's going on under the hood, your response will be very much appreciated.

The below are few variations of what I tried, both failed 😢

private CalendarInfo CustomPeriod(DateTime datetime)
{
    var period = TimeSpan.FromHours(value: 4);
    var start = new DateTime(year: datetime.Year, month: datetime.Month, day: datetime.Day, hour: 1, minute: 0,
        second: 0);
    return new CalendarInfo(start: start, period: period);
}        

private CalendarInfo CustomPeriod(DateTime datetime)
{
    var period = TimeSpan.FromHours(value: 4);
    var start = datetime.RoundDown(TimeSpan.FromMinutes(240));
    return new CalendarInfo(start: start, period: period);
}

 

Victor