JSFiddle - React, Tailwind, and code Playground

by NerfAnarchist

HTML

<input id="test" />

JavaScript

// date picker code (use the console)
$("#test").val('10-10-2012');
var input_date = $('#test').val(), working_date, first_display_date, current_date, first_of_this, last_of_this, last_display_date, today;
today = new Date();
today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
working_date = new Date(input_date);
if (working_date === 'Invalid Date' || isNaN(working_date)) {
    working_date = new Date(today);
} 
first_display_date = new Date(working_date.getFullYear(), working_date.getMonth(), working_date.getDate());

first_of_this = new Date(first_display_date);
first_of_this.setDate(1);
last_of_this = new Date(first_of_this);
last_of_this.setMonth(last_of_this.getMonth() + 1);
last_of_this.setDate(last_of_this.getDate() - 1);
first_display_date.setDate(1);

while (first_display_date.getDay() > 0) { 
    first_display_date.setDate(first_display_date.getDate() - 1);
}

last_display_date = new Date(last_of_this);
while (last_display_date.getDay() < 6) { 
    last_display_date.setDate(last_display_date.getDate() + 1);
}

current_date = first_display_date;
while (current_date <= last_display_date) {
    if (current_date < first_of_this || current_date > last_of_this) {
        console.log('grey: ' + current_date);
    } else if (current_date.toString('yyyymmdd') === working_date.toString('yyyymmdd') && working_date.toString('yyyymmdd') !==today.toString('yyyymmdd')) {
        console.log('selected date: ' + current_date);
    } else if (current_date.toString('yyyymmdd') === today.toString('yyyymmdd')) {
        console.log('todays date: ' + current_date);
    } else {
        console.log('normal:' + current_date);
    }
    current_date.setDate(current_date.getDate() + 1);
}