Release v2.6.19
This commit is contained in:
@@ -1,22 +1,45 @@
|
||||
// Timetable group list page renderer.
|
||||
|
||||
const { renderView } = require('../../../view');
|
||||
const { normalizeTimeZone } = require('../../../../data/timetables');
|
||||
|
||||
function formatNextStartLabel(value, formatDashboardDate) {
|
||||
function formatDateInTimeZone(value, timeZone) {
|
||||
if (!value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const resolvedTimeZone = normalizeTimeZone(timeZone, 'Europe/London');
|
||||
return new Intl.DateTimeFormat('en-US', {
|
||||
timeZone: resolvedTimeZone,
|
||||
month: 'short',
|
||||
day: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: 'numeric',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
function formatNextStartLabel(value, timeZone) {
|
||||
if (!value) {
|
||||
return 'No entries';
|
||||
}
|
||||
|
||||
const label = typeof formatDashboardDate === 'function'
|
||||
? formatDashboardDate(value)
|
||||
: String(value);
|
||||
const label = formatDateInTimeZone(value, timeZone) || String(value);
|
||||
return label || 'No entries';
|
||||
}
|
||||
|
||||
module.exports = function renderTimetableGroupsPage(data, message, currentUser, formatDashboardDate) {
|
||||
module.exports = function renderTimetableGroupsPage(data, message, currentUser) {
|
||||
const timetableGroups = (data.timetableGroups || []).map(function (timetableGroup) {
|
||||
const timeZone = normalizeTimeZone(timetableGroup.timezone, 'Europe/London');
|
||||
return Object.assign({}, timetableGroup, {
|
||||
nextStartLabel: formatNextStartLabel(timetableGroup.next_start_datetime, formatDashboardDate),
|
||||
timeZone: timeZone,
|
||||
nextStartLabel: formatNextStartLabel(timetableGroup.next_start_datetime, timeZone),
|
||||
nextStartValue: timetableGroup.next_start_datetime ? new Date(timetableGroup.next_start_datetime).toISOString() : ''
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user