From ec6305086eda98d5bdada1863d5e26ad0f04d55f Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 22 Apr 2022 02:32:49 +0000 Subject: [PATCH] Change implementation of Test.dateString --- lib/Test.js | 23 +++++++++-------------- lib/TestResult.js | 2 +- lib/TestTemplate.js | 2 +- routes/report.js | 2 +- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/Test.js b/lib/Test.js index 530b150..b7236ca 100644 --- a/lib/Test.js +++ b/lib/Test.js @@ -1,4 +1,3 @@ -/* eslint-disable no-empty-function, getter-return */ 'use strict'; const { EmailBuilder, Emailer } = require('./Emailer'); @@ -118,14 +117,18 @@ class Test { ); } - get dateString() { - return this.date.toLocaleDateString('en-GB', { + getDateString(long = true) { + const options = { timeZone: 'Europe/London', - weekday: 'long', day: 'numeric', month: 'numeric', year: 'numeric' - }); + }; + + if (long) + options.weekday = 'long'; + + return this.date.toLocaleDateString('en-GB', options); } async getTestResults() { @@ -163,7 +166,7 @@ class Test { .setBody( 'Your result has been added for ' + `the test "${this.template.name}" that you ` + - `took on ${this.dateString}\n\n` + + `took on ${this.getDateString()}\n\n` + `You scored ${mark}/${this.template.maxMark} ` + `(${tr.percentage}%) which is a grade ` + `${tr.grade}` @@ -197,14 +200,6 @@ class Test { return t.id === this.id; }).length; } - - calculateAverageScore() { - - } - - calculateGradeBoundaries() { - - } } module.exports = Test; diff --git a/lib/TestResult.js b/lib/TestResult.js index c81fbf8..11acbcc 100644 --- a/lib/TestResult.js +++ b/lib/TestResult.js @@ -101,7 +101,7 @@ class TestResult { let body = 'Your result has been changed for ' + `the test "${this.test.template.name}" ` + 'that you took on ' + - `${this.test.dateString}\n\n` + + `${this.test.getDateString()}\n\n` + `Your previous result was ${this.mark}/` + `${this.test.template.maxMark} ` + `(${this.percentage}%) which was a grade ` + diff --git a/lib/TestTemplate.js b/lib/TestTemplate.js index cc7a9b2..c19532b 100644 --- a/lib/TestTemplate.js +++ b/lib/TestTemplate.js @@ -144,7 +144,7 @@ class TestTemplate { .setBody( `New test added for class ${c.name}:\n` + `Test name: ${this.name}\n` + - `Test date: ${t.dateString}\n` + + `Test date: ${t.getDateString()}\n` + `Maximum mark: ${this.maxMark}` ); diff --git a/routes/report.js b/routes/report.js index 7e9fd8c..8e8fd9b 100644 --- a/routes/report.js +++ b/routes/report.js @@ -48,7 +48,7 @@ router.get('/reports', async (req, res) => { id: t.id, name: `${t.template.name} - ` + `${t.class.name} - ` + - `${t.dateString}` + `${t.getDateString()}` })) }) });