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/LICENSE +21 -0
- package/README.md +160 -0
- package/__tests__/page.test.js +46 -0
- package/__tests__/page.test.tsx +57 -0
- package/contexts/CalendarContext.js +12 -0
- package/contexts/CalendarContext.tsx +34 -0
- package/definition.txt +318 -0
- package/definitions/index.js +1 -0
- package/definitions/index.ts +446 -0
- package/docs/global.html +4983 -0
- package/docs/index.html +473 -0
- package/docs/index.ts.html +567 -0
- package/docs/scripts/app.min.js +1 -0
- package/docs/scripts/linenumber.js +26 -0
- package/docs/scripts/search.js +39 -0
- package/docs/styles/app.min.css +1 -0
- package/docs/styles/iframe.css +13 -0
- package/docs/styles/prettify-jsdoc.css +111 -0
- package/docs/styles/prettify-tomorrow.css +132 -0
- package/docs/styles/reset.css +44 -0
- package/index.js +224 -0
- package/index.tsx +591 -0
- package/jest.config.js +9 -0
- package/jest.config.ts +10 -0
- package/jsdoc.json +26 -0
- package/lib/utils.js +437 -0
- package/lib/utils.ts +598 -0
- package/myJsDoc.js +0 -0
- package/out/index.html +129 -0
- package/out/scripts/app.min.js +1 -0
- package/out/scripts/linenumber.js +26 -0
- package/out/scripts/search.js +39 -0
- package/out/styles/app.min.css +1 -0
- package/out/styles/iframe.css +13 -0
- package/out/styles/prettify-jsdoc.css +111 -0
- package/out/styles/prettify-tomorrow.css +132 -0
- package/out/styles/reset.css +44 -0
- package/package.json +45 -0
- package/style.css +51 -0
package/lib/utils.ts
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
import {
|
|
3
|
+
TasksType,
|
|
4
|
+
TaskType,
|
|
5
|
+
TaskFeildsType,
|
|
6
|
+
GroupFeildsType,
|
|
7
|
+
} from "../definitions";
|
|
8
|
+
// Obtenir la date actuelle
|
|
9
|
+
const currentDate = new Date();
|
|
10
|
+
// Obtenir le jour de la semaine (dimanche = 0, lundi = 1, ..., samedi = 6)
|
|
11
|
+
const currentDayOfWeek = currentDate.getDay();
|
|
12
|
+
|
|
13
|
+
// Calculer la date de début de la semaine en millisecondes
|
|
14
|
+
const startDate = new Date(currentDate);
|
|
15
|
+
startDate.setDate(startDate.getDate() - currentDayOfWeek);
|
|
16
|
+
startDate.setHours(0, 0, 0, 0);
|
|
17
|
+
const startDateMilliseconds = startDate.getTime();
|
|
18
|
+
|
|
19
|
+
// Calculer la date de fin de la semaine en millisecondes
|
|
20
|
+
const endDate = new Date(currentDate);
|
|
21
|
+
endDate.setDate(endDate.getDate() + (6 - currentDayOfWeek));
|
|
22
|
+
endDate.setHours(23, 59, 59, 999);
|
|
23
|
+
const endDateMilliseconds = endDate.getTime();
|
|
24
|
+
function getDayHourly(weekOffset: number) {
|
|
25
|
+
const dailyHours: {
|
|
26
|
+
positionDay: number;
|
|
27
|
+
day: Date;
|
|
28
|
+
start: number;
|
|
29
|
+
end: number;
|
|
30
|
+
}[] = [];
|
|
31
|
+
|
|
32
|
+
// Boucle pour calculer les heures de début et de fin de chaque jour de la semaine
|
|
33
|
+
for (let i = 0; i < 7; i++) {
|
|
34
|
+
const dayDate = new Date(startDate);
|
|
35
|
+
dayDate.setDate(startDate.getDate() + i);
|
|
36
|
+
const dayStart = new Date(dayDate);
|
|
37
|
+
dayStart.setHours(1, 0, 0, 0);
|
|
38
|
+
const dayEnd = new Date(dayDate);
|
|
39
|
+
dayEnd.setHours(23, 59, 59, 59);
|
|
40
|
+
|
|
41
|
+
dailyHours.push({
|
|
42
|
+
positionDay: i,
|
|
43
|
+
day: new Date(dayStart.getTime() + weekOffset * 86400000),
|
|
44
|
+
start: dayStart.getTime() + weekOffset * 86400000,
|
|
45
|
+
end: dayEnd.getTime() + weekOffset * 86400000,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return dailyHours;
|
|
49
|
+
}
|
|
50
|
+
// Tableau pour stocker les heures de début et de fin de chaque jour de la semaine
|
|
51
|
+
|
|
52
|
+
function millisecondsToDate(milliseconds: number) {
|
|
53
|
+
const date = new Date(milliseconds);
|
|
54
|
+
|
|
55
|
+
// Récupération du jour de la semaine
|
|
56
|
+
const daysOfWeek = ["Mon", "Tues", "Wed", "Thur", "Frid", "Sat", "Sun"];
|
|
57
|
+
const dayOfWeek = daysOfWeek[date.getDay()];
|
|
58
|
+
// Récupération de l'heure
|
|
59
|
+
let hours = date.getHours();
|
|
60
|
+
// Conversion de l'heure au format 12 heures
|
|
61
|
+
// hours = hours % 12 || 12;
|
|
62
|
+
|
|
63
|
+
// Récupération des minutes
|
|
64
|
+
const minutes = date.getMinutes();
|
|
65
|
+
|
|
66
|
+
// Construction de la date au format souhaité
|
|
67
|
+
const formattedDate = `${hours.toString().padStart(2, "0")}h:${minutes
|
|
68
|
+
.toString()
|
|
69
|
+
.padStart(2, "0")}`;
|
|
70
|
+
|
|
71
|
+
return { formattedDate, dayOfWeek };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function millisecondsToInt(milliseconds: number) {
|
|
75
|
+
const date = new Date(milliseconds);
|
|
76
|
+
|
|
77
|
+
// Récupération du jour de la semaine
|
|
78
|
+
const daysOfWeek = [
|
|
79
|
+
"Dimanche",
|
|
80
|
+
"Lundi",
|
|
81
|
+
"Mardi",
|
|
82
|
+
"Mercredi",
|
|
83
|
+
"Jeudi",
|
|
84
|
+
"Vendredi",
|
|
85
|
+
"Samedi",
|
|
86
|
+
];
|
|
87
|
+
const dayOfWeek = daysOfWeek[date.getDay()];
|
|
88
|
+
|
|
89
|
+
// Récupération du jour du mois
|
|
90
|
+
const dayOfMonth = date.getDate();
|
|
91
|
+
|
|
92
|
+
// Récupération du mois
|
|
93
|
+
const months = [
|
|
94
|
+
"janvier",
|
|
95
|
+
"février",
|
|
96
|
+
"mars",
|
|
97
|
+
"avril",
|
|
98
|
+
"mai",
|
|
99
|
+
"juin",
|
|
100
|
+
"juillet",
|
|
101
|
+
"août",
|
|
102
|
+
"septembre",
|
|
103
|
+
"octobre",
|
|
104
|
+
"novembre",
|
|
105
|
+
"décembre",
|
|
106
|
+
];
|
|
107
|
+
const month = months[date.getMonth()];
|
|
108
|
+
|
|
109
|
+
// Récupération de l'heure
|
|
110
|
+
let hours = date.getHours();
|
|
111
|
+
const amOrPm = hours >= 12 ? " pm" : " am";
|
|
112
|
+
|
|
113
|
+
// Conversion de l'heure au format 12 heures
|
|
114
|
+
// hours = hours % 12 || 12;
|
|
115
|
+
|
|
116
|
+
// Récupération des minutes
|
|
117
|
+
const minutes = date.getMinutes();
|
|
118
|
+
|
|
119
|
+
// Construction de la date au format souhaité
|
|
120
|
+
const formattedDate = hours.toString().padStart(2, "0");
|
|
121
|
+
|
|
122
|
+
return { formattedDate, dayOfWeek };
|
|
123
|
+
}
|
|
124
|
+
function getWeekDays(jump: number) {
|
|
125
|
+
const days = ["Sun", "Mon", "Tues", "Wed", "Thur", "Frid", "Sat"];
|
|
126
|
+
const month = [
|
|
127
|
+
"Jan",
|
|
128
|
+
"Fev",
|
|
129
|
+
"Mar",
|
|
130
|
+
"Avr",
|
|
131
|
+
"Mai",
|
|
132
|
+
"Jui",
|
|
133
|
+
"Juil",
|
|
134
|
+
"Aôu",
|
|
135
|
+
"Sept",
|
|
136
|
+
"Oct",
|
|
137
|
+
"Nov",
|
|
138
|
+
"Dec",
|
|
139
|
+
];
|
|
140
|
+
const currentDate = new Date();
|
|
141
|
+
const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
|
|
142
|
+
let weekDays = [];
|
|
143
|
+
|
|
144
|
+
for (let i = 0; i < 7; i++) {
|
|
145
|
+
const day = new Date();
|
|
146
|
+
const diff = i - currentDayOfWeek;
|
|
147
|
+
|
|
148
|
+
day.setDate(currentDate.getDate() + diff + jump);
|
|
149
|
+
|
|
150
|
+
const formattedDay = `${days[day.getDay()]}. ${day.getDate()}, ${
|
|
151
|
+
month[day.getMonth()]
|
|
152
|
+
} ${day.getFullYear()}`;
|
|
153
|
+
weekDays.push({
|
|
154
|
+
day: days[day.getDay()],
|
|
155
|
+
dayMonth: month[day.getMonth()],
|
|
156
|
+
dayYear: day.getFullYear(),
|
|
157
|
+
dayOfTheMonth: day.getDate(),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return weekDays;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getCalandarDays(jump: number) {
|
|
165
|
+
const days = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
|
|
166
|
+
const month = [
|
|
167
|
+
"Jan",
|
|
168
|
+
"Fev",
|
|
169
|
+
"Mar",
|
|
170
|
+
"Avr",
|
|
171
|
+
"Mai",
|
|
172
|
+
"Jui",
|
|
173
|
+
"Juil",
|
|
174
|
+
"Aôu",
|
|
175
|
+
"Sept",
|
|
176
|
+
"Oct",
|
|
177
|
+
"Nov",
|
|
178
|
+
"Dec",
|
|
179
|
+
];
|
|
180
|
+
const currentDate = new Date();
|
|
181
|
+
const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
|
|
182
|
+
let weekDays = [];
|
|
183
|
+
|
|
184
|
+
for (let i = 0; i < 7; i++) {
|
|
185
|
+
const day = new Date();
|
|
186
|
+
const diff = i - currentDayOfWeek;
|
|
187
|
+
|
|
188
|
+
day.setDate(currentDate.getDate() + diff + jump);
|
|
189
|
+
|
|
190
|
+
const formattedDay = day;
|
|
191
|
+
weekDays.push(formattedDay);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return weekDays;
|
|
195
|
+
}
|
|
196
|
+
function getWeekMonthAndYear(jump: number) {
|
|
197
|
+
const days = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
|
|
198
|
+
const currentDate = new Date();
|
|
199
|
+
const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
|
|
200
|
+
let weekMonthYear = [];
|
|
201
|
+
|
|
202
|
+
for (let i = 0; i < 7; i++) {
|
|
203
|
+
const day = new Date();
|
|
204
|
+
const diff = i - currentDayOfWeek;
|
|
205
|
+
|
|
206
|
+
day.setDate(currentDate.getDate() + diff + jump);
|
|
207
|
+
|
|
208
|
+
const formattedDay = `${days[day.getMonth()]} - ${day.getFullYear()}`;
|
|
209
|
+
weekMonthYear.push(formattedDay);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return weekMonthYear;
|
|
213
|
+
}
|
|
214
|
+
function displayDayOnModalLeft(jump: number) {
|
|
215
|
+
const currentDate = new Date();
|
|
216
|
+
const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
|
|
217
|
+
let dayModal = [];
|
|
218
|
+
|
|
219
|
+
for (let i = 0; i < 7; i++) {
|
|
220
|
+
const day = new Date();
|
|
221
|
+
const diff = i - currentDayOfWeek;
|
|
222
|
+
|
|
223
|
+
day.setDate(currentDate.getDate() + diff + jump);
|
|
224
|
+
dayModal.push(day);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return dayModal;
|
|
228
|
+
}
|
|
229
|
+
function getWeeksListUpdate(annee: any) {
|
|
230
|
+
// Créer un objet Date pour le premier jour de l'année
|
|
231
|
+
const premierJour = new Date(annee, 0, 1);
|
|
232
|
+
|
|
233
|
+
// Créer un tableau vide pour stocker les semaines
|
|
234
|
+
const weeksList = [];
|
|
235
|
+
|
|
236
|
+
// Créer des tableaux pour les jours de la semaine et les mois
|
|
237
|
+
const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
|
|
238
|
+
const months = [
|
|
239
|
+
"Jan",
|
|
240
|
+
"Fev",
|
|
241
|
+
"Mar",
|
|
242
|
+
"Avr",
|
|
243
|
+
"Mai",
|
|
244
|
+
"Jui",
|
|
245
|
+
"Juil",
|
|
246
|
+
"Aôu",
|
|
247
|
+
"Sept",
|
|
248
|
+
"Oct",
|
|
249
|
+
"Nov",
|
|
250
|
+
"Dec",
|
|
251
|
+
];
|
|
252
|
+
|
|
253
|
+
// Obtenir le nombre de semaines dans l'année
|
|
254
|
+
const nombreSemaines = moment().year(annee).weeksInYear();
|
|
255
|
+
|
|
256
|
+
// Faire une boucle sur les semaines
|
|
257
|
+
for (let i = 0; i < nombreSemaines; i++) {
|
|
258
|
+
// Calculer le début et la fin de la semaine en ajoutant le nombre de jours correspondant
|
|
259
|
+
const weekStart = new Date(annee, 0, 1 + i * 7 - premierJour.getDay());
|
|
260
|
+
const weekEnd = new Date(annee, 0, 1 + i * 7 - premierJour.getDay() + 6);
|
|
261
|
+
|
|
262
|
+
// Formater les dates au format souhaité
|
|
263
|
+
const formattedStart = `${
|
|
264
|
+
daysOfWeek[weekStart.getDay()]
|
|
265
|
+
}.${weekStart.getDate()} ${
|
|
266
|
+
months[weekStart.getMonth()]
|
|
267
|
+
} ${weekStart.getFullYear()}`;
|
|
268
|
+
const formattedEnd = `${
|
|
269
|
+
daysOfWeek[weekEnd.getDay()]
|
|
270
|
+
}.${weekEnd.getDate()} ${
|
|
271
|
+
months[weekEnd.getMonth()]
|
|
272
|
+
} ${weekEnd.getFullYear()}`;
|
|
273
|
+
|
|
274
|
+
// Ajouter la semaine au tableau
|
|
275
|
+
weeksList.push(`${formattedStart} - ${formattedEnd}`);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Retourner le tableau des semaines
|
|
279
|
+
return weeksList;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function getWeeksList() {
|
|
283
|
+
const today = new Date();
|
|
284
|
+
const weeksList = [];
|
|
285
|
+
const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
|
|
286
|
+
const months = [
|
|
287
|
+
"Jan",
|
|
288
|
+
"Fev",
|
|
289
|
+
"Mar",
|
|
290
|
+
"Avr",
|
|
291
|
+
"Mai",
|
|
292
|
+
"Jui",
|
|
293
|
+
"Juil",
|
|
294
|
+
"Aôu",
|
|
295
|
+
"Sept",
|
|
296
|
+
"Oct",
|
|
297
|
+
"Nov",
|
|
298
|
+
"Dec",
|
|
299
|
+
];
|
|
300
|
+
for (let i = -5; i <= 5; i++) {
|
|
301
|
+
const weekStart = new Date(
|
|
302
|
+
today.getFullYear(),
|
|
303
|
+
today.getMonth(),
|
|
304
|
+
today.getDate() + i * 7 - today.getDay()
|
|
305
|
+
);
|
|
306
|
+
const weekEnd = new Date(
|
|
307
|
+
today.getFullYear(),
|
|
308
|
+
today.getMonth(),
|
|
309
|
+
today.getDate() + i * 7 - today.getDay() + 6
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
const options = {
|
|
313
|
+
weekday: "short",
|
|
314
|
+
day: "numeric",
|
|
315
|
+
month: "short",
|
|
316
|
+
year: "numeric",
|
|
317
|
+
};
|
|
318
|
+
const dayOfWeek = daysOfWeek[weekStart.getDay()];
|
|
319
|
+
const formattedStart = `${
|
|
320
|
+
daysOfWeek[weekStart.getDay()]
|
|
321
|
+
}.${weekStart.getDate()} ${
|
|
322
|
+
months[weekStart.getMonth()]
|
|
323
|
+
} ${weekStart.getFullYear()}`;
|
|
324
|
+
// const formattedStart = weekStart.toLocaleDateString('fr-FR', options);
|
|
325
|
+
const formattedEnd = `${
|
|
326
|
+
daysOfWeek[weekEnd.getDay()]
|
|
327
|
+
}.${weekEnd.getDate()} ${
|
|
328
|
+
months[weekEnd.getMonth()]
|
|
329
|
+
} ${weekEnd.getFullYear()}`;
|
|
330
|
+
|
|
331
|
+
weeksList.push(`${formattedStart} - ${formattedEnd}`);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return weeksList;
|
|
335
|
+
}
|
|
336
|
+
function getDoubleWeeksList() {
|
|
337
|
+
const today = new Date();
|
|
338
|
+
const weeksList = [];
|
|
339
|
+
const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
|
|
340
|
+
const months = [
|
|
341
|
+
"Jan",
|
|
342
|
+
"Fev",
|
|
343
|
+
"Mar",
|
|
344
|
+
"Avr",
|
|
345
|
+
"Mai",
|
|
346
|
+
"Jui",
|
|
347
|
+
"Juil",
|
|
348
|
+
"Aôu",
|
|
349
|
+
"Sept",
|
|
350
|
+
"Oct",
|
|
351
|
+
"Nov",
|
|
352
|
+
"Dec",
|
|
353
|
+
];
|
|
354
|
+
for (let i = -5; i <= 5; i++) {
|
|
355
|
+
const weekStart = new Date(
|
|
356
|
+
today.getFullYear(),
|
|
357
|
+
today.getMonth(),
|
|
358
|
+
today.getDate() + i * 7 - today.getDay()
|
|
359
|
+
);
|
|
360
|
+
const weekEnd = new Date(
|
|
361
|
+
today.getFullYear(),
|
|
362
|
+
today.getMonth(),
|
|
363
|
+
today.getDate() + i * 7 - today.getDay() + 13
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
const options = {
|
|
367
|
+
weekday: "short",
|
|
368
|
+
day: "numeric",
|
|
369
|
+
month: "short",
|
|
370
|
+
year: "numeric",
|
|
371
|
+
};
|
|
372
|
+
const dayOfWeek = daysOfWeek[weekStart.getDay()];
|
|
373
|
+
const formattedStart = `${
|
|
374
|
+
daysOfWeek[weekStart.getDay()]
|
|
375
|
+
}.${weekStart.getDate()} ${
|
|
376
|
+
months[weekStart.getMonth()]
|
|
377
|
+
} ${weekStart.getFullYear()}`;
|
|
378
|
+
// const formattedStart = weekStart.toLocaleDateString('fr-FR', options);
|
|
379
|
+
const formattedEnd = `${
|
|
380
|
+
daysOfWeek[weekEnd.getDay()]
|
|
381
|
+
}.${weekEnd.getDate()} ${
|
|
382
|
+
months[weekEnd.getMonth()]
|
|
383
|
+
} ${weekEnd.getFullYear()}`;
|
|
384
|
+
|
|
385
|
+
weeksList.push(`${formattedStart} - ${formattedEnd}`);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return weeksList;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function formatDateToCustomFormat(dateString: string) {
|
|
392
|
+
// Tableau contenant les noms des jours de la semaine en français
|
|
393
|
+
const daysOfWeek = [
|
|
394
|
+
"Dimanche",
|
|
395
|
+
"Lundi",
|
|
396
|
+
"Mardi",
|
|
397
|
+
"Mercredi",
|
|
398
|
+
"Jeudi",
|
|
399
|
+
"Vendredi",
|
|
400
|
+
"Samedi",
|
|
401
|
+
];
|
|
402
|
+
|
|
403
|
+
// Tableau contenant les noms des mois en français
|
|
404
|
+
const months = [
|
|
405
|
+
"janvier",
|
|
406
|
+
"février",
|
|
407
|
+
"mars",
|
|
408
|
+
"avril",
|
|
409
|
+
"mai",
|
|
410
|
+
"juin",
|
|
411
|
+
"juillet",
|
|
412
|
+
"août",
|
|
413
|
+
"septembre",
|
|
414
|
+
"octobre",
|
|
415
|
+
"novembre",
|
|
416
|
+
"décembre",
|
|
417
|
+
];
|
|
418
|
+
|
|
419
|
+
// Créer un objet Date à partir de la chaîne de caractères
|
|
420
|
+
const date = new Date(dateString);
|
|
421
|
+
|
|
422
|
+
// Récupérer le jour de la semaine, le jour du mois et le mois
|
|
423
|
+
const dayOfWeek = daysOfWeek[date.getDay()];
|
|
424
|
+
const dayOfMonth = date.getDate();
|
|
425
|
+
const month = months[date.getMonth()];
|
|
426
|
+
|
|
427
|
+
// Formater la date dans le format 'jour_de_la_semaine jour_du_mois mois'
|
|
428
|
+
const formattedDate = `${dayOfWeek} ${dayOfMonth} ${month}`;
|
|
429
|
+
|
|
430
|
+
return formattedDate;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function clickedDate(dateString: string) {
|
|
434
|
+
// Créer un objet Date à partir de la chaîne de caractères
|
|
435
|
+
const date = new Date(dateString);
|
|
436
|
+
return date;
|
|
437
|
+
}
|
|
438
|
+
const calculateTimeOfDayRange = (start: number, end: number) => {
|
|
439
|
+
const hourToMillisecond = 3600000;
|
|
440
|
+
const range = [];
|
|
441
|
+
for (let i = start; i < end; i += hourToMillisecond) {
|
|
442
|
+
range.push(i);
|
|
443
|
+
}
|
|
444
|
+
return range;
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
function getWeekNumber(date: Date) {
|
|
448
|
+
date.setHours(0, 0, 0, 0);
|
|
449
|
+
date.setDate(date.getDate() + 4 - (date.getDay() || 7));
|
|
450
|
+
const yearStart = new Date(date.getFullYear(), 0, 1).getTime();
|
|
451
|
+
const weekNumber = Math.ceil(
|
|
452
|
+
((date.getTime() - yearStart) / 86400000 + 1) / 7
|
|
453
|
+
);
|
|
454
|
+
return weekNumber;
|
|
455
|
+
}
|
|
456
|
+
function updateSelectedDateForEcartSemaine(dateSelectionnee: Date) {
|
|
457
|
+
if (dateSelectionnee.getDay() === 0)
|
|
458
|
+
return new Date(dateSelectionnee.getTime() + 86400000);
|
|
459
|
+
return dateSelectionnee;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function calculerEcartSemaine(dateSelectionnee: Date) {
|
|
463
|
+
// Récupérer la date actuelle
|
|
464
|
+
if (!dateSelectionnee) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const selectedDateUpdated=updateSelectedDateForEcartSemaine(dateSelectionnee)
|
|
468
|
+
|
|
469
|
+
const dateActuelle = new Date();
|
|
470
|
+
|
|
471
|
+
// Extraire l'année et le numéro de la semaine de la date actuelle
|
|
472
|
+
const anneeActuelle = dateActuelle.getFullYear();
|
|
473
|
+
const numeroSemaineActuelle = getWeekNumber(dateActuelle);
|
|
474
|
+
|
|
475
|
+
// Extraire l'année et le numéro de la semaine de la date sélectionnée
|
|
476
|
+
|
|
477
|
+
const anneeSelectionnee = selectedDateUpdated.getFullYear();
|
|
478
|
+
const numeroSemaineSelectionnee = getWeekNumber(selectedDateUpdated);
|
|
479
|
+
|
|
480
|
+
// Calculer le nombre de semaines depuis une date d'origine arbitraire
|
|
481
|
+
|
|
482
|
+
// Calculer l'écart entre les semaines en utilisant la formule
|
|
483
|
+
const ecartSemaine =
|
|
484
|
+
semainesDepuisOrigine(anneeSelectionnee, numeroSemaineSelectionnee) -
|
|
485
|
+
semainesDepuisOrigine(anneeActuelle, numeroSemaineActuelle);
|
|
486
|
+
|
|
487
|
+
return ecartSemaine * 7;
|
|
488
|
+
}
|
|
489
|
+
function semainesDepuisOrigine(annee: number, numeroSemaine: number) {
|
|
490
|
+
// Choisir le 1er janvier 2022 comme date d'origine
|
|
491
|
+
const dateOrigine = new Date(2022, 0, 1);
|
|
492
|
+
const anneeOrigine = dateOrigine.getFullYear();
|
|
493
|
+
const numeroSemaineOrigine = getWeekNumber(dateOrigine);
|
|
494
|
+
|
|
495
|
+
// Calculer le nombre total de semaines écoulées depuis la date d'origine
|
|
496
|
+
let nombreSemaines = 0;
|
|
497
|
+
for (let i = anneeOrigine; i < annee; i++) {
|
|
498
|
+
nombreSemaines += moment().year(i).weeksInYear();
|
|
499
|
+
}
|
|
500
|
+
nombreSemaines += numeroSemaine - numeroSemaineOrigine;
|
|
501
|
+
|
|
502
|
+
return nombreSemaines;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function getSessionStorageRecordForDragAndDrop(
|
|
506
|
+
tasks: TasksType,
|
|
507
|
+
positionDay: number,
|
|
508
|
+
dropGroupId: string
|
|
509
|
+
) {
|
|
510
|
+
const dragtaskId = window.sessionStorage.getItem("calendardragtaskId");
|
|
511
|
+
const dragtaskStart = window.sessionStorage.getItem("calendardragtaskStart");
|
|
512
|
+
const dragtaskEnd = window.sessionStorage.getItem("calendardragtaskEnd");
|
|
513
|
+
const dragdayIndex = window.sessionStorage.getItem("calendardragdayIndex");
|
|
514
|
+
let newTask: TaskFeildsType | any;
|
|
515
|
+
let newTasks: TasksType = [];
|
|
516
|
+
// window.sessionStorage.clear();
|
|
517
|
+
if (!dragdayIndex || !dragtaskStart || !dragtaskEnd || !dragtaskId || !tasks)
|
|
518
|
+
return;
|
|
519
|
+
const dragTask = tasks.find((task) => task.taskId === dragtaskId);
|
|
520
|
+
const dayIndex = parseInt(dragdayIndex);
|
|
521
|
+
const ecartDaysIndex = positionDay - dayIndex;
|
|
522
|
+
const ecartDays = ecartDaysIndex * 86400000;
|
|
523
|
+
const taskDropStart = parseInt(dragtaskStart) + ecartDays;
|
|
524
|
+
const taskDropEnd = parseInt(dragtaskEnd) + ecartDays;
|
|
525
|
+
const taskDropDate = new Date(taskDropStart);
|
|
526
|
+
if (dragTask) {
|
|
527
|
+
const { taskStart, taskEnd, taskDate, groupId, dayIndex, ...rest } =
|
|
528
|
+
dragTask;
|
|
529
|
+
|
|
530
|
+
newTask = {
|
|
531
|
+
taskStart: taskDropStart,
|
|
532
|
+
taskEnd: taskDropEnd,
|
|
533
|
+
taskDate: taskDropDate,
|
|
534
|
+
groupId: dropGroupId,
|
|
535
|
+
dayIndex: positionDay,
|
|
536
|
+
...rest,
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
const dragTaskIndex = tasks.findIndex((task) => task.taskId === dragtaskId);
|
|
540
|
+
newTasks = [...tasks];
|
|
541
|
+
newTasks.splice(dragTaskIndex, 1, newTask);
|
|
542
|
+
}
|
|
543
|
+
return { taskDropStart, taskDropEnd, taskDropDate, newTask, newTasks };
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function compareWeekOffset(
|
|
547
|
+
calendarDate: Date,
|
|
548
|
+
weekOffset: number,
|
|
549
|
+
taskDate: Date
|
|
550
|
+
) {
|
|
551
|
+
if (taskDate.getDay() === 0 && calculerEcartSemaine(taskDate) === -7) {
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
554
|
+
if (calendarDate)
|
|
555
|
+
return (
|
|
556
|
+
calculerEcartSemaine(calendarDate) === calculerEcartSemaine(taskDate)
|
|
557
|
+
);
|
|
558
|
+
return weekOffset === calculerEcartSemaine(taskDate);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const sumHoursByGroups = (
|
|
562
|
+
groupId: string,
|
|
563
|
+
tasks: TasksType | any,
|
|
564
|
+
weekOffset: number,
|
|
565
|
+
calendarDate: Date
|
|
566
|
+
) => {
|
|
567
|
+
let sum: number = 0;
|
|
568
|
+
tasks?.forEach((task: TaskType | any) => {
|
|
569
|
+
if (
|
|
570
|
+
task.groupId === groupId &&
|
|
571
|
+
compareWeekOffset(calendarDate, weekOffset, task.taskDate) === true
|
|
572
|
+
) {
|
|
573
|
+
sum += (task.taskEnd - task.taskStart) / 3600000;
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
return sum;
|
|
577
|
+
};
|
|
578
|
+
export {
|
|
579
|
+
getWeeksListUpdate,
|
|
580
|
+
clickedDate,
|
|
581
|
+
getCalandarDays,
|
|
582
|
+
startDateMilliseconds,
|
|
583
|
+
endDateMilliseconds,
|
|
584
|
+
getDayHourly,
|
|
585
|
+
millisecondsToDate,
|
|
586
|
+
getWeekDays,
|
|
587
|
+
formatDateToCustomFormat,
|
|
588
|
+
displayDayOnModalLeft,
|
|
589
|
+
millisecondsToInt,
|
|
590
|
+
getWeekMonthAndYear,
|
|
591
|
+
getWeeksList,
|
|
592
|
+
getDoubleWeeksList,
|
|
593
|
+
calculerEcartSemaine,
|
|
594
|
+
calculateTimeOfDayRange,
|
|
595
|
+
getSessionStorageRecordForDragAndDrop,
|
|
596
|
+
compareWeekOffset,
|
|
597
|
+
sumHoursByGroups,
|
|
598
|
+
};
|
package/myJsDoc.js
ADDED
|
File without changes
|