diff --git a/public/js/src_modules/aggregateHelpers.mjs b/public/js/src_modules/aggregateHelpers.mjs index 85c1583e80d34174eed88809a77c7e5cb15bad98..a79dd97a160a56e3aa97f3c0c6a0accc2f98991f 100644 --- a/public/js/src_modules/aggregateHelpers.mjs +++ b/public/js/src_modules/aggregateHelpers.mjs @@ -60,19 +60,36 @@ const checkIfLeapYear = function (year) { * @returns {Number} An integer representing the index of the timestamp of interest in the array of timestamps */ const getIndexOfTimestamp = function (inputTimestampArr, timestampOfInterest) { - const timestampIndex = inputTimestampArr.findIndex( + return inputTimestampArr.findIndex( (timestamp) => timestamp === timestampOfInterest ); +}; + +/** + * Calculate the index of a start 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 getIndexOfStartTimestamp = function ( + inputTimestampArr, + timestampOfInterest +) { + const timestampStartIndex = getIndexOfTimestamp( + inputTimestampArr, + timestampOfInterest + ); // If the timestamp does not exist in the timestamp array - if (timestampIndex === -1) { + if (timestampStartIndex === -1) { throw new Error( - "A start or end timestamp could not be found in the timestamp array" + "A start timestamp could not be found in the timestamp array" ); } // If the timestamp exists in the timestamp array else { - return timestampIndex; + return timestampStartIndex; } };