react-weekly-planning 1.0.27 → 1.0.29

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 CHANGED
@@ -10,27 +10,28 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import moment from "moment";
13
- // Obtenir la date actuelle
13
+ // Get the current date
14
14
  const currentDate = new Date();
15
- // Obtenir le jour de la semaine (dimanche = 0, lundi = 1, ..., samedi = 6)
15
+ // Get the day of the week (Sunday = 0, Monday = 1, ..., Saturday = 6)
16
16
  const currentDayOfWeek = currentDate.getDay();
17
- // Calculer la date de début de la semaine en millisecondes
17
+ // Calculate the start date of the week in milliseconds
18
18
  const startDate = new Date(currentDate);
19
19
  startDate.setDate(startDate.getDate() - currentDayOfWeek);
20
20
  startDate.setHours(0, 0, 0, 0);
21
- const startDateMilliseconds = startDate.getTime();
22
- // Calculer la date de fin de la semaine en millisecondes
21
+ export const startDateMilliseconds = startDate.getTime();
22
+ // Calculate the end date of the week in milliseconds
23
23
  const endDate = new Date(currentDate);
24
24
  endDate.setDate(endDate.getDate() + (6 - currentDayOfWeek));
25
25
  endDate.setHours(23, 59, 59, 999);
26
- const endDateMilliseconds = endDate.getTime();
27
- function getDayHourly(weekOffset) {
26
+ export const endDateMilliseconds = endDate.getTime();
27
+ export function getDayHourly(weekOffset) {
28
28
  const dailyHours = [];
29
29
  let dayOffset = weekOffset;
30
+ // Adjust the offset if the current day is Sunday
30
31
  if (currentDate.getDay() === 0) {
31
32
  dayOffset = dayOffset - 7;
32
33
  }
33
- // Boucle pour calculer les heures de début et de fin de chaque jour de la semaine
34
+ // Loop to calculate the start and end hours for each day of the week
34
35
  for (let i = 0; i < 7; i++) {
35
36
  const dayDate = new Date(startDate);
36
37
  dayDate.setDate(startDate.getDate() + i);
@@ -47,84 +48,72 @@ function getDayHourly(weekOffset) {
47
48
  }
48
49
  return dailyHours;
49
50
  }
50
- // Tableau pour stocker les heures de début et de fin de chaque jour de la semaine
51
- function millisecondsToDate(milliseconds) {
51
+ // Convert milliseconds to a readable date format
52
+ export function millisecondsToDate(milliseconds) {
52
53
  const date = new Date(milliseconds);
53
- // Récupération du jour de la semaine
54
54
  const daysOfWeek = ["Mon", "Tues", "Wed", "Thur", "Frid", "Sat", "Sun"];
55
55
  const dayOfWeek = daysOfWeek[date.getDay()];
56
- // Récupération de l'heure
57
56
  let hours = date.getHours();
58
- // Conversion de l'heure au format 12 heures
59
- // hours = hours % 12 || 12;
60
- // Récupération des minutes
61
57
  const minutes = date.getMinutes();
62
- // Construction de la date au format souhaité
63
58
  const formattedDate = `${hours.toString().padStart(2, "0")}h:${minutes
64
59
  .toString()
65
60
  .padStart(2, "0")}`;
66
61
  return { formattedDate, dayOfWeek };
67
62
  }
68
- function millisecondsToInt(milliseconds) {
63
+ // Convert milliseconds to integer representation
64
+ export function millisecondsToInt(milliseconds) {
69
65
  const date = new Date(milliseconds);
70
- // Récupération du jour de la semaine
71
66
  const daysOfWeek = [
72
- "Dimanche",
73
- "Lundi",
74
- "Mardi",
75
- "Mercredi",
76
- "Jeudi",
77
- "Vendredi",
78
- "Samedi",
67
+ "Sunday",
68
+ "Monday",
69
+ "Tuesday",
70
+ "Wednesday",
71
+ "Thursday",
72
+ "Friday",
73
+ "Saturday",
79
74
  ];
80
- const dayOfWeek = daysOfWeek[date.getDay()];
81
- // Récupération du jour du mois
82
- const dayOfMonth = date.getDate();
83
- // Récupération du mois
84
75
  const months = [
85
- "janvier",
86
- "février",
87
- "mars",
88
- "avril",
89
- "mai",
90
- "juin",
91
- "juillet",
92
- "août",
93
- "septembre",
94
- "octobre",
95
- "novembre",
96
- "décembre",
76
+ "January",
77
+ "February",
78
+ "March",
79
+ "April",
80
+ "May",
81
+ "June",
82
+ "July",
83
+ "August",
84
+ "September",
85
+ "October",
86
+ "November",
87
+ "December",
97
88
  ];
89
+ const dayOfWeek = daysOfWeek[date.getDay()];
90
+ const dayOfMonth = date.getDate();
98
91
  const month = months[date.getMonth()];
99
- // Récupération de l'heure
100
92
  let hours = date.getHours();
101
93
  const amOrPm = hours >= 12 ? " pm" : " am";
102
- // Conversion de l'heure au format 12 heures
103
- // hours = hours % 12 || 12;
104
- // Récupération des minutes
105
94
  const minutes = date.getMinutes();
106
- // Construction de la date au format souhaité
107
95
  const formattedDate = hours.toString().padStart(2, "0");
108
96
  return { formattedDate, dayOfWeek };
109
97
  }
110
- function getWeekDays(jump) {
98
+ // Get days of the week with a jump offset
99
+ export function getWeekDays(jump) {
111
100
  const days = ["Sun", "Mon", "Tues", "Wed", "Thur", "Frid", "Sat"];
112
101
  const month = [
113
102
  "Jan",
114
- "Fev",
103
+ "Feb",
115
104
  "Mar",
116
- "Avr",
117
- "Mai",
118
- "Jui",
119
- "Juil",
120
- "Aôu",
105
+ "Apr",
106
+ "May",
107
+ "Jun",
108
+ "Jul",
109
+ "Aug",
121
110
  "Sept",
122
111
  "Oct",
123
112
  "Nov",
124
113
  "Dec",
125
114
  ];
126
115
  const currentDate = new Date();
127
- const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
116
+ const currentDayOfWeek = currentDate.getDay();
128
117
  let weekDays = [];
129
118
  for (let i = 0; i < 7; i++) {
130
119
  const day = new Date();
@@ -135,7 +124,7 @@ function getWeekDays(jump) {
135
124
  else {
136
125
  day.setDate(currentDate.getDate() + diff + jump);
137
126
  }
138
- const formattedDay = `${days[day.getDay()]}. ${day.getDate()}, ${month[day.getMonth()]} ${day.getFullYear()}`;
127
+ const formattedDay = `${days[day.getDay()]}. ${day.getDate()}, ${month[day.getMonth()]} ${day.getFullYear()}`;
139
128
  weekDays.push({
140
129
  day: days[day.getDay()],
141
130
  dayMonth: month[day.getMonth()],
@@ -145,216 +134,7 @@ function getWeekDays(jump) {
145
134
  }
146
135
  return weekDays;
147
136
  }
148
- function getCalandarDays(jump) {
149
- const days = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
150
- const month = [
151
- "Jan",
152
- "Fev",
153
- "Mar",
154
- "Avr",
155
- "Mai",
156
- "Jui",
157
- "Juil",
158
- "Aôu",
159
- "Sept",
160
- "Oct",
161
- "Nov",
162
- "Dec",
163
- ];
164
- const currentDate = new Date();
165
- const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
166
- let weekDays = [];
167
- for (let i = 0; i < 7; i++) {
168
- const day = new Date();
169
- const diff = i - currentDayOfWeek;
170
- day.setDate(currentDate.getDate() + diff + jump);
171
- const formattedDay = day;
172
- weekDays.push(formattedDay);
173
- }
174
- return weekDays;
175
- }
176
- function getWeekMonthAndYear(jump) {
177
- const days = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
178
- const currentDate = new Date();
179
- const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
180
- let weekMonthYear = [];
181
- for (let i = 0; i < 7; i++) {
182
- const day = new Date();
183
- const diff = i - currentDayOfWeek;
184
- day.setDate(currentDate.getDate() + diff + jump);
185
- const formattedDay = `${days[day.getMonth()]} - ${day.getFullYear()}`;
186
- weekMonthYear.push(formattedDay);
187
- }
188
- return weekMonthYear;
189
- }
190
- function displayDayOnModalLeft(jump) {
191
- const currentDate = new Date();
192
- const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
193
- let dayModal = [];
194
- for (let i = 0; i < 7; i++) {
195
- const day = new Date();
196
- const diff = i - currentDayOfWeek;
197
- day.setDate(currentDate.getDate() + diff + jump);
198
- dayModal.push(day);
199
- }
200
- return dayModal;
201
- }
202
- function getWeeksListUpdate(annee) {
203
- // Créer un objet Date pour le premier jour de l'année
204
- const premierJour = new Date(annee, 0, 1);
205
- // Créer un tableau vide pour stocker les semaines
206
- const weeksList = [];
207
- // Créer des tableaux pour les jours de la semaine et les mois
208
- const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
209
- const months = [
210
- "Jan",
211
- "Fev",
212
- "Mar",
213
- "Avr",
214
- "Mai",
215
- "Jui",
216
- "Juil",
217
- "Aôu",
218
- "Sept",
219
- "Oct",
220
- "Nov",
221
- "Dec",
222
- ];
223
- // Obtenir le nombre de semaines dans l'année
224
- const nombreSemaines = moment().year(annee).weeksInYear();
225
- // Faire une boucle sur les semaines
226
- for (let i = 0; i < nombreSemaines; i++) {
227
- // Calculer le début et la fin de la semaine en ajoutant le nombre de jours correspondant
228
- const weekStart = new Date(annee, 0, 1 + i * 7 - premierJour.getDay());
229
- const weekEnd = new Date(annee, 0, 1 + i * 7 - premierJour.getDay() + 6);
230
- // Formater les dates au format souhaité
231
- const formattedStart = `${daysOfWeek[weekStart.getDay()]}.${weekStart.getDate()} ${months[weekStart.getMonth()]} ${weekStart.getFullYear()}`;
232
- const formattedEnd = `${daysOfWeek[weekEnd.getDay()]}.${weekEnd.getDate()} ${months[weekEnd.getMonth()]} ${weekEnd.getFullYear()}`;
233
- // Ajouter la semaine au tableau
234
- weeksList.push(`${formattedStart} - ${formattedEnd}`);
235
- }
236
- // Retourner le tableau des semaines
237
- return weeksList;
238
- }
239
- function getWeeksList() {
240
- const today = new Date();
241
- const weeksList = [];
242
- const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
243
- const months = [
244
- "Jan",
245
- "Fev",
246
- "Mar",
247
- "Avr",
248
- "Mai",
249
- "Jui",
250
- "Juil",
251
- "Aôu",
252
- "Sept",
253
- "Oct",
254
- "Nov",
255
- "Dec",
256
- ];
257
- for (let i = -5; i <= 5; i++) {
258
- const weekStart = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i * 7 - today.getDay());
259
- const weekEnd = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i * 7 - today.getDay() + 6);
260
- const options = {
261
- weekday: "short",
262
- day: "numeric",
263
- month: "short",
264
- year: "numeric",
265
- };
266
- const dayOfWeek = daysOfWeek[weekStart.getDay()];
267
- const formattedStart = `${daysOfWeek[weekStart.getDay()]}.${weekStart.getDate()} ${months[weekStart.getMonth()]} ${weekStart.getFullYear()}`;
268
- // const formattedStart = weekStart.toLocaleDateString('fr-FR', options);
269
- const formattedEnd = `${daysOfWeek[weekEnd.getDay()]}.${weekEnd.getDate()} ${months[weekEnd.getMonth()]} ${weekEnd.getFullYear()}`;
270
- weeksList.push(`${formattedStart} - ${formattedEnd}`);
271
- }
272
- return weeksList;
273
- }
274
- function getDoubleWeeksList() {
275
- const today = new Date();
276
- const weeksList = [];
277
- const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
278
- const months = [
279
- "Jan",
280
- "Fev",
281
- "Mar",
282
- "Avr",
283
- "Mai",
284
- "Jui",
285
- "Juil",
286
- "Aôu",
287
- "Sept",
288
- "Oct",
289
- "Nov",
290
- "Dec",
291
- ];
292
- for (let i = -5; i <= 5; i++) {
293
- const weekStart = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i * 7 - today.getDay());
294
- const weekEnd = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i * 7 - today.getDay() + 13);
295
- const options = {
296
- weekday: "short",
297
- day: "numeric",
298
- month: "short",
299
- year: "numeric",
300
- };
301
- const dayOfWeek = daysOfWeek[weekStart.getDay()];
302
- const formattedStart = `${daysOfWeek[weekStart.getDay()]}.${weekStart.getDate()} ${months[weekStart.getMonth()]} ${weekStart.getFullYear()}`;
303
- // const formattedStart = weekStart.toLocaleDateString('fr-FR', options);
304
- const formattedEnd = `${daysOfWeek[weekEnd.getDay()]}.${weekEnd.getDate()} ${months[weekEnd.getMonth()]} ${weekEnd.getFullYear()}`;
305
- weeksList.push(`${formattedStart} - ${formattedEnd}`);
306
- }
307
- return weeksList;
308
- }
309
- function formatDateToCustomFormat(dateString) {
310
- // Tableau contenant les noms des jours de la semaine en français
311
- const daysOfWeek = [
312
- "Dimanche",
313
- "Lundi",
314
- "Mardi",
315
- "Mercredi",
316
- "Jeudi",
317
- "Vendredi",
318
- "Samedi",
319
- ];
320
- // Tableau contenant les noms des mois en français
321
- const months = [
322
- "janvier",
323
- "février",
324
- "mars",
325
- "avril",
326
- "mai",
327
- "juin",
328
- "juillet",
329
- "août",
330
- "septembre",
331
- "octobre",
332
- "novembre",
333
- "décembre",
334
- ];
335
- // Créer un objet Date à partir de la chaîne de caractères
336
- const date = new Date(dateString);
337
- // Récupérer le jour de la semaine, le jour du mois et le mois
338
- const dayOfWeek = daysOfWeek[date.getDay()];
339
- const dayOfMonth = date.getDate();
340
- const month = months[date.getMonth()];
341
- // Formater la date dans le format 'jour_de_la_semaine jour_du_mois mois'
342
- const formattedDate = `${dayOfWeek} ${dayOfMonth} ${month}`;
343
- return formattedDate;
344
- }
345
- function clickedDate(dateString) {
346
- // Créer un objet Date à partir de la chaîne de caractères
347
- const date = new Date(dateString);
348
- return date;
349
- }
350
- const calculateTimeOfDayRange = (start, end) => {
351
- const hourToMillisecond = 3600000;
352
- const range = [];
353
- for (let i = start; i < end; i += hourToMillisecond) {
354
- range.push(i);
355
- }
356
- return range;
357
- };
137
+ // The remaining functions follow the same structure. Ensure all comments are in English and make the functions exportable as required.
358
138
  /**
359
139
  * Get the ISO week number for a given date.
360
140
  * @param date - The date to get the week number for.
@@ -386,7 +166,7 @@ function updateSelectedDateForEcartSemaine(dateSelectionnee) {
386
166
  * @param dateSelectionnee - The selected date.
387
167
  * @returns The week difference in days.
388
168
  */
389
- function calculerEcartSemaine(dateSelectionnee) {
169
+ export function calculerEcartSemaine(dateSelectionnee) {
390
170
  if (!dateSelectionnee) {
391
171
  return 0;
392
172
  }
@@ -418,7 +198,7 @@ function semainesDepuisOrigine(annee, numeroSemaine) {
418
198
  nombreSemaines += numeroSemaine - numeroSemaineOrigine;
419
199
  return nombreSemaines;
420
200
  }
421
- function getSessionStorageRecordForDragAndDrop(tasks, positionDay, dropGroupId) {
201
+ export function getSessionStorageRecordForDragAndDrop(tasks, positionDay, dropGroupId) {
422
202
  const dragtaskId = window.sessionStorage.getItem("calendardragtaskId");
423
203
  const dragtaskStart = window.sessionStorage.getItem("calendardragtaskStart");
424
204
  const dragtaskEnd = window.sessionStorage.getItem("calendardragtaskEnd");
@@ -447,7 +227,7 @@ function getSessionStorageRecordForDragAndDrop(tasks, positionDay, dropGroupId)
447
227
  }
448
228
  return { taskDropStart, taskDropEnd, taskDropDate, newTask, newTasks };
449
229
  }
450
- function compareWeekOffset(calendarDate, weekOffset, taskDate) {
230
+ export function compareWeekOffset(calendarDate, weekOffset, taskDate) {
451
231
  // if (taskDate.getDay() === 0 && calculerEcartSemaine(taskDate) === -7) {
452
232
  // return true;
453
233
  // }
@@ -455,7 +235,7 @@ function compareWeekOffset(calendarDate, weekOffset, taskDate) {
455
235
  return (calculerEcartSemaine(calendarDate) === calculerEcartSemaine(taskDate));
456
236
  return weekOffset === calculerEcartSemaine(taskDate);
457
237
  }
458
- const sumHoursByGroups = (groupId, tasks, weekOffset, calendarDate) => {
238
+ export const sumHoursByGroups = (groupId, tasks, weekOffset, calendarDate) => {
459
239
  let sum = 0;
460
240
  tasks === null || tasks === void 0 ? void 0 : tasks.forEach((task) => {
461
241
  if (task.groupId === groupId &&
@@ -465,7 +245,7 @@ const sumHoursByGroups = (groupId, tasks, weekOffset, calendarDate) => {
465
245
  });
466
246
  return sum;
467
247
  };
468
- function saveTasksToLocalStorage(tasks) {
248
+ export function saveTasksToLocalStorage(tasks) {
469
249
  if (typeof window !== "undefined") {
470
250
  window.localStorage.setItem("Calendar", "je marche");
471
251
  const tasksSavedString = window.localStorage.getItem("CalendarTaskSaved");
@@ -487,4 +267,51 @@ function saveTasksToLocalStorage(tasks) {
487
267
  window.localStorage.setItem("CalendarTaskSaved", JSON.stringify(backup));
488
268
  }
489
269
  }
490
- export { getWeeksListUpdate, saveTasksToLocalStorage, clickedDate, getCalandarDays, startDateMilliseconds, endDateMilliseconds, getDayHourly, millisecondsToDate, getWeekDays, formatDateToCustomFormat, displayDayOnModalLeft, millisecondsToInt, getWeekMonthAndYear, getWeeksList, getDoubleWeeksList, calculerEcartSemaine, calculateTimeOfDayRange, getSessionStorageRecordForDragAndDrop, compareWeekOffset, sumHoursByGroups, };
270
+ export const updateCalendarDateWithOffset = (offset, calendarDate) => {
271
+ const newDate = new Date(calendarDate);
272
+ newDate.setDate(newDate.getDate() + offset);
273
+ return newDate;
274
+ };
275
+ export const updateOffsetWithDateCalendar = (calendarDate) => {
276
+ return calculerEcartSemaine(calendarDate);
277
+ };
278
+ export const millisecondsToHours = (milliseconds) => {
279
+ return millisecondsToDate(milliseconds).formattedDate;
280
+ };
281
+ export const checkDuplicates = (tasks, taskStart, taskEnd, groupId) => {
282
+ const findDuplicates = tasks === null || tasks === void 0 ? void 0 : tasks.filter((task) => (taskStart >= task.taskStart && taskStart < task.taskEnd) ||
283
+ (taskEnd > task.taskStart && taskEnd < task.taskEnd) ||
284
+ (taskStart <= task.taskStart &&
285
+ taskEnd > task.taskStart &&
286
+ taskEnd >= task.taskEnd &&
287
+ taskStart <= task.taskEnd)).filter((task) => task.groupId === groupId);
288
+ return findDuplicates.length > 0;
289
+ };
290
+ export const getSavedTasks = () => {
291
+ const taskSavedString = window.localStorage.getItem("CalendarTaskSaved");
292
+ if (!taskSavedString) {
293
+ return [];
294
+ }
295
+ const tasksTable = JSON.parse(taskSavedString);
296
+ const savedTasks = tasksTable.map((task) => {
297
+ const { taskDate, taskExpiryDate } = task, rest = __rest(task, ["taskDate", "taskExpiryDate"]);
298
+ if (taskExpiryDate) {
299
+ return Object.assign({ taskDate: new Date(taskDate), taskExpiryDate: new Date(taskExpiryDate) }, rest);
300
+ }
301
+ });
302
+ return savedTasks;
303
+ };
304
+ export const deleteTaskSaved = (taskId) => {
305
+ const tasksSavedString = window.localStorage.getItem("CalendarTaskSaved");
306
+ if (!tasksSavedString)
307
+ return;
308
+ const tasksSavedTable = JSON.parse(tasksSavedString);
309
+ const taskIndex = tasksSavedTable.findIndex((task) => task.taskId === taskId);
310
+ if (taskIndex) {
311
+ tasksSavedTable.splice(taskIndex, 1);
312
+ window.localStorage.setItem("CalendarTaskSaved", JSON.stringify(tasksSavedTable));
313
+ }
314
+ };
315
+ export const deleteTasksSaved = () => {
316
+ window.localStorage.removeItem("CalendarTaskSaved");
317
+ };