Skip to content

Commit

Permalink
Timezone validation completed
Browse files Browse the repository at this point in the history
  • Loading branch information
SageMar committed Dec 3, 2024
1 parent 4f12d03 commit 6c612b8
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/server/services/csvPipeline/uploadMeters.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ async function uploadMeters(req, res, filepath, conn) {
}
}

const timezone = meter[5];
if (timezone){
if (!isValidTimeZone(timezone)){
let msg = `For meter ${meter[0]}, ${timeSortValue} is not a valid time zone.`;
throw new CSVPipelineError(msg, undefined, 500);
}
}

// Verify area unit provided
const areaUnitString = meter[25];
if (areaUnitString) {
Expand Down Expand Up @@ -221,8 +229,8 @@ function isValidAreaUnit(areaUnit) {
}

/**
* Checks if the area unit provided is an option
* @param timeSortValue the provided area for the meter
* Checks if the time sort value provided is accurate (should be increasing or decreasing)
* @param timeSortValue the provided time sort
* @returns true or false
*/
function isValidTimeSort(timeSortValue) {
Expand All @@ -248,6 +256,21 @@ function isValidMeterType(meterTypeString) {
}
}

/**
* Checks the provided time zone and if it is a real time zone.
* @param zone the provided time zone from the csv
* @returns true or false
*/
function isValidTimeZone(zone) {
// check against the built in timezones, must use a try catch since it does not return a boolean
try {
new Intl.DateTimeFormat(undefined, {timeZone : zone});
return true;
} catch (e) {
return false;
}
}

/**
* Return the id associated with the given unit's name.
* If the unit's name is invalid or its type is different from expected type, return null.
Expand Down

0 comments on commit 6c612b8

Please sign in to comment.