react-weekly-planning 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/utils.js ADDED
@@ -0,0 +1,437 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import moment from "moment";
13
+ // Obtenir la date actuelle
14
+ const currentDate = new Date();
15
+ // Obtenir le jour de la semaine (dimanche = 0, lundi = 1, ..., samedi = 6)
16
+ const currentDayOfWeek = currentDate.getDay();
17
+ // Calculer la date de début de la semaine en millisecondes
18
+ const startDate = new Date(currentDate);
19
+ startDate.setDate(startDate.getDate() - currentDayOfWeek);
20
+ startDate.setHours(0, 0, 0, 0);
21
+ const startDateMilliseconds = startDate.getTime();
22
+ // Calculer la date de fin de la semaine en millisecondes
23
+ const endDate = new Date(currentDate);
24
+ endDate.setDate(endDate.getDate() + (6 - currentDayOfWeek));
25
+ endDate.setHours(23, 59, 59, 999);
26
+ const endDateMilliseconds = endDate.getTime();
27
+ function getDayHourly(weekOffset) {
28
+ const dailyHours = [];
29
+ // Boucle pour calculer les heures de début et de fin de chaque jour de la semaine
30
+ for (let i = 0; i < 7; i++) {
31
+ const dayDate = new Date(startDate);
32
+ dayDate.setDate(startDate.getDate() + i);
33
+ const dayStart = new Date(dayDate);
34
+ dayStart.setHours(1, 0, 0, 0);
35
+ const dayEnd = new Date(dayDate);
36
+ dayEnd.setHours(23, 59, 59, 59);
37
+ dailyHours.push({
38
+ positionDay: i,
39
+ day: new Date(dayStart.getTime() + weekOffset * 86400000),
40
+ start: dayStart.getTime() + weekOffset * 86400000,
41
+ end: dayEnd.getTime() + weekOffset * 86400000,
42
+ });
43
+ }
44
+ return dailyHours;
45
+ }
46
+ // Tableau pour stocker les heures de début et de fin de chaque jour de la semaine
47
+ function millisecondsToDate(milliseconds) {
48
+ const date = new Date(milliseconds);
49
+ // Récupération du jour de la semaine
50
+ const daysOfWeek = ["Mon", "Tues", "Wed", "Thur", "Frid", "Sat", "Sun"];
51
+ const dayOfWeek = daysOfWeek[date.getDay()];
52
+ // Récupération de l'heure
53
+ let hours = date.getHours();
54
+ // Conversion de l'heure au format 12 heures
55
+ // hours = hours % 12 || 12;
56
+ // Récupération des minutes
57
+ const minutes = date.getMinutes();
58
+ // Construction de la date au format souhaité
59
+ const formattedDate = `${hours.toString().padStart(2, "0")}h:${minutes
60
+ .toString()
61
+ .padStart(2, "0")}`;
62
+ return { formattedDate, dayOfWeek };
63
+ }
64
+ function millisecondsToInt(milliseconds) {
65
+ const date = new Date(milliseconds);
66
+ // Récupération du jour de la semaine
67
+ const daysOfWeek = [
68
+ "Dimanche",
69
+ "Lundi",
70
+ "Mardi",
71
+ "Mercredi",
72
+ "Jeudi",
73
+ "Vendredi",
74
+ "Samedi",
75
+ ];
76
+ const dayOfWeek = daysOfWeek[date.getDay()];
77
+ // Récupération du jour du mois
78
+ const dayOfMonth = date.getDate();
79
+ // Récupération du mois
80
+ const months = [
81
+ "janvier",
82
+ "février",
83
+ "mars",
84
+ "avril",
85
+ "mai",
86
+ "juin",
87
+ "juillet",
88
+ "août",
89
+ "septembre",
90
+ "octobre",
91
+ "novembre",
92
+ "décembre",
93
+ ];
94
+ const month = months[date.getMonth()];
95
+ // Récupération de l'heure
96
+ let hours = date.getHours();
97
+ const amOrPm = hours >= 12 ? " pm" : " am";
98
+ // Conversion de l'heure au format 12 heures
99
+ // hours = hours % 12 || 12;
100
+ // Récupération des minutes
101
+ const minutes = date.getMinutes();
102
+ // Construction de la date au format souhaité
103
+ const formattedDate = hours.toString().padStart(2, "0");
104
+ return { formattedDate, dayOfWeek };
105
+ }
106
+ function getWeekDays(jump) {
107
+ const days = ["Sun", "Mon", "Tues", "Wed", "Thur", "Frid", "Sat"];
108
+ const month = [
109
+ "Jan",
110
+ "Fev",
111
+ "Mar",
112
+ "Avr",
113
+ "Mai",
114
+ "Jui",
115
+ "Juil",
116
+ "Aôu",
117
+ "Sept",
118
+ "Oct",
119
+ "Nov",
120
+ "Dec",
121
+ ];
122
+ const currentDate = new Date();
123
+ const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
124
+ let weekDays = [];
125
+ for (let i = 0; i < 7; i++) {
126
+ const day = new Date();
127
+ const diff = i - currentDayOfWeek;
128
+ day.setDate(currentDate.getDate() + diff + jump);
129
+ const formattedDay = `${days[day.getDay()]}. ${day.getDate()}, ${month[day.getMonth()]} ${day.getFullYear()}`;
130
+ weekDays.push({
131
+ day: days[day.getDay()],
132
+ dayMonth: month[day.getMonth()],
133
+ dayYear: day.getFullYear(),
134
+ dayOfTheMonth: day.getDate(),
135
+ });
136
+ }
137
+ return weekDays;
138
+ }
139
+ function getCalandarDays(jump) {
140
+ const days = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
141
+ const month = [
142
+ "Jan",
143
+ "Fev",
144
+ "Mar",
145
+ "Avr",
146
+ "Mai",
147
+ "Jui",
148
+ "Juil",
149
+ "Aôu",
150
+ "Sept",
151
+ "Oct",
152
+ "Nov",
153
+ "Dec",
154
+ ];
155
+ const currentDate = new Date();
156
+ const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
157
+ let weekDays = [];
158
+ for (let i = 0; i < 7; i++) {
159
+ const day = new Date();
160
+ const diff = i - currentDayOfWeek;
161
+ day.setDate(currentDate.getDate() + diff + jump);
162
+ const formattedDay = day;
163
+ weekDays.push(formattedDay);
164
+ }
165
+ return weekDays;
166
+ }
167
+ function getWeekMonthAndYear(jump) {
168
+ const days = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
169
+ const currentDate = new Date();
170
+ const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
171
+ let weekMonthYear = [];
172
+ for (let i = 0; i < 7; i++) {
173
+ const day = new Date();
174
+ const diff = i - currentDayOfWeek;
175
+ day.setDate(currentDate.getDate() + diff + jump);
176
+ const formattedDay = `${days[day.getMonth()]} - ${day.getFullYear()}`;
177
+ weekMonthYear.push(formattedDay);
178
+ }
179
+ return weekMonthYear;
180
+ }
181
+ function displayDayOnModalLeft(jump) {
182
+ const currentDate = new Date();
183
+ const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
184
+ let dayModal = [];
185
+ for (let i = 0; i < 7; i++) {
186
+ const day = new Date();
187
+ const diff = i - currentDayOfWeek;
188
+ day.setDate(currentDate.getDate() + diff + jump);
189
+ dayModal.push(day);
190
+ }
191
+ return dayModal;
192
+ }
193
+ function getWeeksListUpdate(annee) {
194
+ // Créer un objet Date pour le premier jour de l'année
195
+ const premierJour = new Date(annee, 0, 1);
196
+ // Créer un tableau vide pour stocker les semaines
197
+ const weeksList = [];
198
+ // Créer des tableaux pour les jours de la semaine et les mois
199
+ const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
200
+ const months = [
201
+ "Jan",
202
+ "Fev",
203
+ "Mar",
204
+ "Avr",
205
+ "Mai",
206
+ "Jui",
207
+ "Juil",
208
+ "Aôu",
209
+ "Sept",
210
+ "Oct",
211
+ "Nov",
212
+ "Dec",
213
+ ];
214
+ // Obtenir le nombre de semaines dans l'année
215
+ const nombreSemaines = moment().year(annee).weeksInYear();
216
+ // Faire une boucle sur les semaines
217
+ for (let i = 0; i < nombreSemaines; i++) {
218
+ // Calculer le début et la fin de la semaine en ajoutant le nombre de jours correspondant
219
+ const weekStart = new Date(annee, 0, 1 + i * 7 - premierJour.getDay());
220
+ const weekEnd = new Date(annee, 0, 1 + i * 7 - premierJour.getDay() + 6);
221
+ // Formater les dates au format souhaité
222
+ const formattedStart = `${daysOfWeek[weekStart.getDay()]}.${weekStart.getDate()} ${months[weekStart.getMonth()]} ${weekStart.getFullYear()}`;
223
+ const formattedEnd = `${daysOfWeek[weekEnd.getDay()]}.${weekEnd.getDate()} ${months[weekEnd.getMonth()]} ${weekEnd.getFullYear()}`;
224
+ // Ajouter la semaine au tableau
225
+ weeksList.push(`${formattedStart} - ${formattedEnd}`);
226
+ }
227
+ // Retourner le tableau des semaines
228
+ return weeksList;
229
+ }
230
+ function getWeeksList() {
231
+ const today = new Date();
232
+ const weeksList = [];
233
+ const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
234
+ const months = [
235
+ "Jan",
236
+ "Fev",
237
+ "Mar",
238
+ "Avr",
239
+ "Mai",
240
+ "Jui",
241
+ "Juil",
242
+ "Aôu",
243
+ "Sept",
244
+ "Oct",
245
+ "Nov",
246
+ "Dec",
247
+ ];
248
+ for (let i = -5; i <= 5; i++) {
249
+ const weekStart = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i * 7 - today.getDay());
250
+ const weekEnd = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i * 7 - today.getDay() + 6);
251
+ const options = {
252
+ weekday: "short",
253
+ day: "numeric",
254
+ month: "short",
255
+ year: "numeric",
256
+ };
257
+ const dayOfWeek = daysOfWeek[weekStart.getDay()];
258
+ const formattedStart = `${daysOfWeek[weekStart.getDay()]}.${weekStart.getDate()} ${months[weekStart.getMonth()]} ${weekStart.getFullYear()}`;
259
+ // const formattedStart = weekStart.toLocaleDateString('fr-FR', options);
260
+ const formattedEnd = `${daysOfWeek[weekEnd.getDay()]}.${weekEnd.getDate()} ${months[weekEnd.getMonth()]} ${weekEnd.getFullYear()}`;
261
+ weeksList.push(`${formattedStart} - ${formattedEnd}`);
262
+ }
263
+ return weeksList;
264
+ }
265
+ function getDoubleWeeksList() {
266
+ const today = new Date();
267
+ const weeksList = [];
268
+ const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
269
+ const months = [
270
+ "Jan",
271
+ "Fev",
272
+ "Mar",
273
+ "Avr",
274
+ "Mai",
275
+ "Jui",
276
+ "Juil",
277
+ "Aôu",
278
+ "Sept",
279
+ "Oct",
280
+ "Nov",
281
+ "Dec",
282
+ ];
283
+ for (let i = -5; i <= 5; i++) {
284
+ const weekStart = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i * 7 - today.getDay());
285
+ const weekEnd = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i * 7 - today.getDay() + 13);
286
+ const options = {
287
+ weekday: "short",
288
+ day: "numeric",
289
+ month: "short",
290
+ year: "numeric",
291
+ };
292
+ const dayOfWeek = daysOfWeek[weekStart.getDay()];
293
+ const formattedStart = `${daysOfWeek[weekStart.getDay()]}.${weekStart.getDate()} ${months[weekStart.getMonth()]} ${weekStart.getFullYear()}`;
294
+ // const formattedStart = weekStart.toLocaleDateString('fr-FR', options);
295
+ const formattedEnd = `${daysOfWeek[weekEnd.getDay()]}.${weekEnd.getDate()} ${months[weekEnd.getMonth()]} ${weekEnd.getFullYear()}`;
296
+ weeksList.push(`${formattedStart} - ${formattedEnd}`);
297
+ }
298
+ return weeksList;
299
+ }
300
+ function formatDateToCustomFormat(dateString) {
301
+ // Tableau contenant les noms des jours de la semaine en français
302
+ const daysOfWeek = [
303
+ "Dimanche",
304
+ "Lundi",
305
+ "Mardi",
306
+ "Mercredi",
307
+ "Jeudi",
308
+ "Vendredi",
309
+ "Samedi",
310
+ ];
311
+ // Tableau contenant les noms des mois en français
312
+ const months = [
313
+ "janvier",
314
+ "février",
315
+ "mars",
316
+ "avril",
317
+ "mai",
318
+ "juin",
319
+ "juillet",
320
+ "août",
321
+ "septembre",
322
+ "octobre",
323
+ "novembre",
324
+ "décembre",
325
+ ];
326
+ // Créer un objet Date à partir de la chaîne de caractères
327
+ const date = new Date(dateString);
328
+ // Récupérer le jour de la semaine, le jour du mois et le mois
329
+ const dayOfWeek = daysOfWeek[date.getDay()];
330
+ const dayOfMonth = date.getDate();
331
+ const month = months[date.getMonth()];
332
+ // Formater la date dans le format 'jour_de_la_semaine jour_du_mois mois'
333
+ const formattedDate = `${dayOfWeek} ${dayOfMonth} ${month}`;
334
+ return formattedDate;
335
+ }
336
+ function clickedDate(dateString) {
337
+ // Créer un objet Date à partir de la chaîne de caractères
338
+ const date = new Date(dateString);
339
+ return date;
340
+ }
341
+ const calculateTimeOfDayRange = (start, end) => {
342
+ const hourToMillisecond = 3600000;
343
+ const range = [];
344
+ for (let i = start; i < end; i += hourToMillisecond) {
345
+ range.push(i);
346
+ }
347
+ return range;
348
+ };
349
+ function getWeekNumber(date) {
350
+ date.setHours(0, 0, 0, 0);
351
+ date.setDate(date.getDate() + 4 - (date.getDay() || 7));
352
+ const yearStart = new Date(date.getFullYear(), 0, 1).getTime();
353
+ const weekNumber = Math.ceil(((date.getTime() - yearStart) / 86400000 + 1) / 7);
354
+ return weekNumber;
355
+ }
356
+ function updateSelectedDateForEcartSemaine(dateSelectionnee) {
357
+ if (dateSelectionnee.getDay() === 0)
358
+ return new Date(dateSelectionnee.getTime() + 86400000);
359
+ return dateSelectionnee;
360
+ }
361
+ function calculerEcartSemaine(dateSelectionnee) {
362
+ // Récupérer la date actuelle
363
+ if (!dateSelectionnee) {
364
+ return;
365
+ }
366
+ const selectedDateUpdated = updateSelectedDateForEcartSemaine(dateSelectionnee);
367
+ const dateActuelle = new Date();
368
+ // Extraire l'année et le numéro de la semaine de la date actuelle
369
+ const anneeActuelle = dateActuelle.getFullYear();
370
+ const numeroSemaineActuelle = getWeekNumber(dateActuelle);
371
+ // Extraire l'année et le numéro de la semaine de la date sélectionnée
372
+ const anneeSelectionnee = selectedDateUpdated.getFullYear();
373
+ const numeroSemaineSelectionnee = getWeekNumber(selectedDateUpdated);
374
+ // Calculer le nombre de semaines depuis une date d'origine arbitraire
375
+ // Calculer l'écart entre les semaines en utilisant la formule
376
+ const ecartSemaine = semainesDepuisOrigine(anneeSelectionnee, numeroSemaineSelectionnee) -
377
+ semainesDepuisOrigine(anneeActuelle, numeroSemaineActuelle);
378
+ return ecartSemaine * 7;
379
+ }
380
+ function semainesDepuisOrigine(annee, numeroSemaine) {
381
+ // Choisir le 1er janvier 2022 comme date d'origine
382
+ const dateOrigine = new Date(2022, 0, 1);
383
+ const anneeOrigine = dateOrigine.getFullYear();
384
+ const numeroSemaineOrigine = getWeekNumber(dateOrigine);
385
+ // Calculer le nombre total de semaines écoulées depuis la date d'origine
386
+ let nombreSemaines = 0;
387
+ for (let i = anneeOrigine; i < annee; i++) {
388
+ nombreSemaines += moment().year(i).weeksInYear();
389
+ }
390
+ nombreSemaines += numeroSemaine - numeroSemaineOrigine;
391
+ return nombreSemaines;
392
+ }
393
+ function getSessionStorageRecordForDragAndDrop(tasks, positionDay, dropGroupId) {
394
+ const dragtaskId = window.sessionStorage.getItem("calendardragtaskId");
395
+ const dragtaskStart = window.sessionStorage.getItem("calendardragtaskStart");
396
+ const dragtaskEnd = window.sessionStorage.getItem("calendardragtaskEnd");
397
+ const dragdayIndex = window.sessionStorage.getItem("calendardragdayIndex");
398
+ let newTask;
399
+ let newTasks = [];
400
+ // window.sessionStorage.clear();
401
+ if (!dragdayIndex || !dragtaskStart || !dragtaskEnd || !dragtaskId || !tasks)
402
+ return;
403
+ const dragTask = tasks.find((task) => task.taskId === dragtaskId);
404
+ const dayIndex = parseInt(dragdayIndex);
405
+ const ecartDaysIndex = positionDay - dayIndex;
406
+ const ecartDays = ecartDaysIndex * 86400000;
407
+ const taskDropStart = parseInt(dragtaskStart) + ecartDays;
408
+ const taskDropEnd = parseInt(dragtaskEnd) + ecartDays;
409
+ const taskDropDate = new Date(taskDropStart);
410
+ if (dragTask) {
411
+ const { taskStart, taskEnd, taskDate, groupId, dayIndex } = dragTask, rest = __rest(dragTask, ["taskStart", "taskEnd", "taskDate", "groupId", "dayIndex"]);
412
+ newTask = Object.assign({ taskStart: taskDropStart, taskEnd: taskDropEnd, taskDate: taskDropDate, groupId: dropGroupId, dayIndex: positionDay }, rest);
413
+ const dragTaskIndex = tasks.findIndex((task) => task.taskId === dragtaskId);
414
+ newTasks = [...tasks];
415
+ newTasks.splice(dragTaskIndex, 1, newTask);
416
+ }
417
+ return { taskDropStart, taskDropEnd, taskDropDate, newTask, newTasks };
418
+ }
419
+ function compareWeekOffset(calendarDate, weekOffset, taskDate) {
420
+ if (taskDate.getDay() === 0 && calculerEcartSemaine(taskDate) === -7) {
421
+ return true;
422
+ }
423
+ if (calendarDate)
424
+ return (calculerEcartSemaine(calendarDate) === calculerEcartSemaine(taskDate));
425
+ return weekOffset === calculerEcartSemaine(taskDate);
426
+ }
427
+ const sumHoursByGroups = (groupId, tasks, weekOffset, calendarDate) => {
428
+ let sum = 0;
429
+ tasks === null || tasks === void 0 ? void 0 : tasks.forEach((task) => {
430
+ if (task.groupId === groupId &&
431
+ compareWeekOffset(calendarDate, weekOffset, task.taskDate) === true) {
432
+ sum += (task.taskEnd - task.taskStart) / 3600000;
433
+ }
434
+ });
435
+ return sum;
436
+ };
437
+ export { getWeeksListUpdate, clickedDate, getCalandarDays, startDateMilliseconds, endDateMilliseconds, getDayHourly, millisecondsToDate, getWeekDays, formatDateToCustomFormat, displayDayOnModalLeft, millisecondsToInt, getWeekMonthAndYear, getWeeksList, getDoubleWeeksList, calculerEcartSemaine, calculateTimeOfDayRange, getSessionStorageRecordForDragAndDrop, compareWeekOffset, sumHoursByGroups, };