Release v2.6.19
This commit is contained in:
@@ -1,14 +1,40 @@
|
||||
// Shared timetable group form view-model builder.
|
||||
|
||||
const { normalizeTimeZone } = require('../../../../data/timetables');
|
||||
|
||||
const COMMON_TIME_ZONES = [
|
||||
'UTC',
|
||||
'Europe/London',
|
||||
'Europe/Dublin',
|
||||
'Europe/Paris',
|
||||
'Europe/Berlin',
|
||||
'Europe/Madrid',
|
||||
'America/New_York',
|
||||
'America/Chicago',
|
||||
'America/Denver',
|
||||
'America/Los_Angeles',
|
||||
'America/Toronto',
|
||||
'America/Vancouver',
|
||||
'America/Sao_Paulo',
|
||||
'Asia/Dubai',
|
||||
'Asia/Kolkata',
|
||||
'Asia/Singapore',
|
||||
'Asia/Tokyo',
|
||||
'Asia/Seoul',
|
||||
'Australia/Sydney',
|
||||
'Pacific/Auckland'
|
||||
];
|
||||
|
||||
function buildDefaultTimetableGroup() {
|
||||
return {
|
||||
id: null,
|
||||
name: '',
|
||||
shortDescription: ''
|
||||
shortDescription: '',
|
||||
timezone: 'Europe/London'
|
||||
};
|
||||
}
|
||||
|
||||
function formatDateTimeLocalValue(value) {
|
||||
function formatDateTimeLocalValue(value, timeZone) {
|
||||
if (!value) {
|
||||
return '';
|
||||
}
|
||||
@@ -18,22 +44,49 @@ function formatDateTimeLocalValue(value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const year = String(date.getFullYear()).padStart(4, '0');
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}T${hours}:${minutes}`;
|
||||
const resolvedTimeZone = normalizeTimeZone(timeZone, 'Europe/London');
|
||||
const parts = new Intl.DateTimeFormat('en-GB', {
|
||||
timeZone: resolvedTimeZone,
|
||||
hour12: false,
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
}).formatToParts(date).reduce(function (acc, part) {
|
||||
if (part && part.type && part.type !== 'literal') {
|
||||
acc[part.type] = part.value;
|
||||
}
|
||||
return acc;
|
||||
}, Object.create(null));
|
||||
|
||||
if (!parts.year || !parts.month || !parts.day || !parts.hour || !parts.minute) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return [
|
||||
String(parts.year).padStart(4, '0'),
|
||||
'-',
|
||||
String(parts.month).padStart(2, '0'),
|
||||
'-',
|
||||
String(parts.day).padStart(2, '0'),
|
||||
'T',
|
||||
String(parts.hour).padStart(2, '0'),
|
||||
':',
|
||||
String(parts.minute).padStart(2, '0')
|
||||
].join('');
|
||||
}
|
||||
|
||||
function buildTimetableGroupFormViewModel(timetableGroup, timetableEntries, message, currentUser, isEdit, options) {
|
||||
const viewTimetableGroup = Object.assign(buildDefaultTimetableGroup(), timetableGroup || {});
|
||||
viewTimetableGroup.timezone = normalizeTimeZone(viewTimetableGroup.timezone, 'Europe/London');
|
||||
const viewOptions = options || {};
|
||||
const viewTimetableEntries = Array.isArray(timetableEntries) && timetableEntries.length
|
||||
? timetableEntries.map(function (entry) {
|
||||
return Object.assign({}, entry, {
|
||||
startValue: formatDateTimeLocalValue(entry.start_datetime),
|
||||
endValue: formatDateTimeLocalValue(entry.end_datetime)
|
||||
startValue: formatDateTimeLocalValue(entry.start_datetime, viewTimetableGroup.timezone),
|
||||
endValue: formatDateTimeLocalValue(entry.end_datetime, viewTimetableGroup.timezone)
|
||||
});
|
||||
})
|
||||
: [{ id: null, title: '', short_description: '', startValue: '', endValue: '', sort_order: 0 }];
|
||||
@@ -46,6 +99,7 @@ function buildTimetableGroupFormViewModel(timetableGroup, timetableEntries, mess
|
||||
messageVariant: viewOptions.messageVariant || '',
|
||||
isEdit: Boolean(isEdit),
|
||||
timetableGroup: viewTimetableGroup,
|
||||
timeZoneOptions: COMMON_TIME_ZONES,
|
||||
timetableEntries: viewTimetableEntries,
|
||||
inUse: Boolean(viewTimetableGroup.inUse),
|
||||
showSaveSecondaryActions: true,
|
||||
|
||||
Reference in New Issue
Block a user