public findClosestDataPointByDate()

in src/converter/data/dataConverter.ts [127:156]


    public findClosestDataPointByDate(
        dataPoints: IDataRepresentationPoint[],
        date: Date,
        defaultDataPoint: IDataRepresentationPoint,
    ): IDataRepresentationPoint {
        if (!dataPoints || !date || !(date instanceof Date)) {
            return defaultDataPoint;
        }

        const dateTime: number = date.getTime();

        let closestDataPoint: IDataRepresentationPoint;

        for (const dataPoint of dataPoints) {
            const currentTime: number = dataPoint.x.getTime();

            if (currentTime === dateTime) {
                closestDataPoint = dataPoint;

                break;
            }
            else if (currentTime < dateTime) {
                closestDataPoint = dataPoint;
            } else {
                break;
            }
        }

        return closestDataPoint || defaultDataPoint;
    }