From bd9563554e5fd2cc301e2cd05d8c87180fdf5644 Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:59:25 +0000 Subject: [PATCH 1/2] Add switch to convert month number to names. --- lambda/export-variance/invokable/index.js | 48 ++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/lambda/export-variance/invokable/index.js b/lambda/export-variance/invokable/index.js index 8d68fc0..c13c705 100644 --- a/lambda/export-variance/invokable/index.js +++ b/lambda/export-variance/invokable/index.js @@ -236,7 +236,7 @@ function formatRecords(records) { } const date = record.pk.split('::')[2]; record['year'] = date.slice(0, 4); - record['month'] = date.slice(4); + record['month'] = convertMonth(parseInt(date.slice(4))); } } @@ -282,4 +282,50 @@ async function uploadToS3(csvData) { } logger.debug("Uploaded to S3"); +} + +function convertMonth(monthNumber){ + let monthName; + + switch (monthNumber) { + case 1: + monthName = 'January'; + break; + case 2: + monthName = 'February'; + break; + case 3: + monthName = 'March'; + break; + case 4: + monthName = 'April'; + break; + case 5: + monthName = 'May'; + break; + case 6: + monthName = 'June'; + break; + case 7: + monthName = 'July'; + break; + case 8: + monthName = 'August'; + break; + case 9: + monthName = 'September'; + break; + case 10: + monthName = 'October'; + break; + case 11: + monthName = 'November'; + break; + case 12: + monthName = 'December'; + break; + default: + monthName = `Invalid month: ${monthNumber}`; + } + return monthName } \ No newline at end of file From f90b723c929d2e392e0bd3b136a7acdab3a95548 Mon Sep 17 00:00:00 2001 From: Christopher-walsh22 <106549296+Christopher-walsh22@users.noreply.github.com> Date: Thu, 26 Oct 2023 18:39:30 +0000 Subject: [PATCH 2/2] Changed switch statement to recommended format --- lambda/export-variance/invokable/index.js | 53 +++++------------------ 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/lambda/export-variance/invokable/index.js b/lambda/export-variance/invokable/index.js index c13c705..3a19663 100644 --- a/lambda/export-variance/invokable/index.js +++ b/lambda/export-variance/invokable/index.js @@ -285,47 +285,16 @@ async function uploadToS3(csvData) { } function convertMonth(monthNumber){ - let monthName; - - switch (monthNumber) { - case 1: - monthName = 'January'; - break; - case 2: - monthName = 'February'; - break; - case 3: - monthName = 'March'; - break; - case 4: - monthName = 'April'; - break; - case 5: - monthName = 'May'; - break; - case 6: - monthName = 'June'; - break; - case 7: - monthName = 'July'; - break; - case 8: - monthName = 'August'; - break; - case 9: - monthName = 'September'; - break; - case 10: - monthName = 'October'; - break; - case 11: - monthName = 'November'; - break; - case 12: - monthName = 'December'; - break; - default: - monthName = `Invalid month: ${monthNumber}`; + + const months = [ + 'January', 'February', 'March', 'April', 'May', 'June', + 'July', 'August', 'September', 'October', 'November', 'December' + ]; + + if (monthNumber >= 1 && monthNumber <= 12) { + return months[monthNumber - 1]; + } else { + return 'Invalid month number'; } - return monthName + } \ No newline at end of file