Giannoudis / TimePeriodLibrary

Extensive time period calculations and individual calendar periods.
MIT License
343 stars 94 forks source link

Divide a TimeRange in contiguous equal TimeRanges ? #7

Closed Larry57 closed 1 year ago

Larry57 commented 4 years ago

To be able to plot a huge set of data points between a start date and an end date, I am performing data decimation.

So, to keep an accurate curve shape, I need to subdivise the TimeRange (from start to end) by an amount of pixels to obtain equally sized contiguous TimeRanges, and performs a decimation algorithm with all the points in every TimeRanges.

I am looking for something like a "/" operator or a TimePeriodDivider to split the root TimeRange to many TimeRanges, but I have not found anything yet about how to proceed.

Is this feature implemented ?

Thank you for your help.

Giannoudis commented 1 year ago

You can use the duration of a period and divide it.

public void TimeDivide()
{
    var timePeriod = new Month(2023, YearMonth.August);

    // half day
    int partCount = 62;
    var partSize = (timePeriod.Duration.Ticks / partCount) + 1;
    for (var i = 0; i < partCount; i++)
    {
        var start = timePeriod.Start.AddTicks(i * partSize);
        var end = start.AddTicks(partSize - 1);
        var timeRange = new TimeRange(start, end);
        Console.WriteLine($"Part {i + 1}: {timeRange}");
    }
}
Giannoudis commented 1 year ago

See previous post.