1
0
forked from PGL/Clyde
Clyde/frontend/src/scheduleFunctions.js

116 lines
3.1 KiB
JavaScript
Raw Normal View History

2024-04-04 14:44:35 +02:00
import {ref} from 'vue'
2024-04-16 22:03:48 +02:00
2024-04-04 14:44:35 +02:00
export function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [day, month, year].join('-');
}
export function durationCourse(element){
2024-04-09 14:01:23 +02:00
const hour = element.lessonEnd.substring(3,5) -element.lessonStart.substring(3,5);
2024-04-04 14:44:35 +02:00
2024-04-09 14:01:23 +02:00
return (element.lessonEnd - element.lessonStart)%2;
2024-04-04 14:44:35 +02:00
}
export function sortByDate(a, b) {
2024-04-09 14:01:23 +02:00
const nameA = a.lessonStart; // ignore upper and lowercase
const nameB = b.lessonStart; // ignore upper and lowercase
2024-04-04 14:44:35 +02:00
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
}
export function getFirstDay(d){
var date = new Date(d);
return new Date(date.getFullYear(), date.getMonth(), 1);
}
export function matrixFromList(list,weekMonday){
const weekStart = new Date(weekMonday);
const matrix = new Array(7);
for (let i = 0; i < matrix.length; i++) {
matrix[i] = [];
}
for(let key in list){
const temp = list[key];
2024-04-09 14:01:23 +02:00
const day = new Date(list[key].lessonStart);
2024-04-04 14:44:35 +02:00
if((((day.getTime()-weekStart.getTime())/60000)<10080) && (((day.getTime()-weekStart.getTime())/60000)>0)){
matrix[day.getDay()].push(temp);
matrix[day.getDay()].sort((a,b) => sortByDate(a,b));
}
}
return matrix;
}
export function lastDateOfMonth(d){
const date = new Date(d);
const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
return temp.getDate();
}
export function monthFromList(list,month){
const beginning = getFirstDay(month);
const matrix = new Array(lastDateOfMonth(month))
for (let i = 0; i < matrix.length; i++) {
matrix[i] = [];
}
for(let key in list){
const temp = list[key];
2024-04-09 14:01:23 +02:00
const day = new Date(list[key].lessonStart);
2024-04-04 14:44:35 +02:00
if(day.getMonth()==month){
matrix[day.getDate()].push(temp);
matrix[day.getDay()].sort((a,b) => sortByDate(a,b));
}}
return matrix;
}
export function sundayToTheEnd(list){
const newlist = list;
const sunday = newlist.shift();
newlist.push(sunday);
return newlist;
}
export function getDifferenceTime(date1,date2){
return Math.abs((new Date(date2).getTime() - new Date(date1).getTime())/60000);
}
export function getMarginTop(list, index1, index2){
if(index2 < 0){
2024-04-09 14:01:23 +02:00
const temp = new Date(list[index1].lessonStart);
2024-04-04 14:44:35 +02:00
temp.setHours(8,0,0);
2024-04-09 14:01:23 +02:00
return Math.abs((new Date(list[index1].lessonStart).getTime()- temp.getTime())/60000);
2024-04-04 14:44:35 +02:00
}
2024-04-09 14:01:23 +02:00
return Math.abs((new Date(list[index1].lessonStart).getTime()- new Date(list[index2].lessonEnd).getTime())/60000)+getMarginTop(list,index2,index2-1);
2024-04-04 14:44:35 +02:00
}
export function getHoursMinutes(date){
const d = new Date(date);
2024-04-16 22:03:48 +02:00
let hours = [d.getHours().toString().length == 1 ? "0" + d.getHours().toString() : d.getHours()];
return hours+ ":" + d.getMinutes();
2024-04-04 14:44:35 +02:00
}