Commit bee78fb8 authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

New function: calculate index of end timestamp

parent d159d439
......@@ -93,6 +93,34 @@ const getIndexOfStartTimestamp = function (
}
};
/**
* Calculate the index of an end timestamp in an array of timestamps
*
* @param {Array} inputTimestampArr An array of timestamps, extracted from an array of observations
* @param {String} timestampOfInterest A string representing the timestamp of interest in ISO 8601 format
* @returns {Number} An integer representing the index of the timestamp of interest in the array of timestamps
*/
const getIndexOfEndTimestamp = function (
inputTimestampArr,
timestampOfInterest
) {
const timestampEndIndex = getIndexOfTimestamp(
inputTimestampArr,
timestampOfInterest
);
// If the timestamp does not exist in the timestamp array
if (timestampEndIndex === -1) {
throw new Error(
"An end timestamp could not be found in the timestamp array"
);
}
// If the timestamp exists in the timestamp array
else {
return timestampEndIndex;
}
};
/**
* Calculate the indexes of the start and end timestamps
* @param {Array} obsTimestampArr An array of observations timestamps
......@@ -122,11 +150,11 @@ const calculateIndexStartEndTimestamp = function (
);
// Calculate the indexes of the timestamps for the start and end of interval
const indexStartTimestamp = getIndexOfTimestamp(
const indexStartTimestamp = getIndexOfStartTimestamp(
obsTimestampArr,
startIso8601DateTimeString
);
const indexEndTimestamp = getIndexOfTimestamp(
const indexEndTimestamp = getIndexOfEndTimestamp(
obsTimestampArr,
endIso8601DateTimeString
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment