These are chat archives for camperbot/bonfire-friendly-date-ranges

3rd
Mar 2016
Gagandeep Singh
@Guggu
Mar 03 2016 15:02
image.png

function friendly(arr) {
var startDate = new Date(arr[0]),
endDate = new Date(arr[1]);

var startYear = startDate.getFullYear(),
startMonth = startDate.getMonth(),
startDay = startDate.getDate();

var endYear = endDate.getFullYear(),
endMonth = endDate.getMonth(),
endDay = endDate.getDate();

var monthNames = ['January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'];

if (startDate.getTime() === endDate.getTime()) {
return [monthNames[startMonth] + ' ' + addEnding(startDay) + ', ' + startYear];
} else if (startYear === endYear && startMonth === endMonth) {
return [monthNames[startMonth] + ' ' + addEnding(startDay), addEnding(endDay)];
} else if (((startYear === new Date().getFullYear() && (startYear === endYear || startYear === endYear - 1)) || startYear === endYear) && startMonth != endMonth) {
return [monthNames[startMonth] + ' ' + addEnding(startDay), monthNames[endMonth] + ' ' + addEnding(endDay)];
} else {
// Any other case returns something like this: ['January 25th, 2020', 'October 23rd, 2045']
return [monthNames[startMonth] + ' ' + addEnding(startDay) + ', ' + startYear, monthNames[endMonth] + ' ' + addEnding(endDay) + ', ' + endYear];
}

function addEnding(day) {
if (day === 1 || day === 21 || day === 31) {
return day + 'st';
} else if (day === 2 || day === 22) {
return day + 'nd';
} else if (day === 3 || day === 23) {
return day + 'rd';
} else {
return day + 'th';
}
}
}

this is the code

and I got an error in this field