Final Schedule - merge
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
import {ref} from 'vue'
|
||||
|
||||
|
||||
/*
|
||||
* Get a date object in a date format dd-mm-yyyy
|
||||
*/
|
||||
export function formatDate(date) {
|
||||
var d = new Date(date),
|
||||
month = '' + (d.getMonth() + 1),
|
||||
@ -14,8 +17,33 @@
|
||||
return [day, month, year].join('-');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get a date object in a date format yyyy-mm-dd
|
||||
*/
|
||||
export function invertedFormatDate(date) {
|
||||
let 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 [year, month, day].join('-');
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a string date via the hour and the date
|
||||
*/
|
||||
export function createLessonEvent(date,hour){
|
||||
const str = date.concat(' ',hour);
|
||||
return new Date(str);
|
||||
}
|
||||
/*
|
||||
* Get the duration of a lesson
|
||||
*/
|
||||
export function durationCourse(element){
|
||||
const hour = element.lessonEnd.substring(3,5) -element.lessonStart.substring(3,5);
|
||||
|
||||
@ -23,6 +51,9 @@
|
||||
return (element.lessonEnd - element.lessonStart)%2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Help to sort lessons chronologically
|
||||
*/
|
||||
export function sortByDate(a, b) {
|
||||
const nameA = new Date(a.lessonStart); // ignore upper and lowercase
|
||||
const nameB = new Date(b.lessonStart); // ignore upper and lowercase
|
||||
@ -36,15 +67,18 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get the first day of the current month
|
||||
*/
|
||||
export function getFirstDay(d){
|
||||
var date = new Date(d);
|
||||
return new Date(date.getFullYear(), date.getMonth(), 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function matrixFromList(list,weekMonday){
|
||||
/*
|
||||
* Convert a list of lesson to a schedule in a week
|
||||
*/
|
||||
export function weekFromList(list, weekMonday){
|
||||
const weekStart = new Date(weekMonday);
|
||||
const matrix = new Array(7);
|
||||
for (let i = 0; i < matrix.length; i++) {
|
||||
@ -61,12 +95,18 @@
|
||||
return matrix;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the last date of a month
|
||||
*/
|
||||
export function lastDateOfMonth(d){
|
||||
const date = new Date(d);
|
||||
const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
||||
return temp.getDate();
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a list of lesson to a schedule in a month
|
||||
*/
|
||||
|
||||
export function monthFromList(list,month){
|
||||
const beginning = getFirstDay(month);
|
||||
const matrix = new Array(lastDateOfMonth(month))
|
||||
@ -84,9 +124,11 @@
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Put the first element of a weekly schedule (corresponds to sunday) to the end of the list
|
||||
*/
|
||||
export function sundayToTheEnd(list){
|
||||
const newlist = list;
|
||||
const sunday = newlist.shift();
|
||||
@ -94,19 +136,31 @@
|
||||
return newlist;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the difference of time between 2 dates
|
||||
*/
|
||||
export function getDifferenceTime(date1,date2){
|
||||
return Math.abs((new Date(date2).getTime() - new Date(date1).getTime())/60000);
|
||||
}
|
||||
|
||||
/*
|
||||
* used to shift the lessons correctly
|
||||
*/
|
||||
export function getMarginTop(list, index1, index2){
|
||||
if(index2 < 0){
|
||||
const temp = new Date(list[index1].lessonStart);
|
||||
temp.setHours(8,0,0);
|
||||
return Math.abs((new Date(list[index1].lessonStart).getTime()- temp.getTime())/60000);
|
||||
}
|
||||
}
|
||||
if(new Date(list[index1].lessonStart).getTime() === new Date(list[index2].lessonEnd).getTime()){
|
||||
return Math.abs(getMarginTop(list,index2,index2-1));
|
||||
}
|
||||
return Math.abs((new Date(list[index1].lessonStart).getTime()- new Date(list[index2].lessonEnd).getTime())/60000)+getMarginTop(list,index2,index2-1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get the hour and minutes of a date in the right format
|
||||
*/
|
||||
export function getHoursMinutes(date){
|
||||
const d = new Date(date);
|
||||
let hours = [d.getHours().toString().length == 1 ? "0" + d.getHours().toString() : d.getHours()];
|
||||
|
Reference in New Issue
Block a user