JSFiddle - React, Tailwind, and code Playground
HTML
<input type="date" value="2019-01-01" id="dates"> <!-- 火曜日 -->
<input type="time" value="08:00" id="time_start"> <!-- 変更前: 00:00-->
<input type="time" value="10:00" id="time_finish"><!-- 変更前: 23:30 -->
JavaScript
{
const
day_name = [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
day_jname = ['Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.'],
doc = document;
const
A = (e, ...a) => a.map (a => e.appendChild (doc.createElement (a))),
B = (d, n) => d.setDate (d.getDate () + n),
C = d => [d.getFullYear (), '年', d.getMonth () + 1 , '月'].join (''),
D = d => [('0' + d.getHours ()).slice (-2), ('0' + d.getMinutes ()).slice (-2)].join (':'),
E = (e, d) => {
let
[a,,b] = A (e, 'label', 'br', 'label'),
w = d.getDay () ;
a.textContent = d.getDate ();
b.textContent = day_jname[w];
e.classList.add (day_name[w]);
},
F = d => {
let m = d.getMonth ();
return [0,31,59,90,120,151,181,212,243,273,304,334][m] + d.getDate() - 1 +
(new Date (d.getFullYear (), m + 1,0) === 29 && 0 < m);
},
G = ary => ary.reduce ((a, b) => {
let
c = typeof b === 'string' ? new Date (b +':00.000+09:00'): b,
d = D (c);
if (! (d in a)) a[d] = [];
a[d][F(c)] = true;
return a;
}, { })
,
H = d => new Date (d.getFullYear (), d.getMonth (), d.getDate ()),
I = d => [('0' + d.getUTCHours ()).slice (-2), ('0' + d.getUTCMinutes ()).slice (-2)].join (':')
;
class Shedule {
constructor (date = new Date, range = 7, plan = []) {
this.current = H (date);
this.date = H (date);
this.range = range;
this.plan = G (plan);
this.table = document.createElement ('table');
this.remake ();
}
add (day = this.range) {
let d = H (this.current);
d.setDate (d.getDate () + day);
if (+this.date <= +d) {
this.current = d;
this.remake ();
}
}
remake () {
...