JSFiddle - React, Tailwind, and code Playground

by sas_sam

JavaScript

// Konstansok
const DAYS_OF_WEEK = ['Hétfő', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek', 'Szombat', 'Vasárnap'];
const START_TIME = 8 * 60; // 8:00 percekben
const END_TIME = 18 * 60; // 18:00 percekben
const LESSON_DURATION = 50;
const MAX_VEHICLES_PER_TEACHER = 2;

// Járművek és kötelező óraszámok
const VEHICLES = {
  '3312': 3,
  '3313': 4,
  '3324': 5,
  '4221': 3,
  '4223': 5,
  '4213': 1
};

// Tanárok és nem elérhető napjaik
const TEACHERS = {
  'Tanár1': ['Hétfő', 'Kedd'],
  'Tanár2': ['Szerda', 'Csütörtök'],
  'Tanár3': ['Péntek', 'Szombat']
};

// Tanulók és gyakorlandó járműveik
const STUDENTS = {
  'Diák1': ['3312', '3313', '3324'],
  'Diák2': ['4221', '4223', '4213'],
  'Diák3': ['3312', '4221', '4223']
};

// Oktatási időszak
const START_DATE = new Date('2024-09-02'); // Hétfő
const END_DATE = new Date('2024-09-30');

// Segédfüggvények
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function getDayName(date) {
  return DAYS_OF_WEEK[date.getDay()];
}

function addDays(date, days) {
  const result = new Date(date);
  result.setDate(result.getDate() + days);
  return result;
}

function getRandomElement(array) {
  return array[Math.floor(Math.random() * array.length)];
}

class Lesson {
  constructor(date, startTime, student, teacher, vehicle) {
    this.date = new Date(date);
    this.startTime = startTime;
    this.student = student;
    this.teacher = teacher;
    this.vehicle = vehicle;
    this.duration = VEHICLES[vehicle] * LESSON_DURATION;
  }

  get endTime() {
    return this.startTime + this.duration;
  }

  toString() {
    const dateStr = this.date.toISOString().split('T')[0].replace(/-/g, '.');
    const startTimeStr = `${Math.floor(this.startTime / 60).toString().padStart(2, '0')}:${(this.startTime % 60).toString().padStart(2, '0')}`;
    const endTimeStr = `${Math.floor(this.endTime / 60).toString().padStart(2, '0')}:${(this.endTime % 60).toString().padStart(2, '0')}`;
    return...