Skip to content

Commit

Permalink
Fix date strings for Firefox & allow MS Excel
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Aug 6, 2022
1 parent 31c5391 commit 407e444
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion website/src/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function handleFiles(files) {

function checkMetadataForFile(file) {
if (file.type) {
if (file.type != 'text/csv') {
// Allow CSV and Microsoft Excel CSV
if (file.type != 'text/csv' && file.type != 'application/vnd.ms-excel') {
alert(`Must be a CSV file, but you uploaded this type: ${file.type}`);
return false;
}
Expand Down
15 changes: 13 additions & 2 deletions website/src/dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ class CbData {
this.title = data['post_title'];
this.status = data['post_status'];
this.type = data['type'];
this.startDate = new Date(data['repetition-start']);
this.endDate = new Date(data['repetition-end']);

// Dates
const beginDateStr = convertToParsableDateString(data['repetition-start']);
const endDateStr = convertToParsableDateString(data['repetition-end']);
this.startDate = new Date(beginDateStr);
this.endDate = new Date(endDateStr);

this.station = data['location-post_title'];
this.item = data['item-post_title'];
this.user = new User({
Expand Down Expand Up @@ -47,4 +52,10 @@ function constructDTOFromCSVArray(csv) {
}

return bookings
}

function convertToParsableDateString(dateStr) {
// Commons Booking has this format: 25. May 2022
// we get back: 25 May 2022 (this is parsable by Date.parse())
return dateStr.replaceAll('.', '');
}
4 changes: 2 additions & 2 deletions website/src/evaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function evaluateBookingsPerWeek(bookings) {
}

const dates = getDatesInRange(booking.startDate, booking.endDate);
for (date of dates) {
for (const date of dates) {
const weekNumber = getIsoWeekNumber(date);
results[year][weekNumber - 1] += 1;
}
Expand All @@ -33,7 +33,7 @@ function evaluateBookingsPerWeekday(bookings) {
results[year] = [0, 0, 0, 0, 0, 0, 0] // Monday to Sunday

const dates = getDatesInRange(booking.startDate, booking.endDate);
for (date of dates) {
for (const date of dates) {
const weekDay = getIsoWeekday(date);
results[year][weekDay - 1] += 1;
}
Expand Down

0 comments on commit 407e444

Please sign in to comment.