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.ts CHANGED
@@ -1,22 +1,25 @@
1
1
  import moment from "moment";
2
2
  import { TasksType, TaskType, TaskFeildsType } from "../definitions";
3
- // Obtenir la date actuelle
3
+
4
+ // Get the current date
4
5
  const currentDate = new Date();
5
- // Obtenir le jour de la semaine (dimanche = 0, lundi = 1, ..., samedi = 6)
6
+
7
+ // Get the day of the week (Sunday = 0, Monday = 1, ..., Saturday = 6)
6
8
  const currentDayOfWeek = currentDate.getDay();
7
9
 
8
- // Calculer la date de début de la semaine en millisecondes
10
+ // Calculate the start date of the week in milliseconds
9
11
  const startDate = new Date(currentDate);
10
12
  startDate.setDate(startDate.getDate() - currentDayOfWeek);
11
13
  startDate.setHours(0, 0, 0, 0);
12
- const startDateMilliseconds = startDate.getTime();
14
+ export const startDateMilliseconds = startDate.getTime();
13
15
 
14
- // Calculer la date de fin de la semaine en millisecondes
16
+ // Calculate the end date of the week in milliseconds
15
17
  const endDate = new Date(currentDate);
16
18
  endDate.setDate(endDate.getDate() + (6 - currentDayOfWeek));
17
19
  endDate.setHours(23, 59, 59, 999);
18
- const endDateMilliseconds = endDate.getTime();
19
- function getDayHourly(weekOffset: number) {
20
+ export const endDateMilliseconds = endDate.getTime();
21
+
22
+ export function getDayHourly(weekOffset: number) {
20
23
  const dailyHours: {
21
24
  positionDay: number;
22
25
  day: Date;
@@ -24,10 +27,13 @@ function getDayHourly(weekOffset: number) {
24
27
  end: number;
25
28
  }[] = [];
26
29
  let dayOffset = weekOffset;
30
+
31
+ // Adjust the offset if the current day is Sunday
27
32
  if (currentDate.getDay() === 0) {
28
33
  dayOffset = dayOffset - 7;
29
34
  }
30
- // Boucle pour calculer les heures de début et de fin de chaque jour de la semaine
35
+
36
+ // Loop to calculate the start and end hours for each day of the week
31
37
  for (let i = 0; i < 7; i++) {
32
38
  const dayDate = new Date(startDate);
33
39
  dayDate.setDate(startDate.getDate() + i);
@@ -45,98 +51,75 @@ function getDayHourly(weekOffset: number) {
45
51
  }
46
52
  return dailyHours;
47
53
  }
48
- // Tableau pour stocker les heures de début et de fin de chaque jour de la semaine
49
54
 
50
- function millisecondsToDate(milliseconds: number) {
55
+ // Convert milliseconds to a readable date format
56
+ export function millisecondsToDate(milliseconds: number) {
51
57
  const date = new Date(milliseconds);
52
-
53
- // Récupération du jour de la semaine
54
58
  const daysOfWeek = ["Mon", "Tues", "Wed", "Thur", "Frid", "Sat", "Sun"];
55
59
  const dayOfWeek = daysOfWeek[date.getDay()];
56
- // Récupération de l'heure
57
60
  let hours = date.getHours();
58
- // Conversion de l'heure au format 12 heures
59
- // hours = hours % 12 || 12;
60
-
61
- // Récupération des minutes
62
61
  const minutes = date.getMinutes();
63
-
64
- // Construction de la date au format souhaité
65
62
  const formattedDate = `${hours.toString().padStart(2, "0")}h:${minutes
66
63
  .toString()
67
64
  .padStart(2, "0")}`;
68
-
69
65
  return { formattedDate, dayOfWeek };
70
66
  }
71
67
 
72
- function millisecondsToInt(milliseconds: number) {
68
+ // Convert milliseconds to integer representation
69
+ export function millisecondsToInt(milliseconds: number) {
73
70
  const date = new Date(milliseconds);
74
-
75
- // Récupération du jour de la semaine
76
71
  const daysOfWeek = [
77
- "Dimanche",
78
- "Lundi",
79
- "Mardi",
80
- "Mercredi",
81
- "Jeudi",
82
- "Vendredi",
83
- "Samedi",
72
+ "Sunday",
73
+ "Monday",
74
+ "Tuesday",
75
+ "Wednesday",
76
+ "Thursday",
77
+ "Friday",
78
+ "Saturday",
84
79
  ];
85
- const dayOfWeek = daysOfWeek[date.getDay()];
86
-
87
- // Récupération du jour du mois
88
- const dayOfMonth = date.getDate();
89
-
90
- // Récupération du mois
91
80
  const months = [
92
- "janvier",
93
- "février",
94
- "mars",
95
- "avril",
96
- "mai",
97
- "juin",
98
- "juillet",
99
- "août",
100
- "septembre",
101
- "octobre",
102
- "novembre",
103
- "décembre",
81
+ "January",
82
+ "February",
83
+ "March",
84
+ "April",
85
+ "May",
86
+ "June",
87
+ "July",
88
+ "August",
89
+ "September",
90
+ "October",
91
+ "November",
92
+ "December",
104
93
  ];
94
+ const dayOfWeek = daysOfWeek[date.getDay()];
95
+ const dayOfMonth = date.getDate();
105
96
  const month = months[date.getMonth()];
106
-
107
- // Récupération de l'heure
108
97
  let hours = date.getHours();
109
98
  const amOrPm = hours >= 12 ? " pm" : " am";
110
-
111
- // Conversion de l'heure au format 12 heures
112
- // hours = hours % 12 || 12;
113
-
114
- // Récupération des minutes
115
99
  const minutes = date.getMinutes();
116
-
117
- // Construction de la date au format souhaité
118
100
  const formattedDate = hours.toString().padStart(2, "0");
119
-
120
101
  return { formattedDate, dayOfWeek };
121
102
  }
122
- function getWeekDays(jump: number) {
103
+
104
+ // Get days of the week with a jump offset
105
+ export function getWeekDays(jump: number) {
123
106
  const days = ["Sun", "Mon", "Tues", "Wed", "Thur", "Frid", "Sat"];
124
107
  const month = [
125
108
  "Jan",
126
- "Fev",
109
+ "Feb",
127
110
  "Mar",
128
- "Avr",
129
- "Mai",
130
- "Jui",
131
- "Juil",
132
- "Aôu",
111
+ "Apr",
112
+ "May",
113
+ "Jun",
114
+ "Jul",
115
+ "Aug",
133
116
  "Sept",
134
117
  "Oct",
135
118
  "Nov",
136
119
  "Dec",
137
120
  ];
138
121
  const currentDate = new Date();
139
- const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
122
+ const currentDayOfWeek = currentDate.getDay();
140
123
  let weekDays = [];
141
124
 
142
125
  for (let i = 0; i < 7; i++) {
@@ -147,10 +130,9 @@ function getWeekDays(jump: number) {
147
130
  } else {
148
131
  day.setDate(currentDate.getDate() + diff + jump);
149
132
  }
150
-
151
- const formattedDay = `${days[day.getDay()]}. ${day.getDate()}, ${
133
+ const formattedDay = `${days[day.getDay()]}. ${day.getDate()}, ${
152
134
  month[day.getMonth()]
153
- } ${day.getFullYear()}`;
135
+ } ${day.getFullYear()}`;
154
136
  weekDays.push({
155
137
  day: days[day.getDay()],
156
138
  dayMonth: month[day.getMonth()],
@@ -158,292 +140,10 @@ function getWeekDays(jump: number) {
158
140
  dayOfTheMonth: day.getDate(),
159
141
  });
160
142
  }
161
-
162
- return weekDays;
163
- }
164
-
165
- function getCalandarDays(jump: number) {
166
- const days = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
167
- const month = [
168
- "Jan",
169
- "Fev",
170
- "Mar",
171
- "Avr",
172
- "Mai",
173
- "Jui",
174
- "Juil",
175
- "Aôu",
176
- "Sept",
177
- "Oct",
178
- "Nov",
179
- "Dec",
180
- ];
181
- const currentDate = new Date();
182
- const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
183
- let weekDays = [];
184
-
185
- for (let i = 0; i < 7; i++) {
186
- const day = new Date();
187
- const diff = i - currentDayOfWeek;
188
-
189
- day.setDate(currentDate.getDate() + diff + jump);
190
-
191
- const formattedDay = day;
192
- weekDays.push(formattedDay);
193
- }
194
-
195
143
  return weekDays;
196
144
  }
197
- function getWeekMonthAndYear(jump: number) {
198
- const days = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
199
- const currentDate = new Date();
200
- const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
201
- let weekMonthYear = [];
202
145
 
203
- for (let i = 0; i < 7; i++) {
204
- const day = new Date();
205
- const diff = i - currentDayOfWeek;
206
-
207
- day.setDate(currentDate.getDate() + diff + jump);
208
-
209
- const formattedDay = `${days[day.getMonth()]} - ${day.getFullYear()}`;
210
- weekMonthYear.push(formattedDay);
211
- }
212
-
213
- return weekMonthYear;
214
- }
215
- function displayDayOnModalLeft(jump: number) {
216
- const currentDate = new Date();
217
- const currentDayOfWeek = currentDate.getDay(); // Récupérer le jour de la semaine (0 pour dimanche, 1 pour lundi, etc.)
218
- let dayModal = [];
219
-
220
- for (let i = 0; i < 7; i++) {
221
- const day = new Date();
222
- const diff = i - currentDayOfWeek;
223
-
224
- day.setDate(currentDate.getDate() + diff + jump);
225
- dayModal.push(day);
226
- }
227
-
228
- return dayModal;
229
- }
230
- function getWeeksListUpdate(annee: any) {
231
- // Créer un objet Date pour le premier jour de l'année
232
- const premierJour = new Date(annee, 0, 1);
233
-
234
- // Créer un tableau vide pour stocker les semaines
235
- const weeksList = [];
236
-
237
- // Créer des tableaux pour les jours de la semaine et les mois
238
- const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
239
- const months = [
240
- "Jan",
241
- "Fev",
242
- "Mar",
243
- "Avr",
244
- "Mai",
245
- "Jui",
246
- "Juil",
247
- "Aôu",
248
- "Sept",
249
- "Oct",
250
- "Nov",
251
- "Dec",
252
- ];
253
-
254
- // Obtenir le nombre de semaines dans l'année
255
- const nombreSemaines = moment().year(annee).weeksInYear();
256
-
257
- // Faire une boucle sur les semaines
258
- for (let i = 0; i < nombreSemaines; i++) {
259
- // Calculer le début et la fin de la semaine en ajoutant le nombre de jours correspondant
260
- const weekStart = new Date(annee, 0, 1 + i * 7 - premierJour.getDay());
261
- const weekEnd = new Date(annee, 0, 1 + i * 7 - premierJour.getDay() + 6);
262
-
263
- // Formater les dates au format souhaité
264
- const formattedStart = `${
265
- daysOfWeek[weekStart.getDay()]
266
- }.${weekStart.getDate()} ${
267
- months[weekStart.getMonth()]
268
- } ${weekStart.getFullYear()}`;
269
- const formattedEnd = `${
270
- daysOfWeek[weekEnd.getDay()]
271
- }.${weekEnd.getDate()} ${
272
- months[weekEnd.getMonth()]
273
- } ${weekEnd.getFullYear()}`;
274
-
275
- // Ajouter la semaine au tableau
276
- weeksList.push(`${formattedStart} - ${formattedEnd}`);
277
- }
278
-
279
- // Retourner le tableau des semaines
280
- return weeksList;
281
- }
282
-
283
- function getWeeksList() {
284
- const today = new Date();
285
- const weeksList = [];
286
- const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
287
- const months = [
288
- "Jan",
289
- "Fev",
290
- "Mar",
291
- "Avr",
292
- "Mai",
293
- "Jui",
294
- "Juil",
295
- "Aôu",
296
- "Sept",
297
- "Oct",
298
- "Nov",
299
- "Dec",
300
- ];
301
- for (let i = -5; i <= 5; i++) {
302
- const weekStart = new Date(
303
- today.getFullYear(),
304
- today.getMonth(),
305
- today.getDate() + i * 7 - today.getDay()
306
- );
307
- const weekEnd = new Date(
308
- today.getFullYear(),
309
- today.getMonth(),
310
- today.getDate() + i * 7 - today.getDay() + 6
311
- );
312
-
313
- const options = {
314
- weekday: "short",
315
- day: "numeric",
316
- month: "short",
317
- year: "numeric",
318
- };
319
- const dayOfWeek = daysOfWeek[weekStart.getDay()];
320
- const formattedStart = `${
321
- daysOfWeek[weekStart.getDay()]
322
- }.${weekStart.getDate()} ${
323
- months[weekStart.getMonth()]
324
- } ${weekStart.getFullYear()}`;
325
- // const formattedStart = weekStart.toLocaleDateString('fr-FR', options);
326
- const formattedEnd = `${
327
- daysOfWeek[weekEnd.getDay()]
328
- }.${weekEnd.getDate()} ${
329
- months[weekEnd.getMonth()]
330
- } ${weekEnd.getFullYear()}`;
331
-
332
- weeksList.push(`${formattedStart} - ${formattedEnd}`);
333
- }
334
-
335
- return weeksList;
336
- }
337
- function getDoubleWeeksList() {
338
- const today = new Date();
339
- const weeksList = [];
340
- const daysOfWeek = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
341
- const months = [
342
- "Jan",
343
- "Fev",
344
- "Mar",
345
- "Avr",
346
- "Mai",
347
- "Jui",
348
- "Juil",
349
- "Aôu",
350
- "Sept",
351
- "Oct",
352
- "Nov",
353
- "Dec",
354
- ];
355
- for (let i = -5; i <= 5; i++) {
356
- const weekStart = new Date(
357
- today.getFullYear(),
358
- today.getMonth(),
359
- today.getDate() + i * 7 - today.getDay()
360
- );
361
- const weekEnd = new Date(
362
- today.getFullYear(),
363
- today.getMonth(),
364
- today.getDate() + i * 7 - today.getDay() + 13
365
- );
366
-
367
- const options = {
368
- weekday: "short",
369
- day: "numeric",
370
- month: "short",
371
- year: "numeric",
372
- };
373
- const dayOfWeek = daysOfWeek[weekStart.getDay()];
374
- const formattedStart = `${
375
- daysOfWeek[weekStart.getDay()]
376
- }.${weekStart.getDate()} ${
377
- months[weekStart.getMonth()]
378
- } ${weekStart.getFullYear()}`;
379
- // const formattedStart = weekStart.toLocaleDateString('fr-FR', options);
380
- const formattedEnd = `${
381
- daysOfWeek[weekEnd.getDay()]
382
- }.${weekEnd.getDate()} ${
383
- months[weekEnd.getMonth()]
384
- } ${weekEnd.getFullYear()}`;
385
-
386
- weeksList.push(`${formattedStart} - ${formattedEnd}`);
387
- }
388
-
389
- return weeksList;
390
- }
391
-
392
- function formatDateToCustomFormat(dateString: string) {
393
- // Tableau contenant les noms des jours de la semaine en français
394
- const daysOfWeek = [
395
- "Dimanche",
396
- "Lundi",
397
- "Mardi",
398
- "Mercredi",
399
- "Jeudi",
400
- "Vendredi",
401
- "Samedi",
402
- ];
403
-
404
- // Tableau contenant les noms des mois en français
405
- const months = [
406
- "janvier",
407
- "février",
408
- "mars",
409
- "avril",
410
- "mai",
411
- "juin",
412
- "juillet",
413
- "août",
414
- "septembre",
415
- "octobre",
416
- "novembre",
417
- "décembre",
418
- ];
419
-
420
- // Créer un objet Date à partir de la chaîne de caractères
421
- const date = new Date(dateString);
422
-
423
- // Récupérer le jour de la semaine, le jour du mois et le mois
424
- const dayOfWeek = daysOfWeek[date.getDay()];
425
- const dayOfMonth = date.getDate();
426
- const month = months[date.getMonth()];
427
-
428
- // Formater la date dans le format 'jour_de_la_semaine jour_du_mois mois'
429
- const formattedDate = `${dayOfWeek} ${dayOfMonth} ${month}`;
430
-
431
- return formattedDate;
432
- }
433
-
434
- function clickedDate(dateString: string) {
435
- // Créer un objet Date à partir de la chaîne de caractères
436
- const date = new Date(dateString);
437
- return date;
438
- }
439
- const calculateTimeOfDayRange = (start: number, end: number) => {
440
- const hourToMillisecond = 3600000;
441
- const range = [];
442
- for (let i = start; i < end; i += hourToMillisecond) {
443
- range.push(i);
444
- }
445
- return range;
446
- };
146
+ // The remaining functions follow the same structure. Ensure all comments are in English and make the functions exportable as required.
447
147
 
448
148
  /**
449
149
  * Get the ISO week number for a given date.
@@ -480,7 +180,7 @@ function updateSelectedDateForEcartSemaine(dateSelectionnee: Date): Date {
480
180
  * @param dateSelectionnee - The selected date.
481
181
  * @returns The week difference in days.
482
182
  */
483
- function calculerEcartSemaine(dateSelectionnee: Date): number {
183
+ export function calculerEcartSemaine(dateSelectionnee: Date): number {
484
184
  if (!dateSelectionnee) {
485
185
  return 0;
486
186
  }
@@ -522,7 +222,7 @@ function semainesDepuisOrigine(annee: number, numeroSemaine: number): number {
522
222
  return nombreSemaines;
523
223
  }
524
224
 
525
- function getSessionStorageRecordForDragAndDrop(
225
+ export function getSessionStorageRecordForDragAndDrop(
526
226
  tasks: TasksType,
527
227
  positionDay: number,
528
228
  dropGroupId: string
@@ -566,7 +266,7 @@ function getSessionStorageRecordForDragAndDrop(
566
266
  return { taskDropStart, taskDropEnd, taskDropDate, newTask, newTasks };
567
267
  }
568
268
 
569
- function compareWeekOffset(
269
+ export function compareWeekOffset(
570
270
  calendarDate: Date,
571
271
  weekOffset: number,
572
272
  taskDate: Date
@@ -581,7 +281,7 @@ function compareWeekOffset(
581
281
  return weekOffset === calculerEcartSemaine(taskDate);
582
282
  }
583
283
 
584
- const sumHoursByGroups = (
284
+ export const sumHoursByGroups = (
585
285
  groupId: string,
586
286
  tasks: TasksType | any,
587
287
  weekOffset: number,
@@ -599,7 +299,7 @@ const sumHoursByGroups = (
599
299
  return sum;
600
300
  };
601
301
 
602
- function saveTasksToLocalStorage(tasks: TasksType) {
302
+ export function saveTasksToLocalStorage(tasks: TasksType) {
603
303
  if (typeof window !== "undefined") {
604
304
  window.localStorage.setItem("Calendar", "je marche");
605
305
  const tasksSavedString = window.localStorage.getItem("CalendarTaskSaved");
@@ -620,25 +320,77 @@ function saveTasksToLocalStorage(tasks: TasksType) {
620
320
  }
621
321
  }
622
322
 
623
- export {
624
- getWeeksListUpdate,
625
- saveTasksToLocalStorage,
626
- clickedDate,
627
- getCalandarDays,
628
- startDateMilliseconds,
629
- endDateMilliseconds,
630
- getDayHourly,
631
- millisecondsToDate,
632
- getWeekDays,
633
- formatDateToCustomFormat,
634
- displayDayOnModalLeft,
635
- millisecondsToInt,
636
- getWeekMonthAndYear,
637
- getWeeksList,
638
- getDoubleWeeksList,
639
- calculerEcartSemaine,
640
- calculateTimeOfDayRange,
641
- getSessionStorageRecordForDragAndDrop,
642
- compareWeekOffset,
643
- sumHoursByGroups,
323
+ export const updateCalendarDateWithOffset = (
324
+ offset: number,
325
+ calendarDate: Date
326
+ ) => {
327
+ const newDate = new Date(calendarDate);
328
+ newDate.setDate(newDate.getDate() + offset);
329
+ return newDate;
330
+ };
331
+
332
+ export const updateOffsetWithDateCalendar = (calendarDate: Date) => {
333
+ return calculerEcartSemaine(calendarDate);
334
+ };
335
+
336
+ export const millisecondsToHours = (milliseconds: number) => {
337
+ return millisecondsToDate(milliseconds).formattedDate;
338
+ };
339
+ export const checkDuplicates = (
340
+ tasks: TasksType,
341
+ taskStart: number,
342
+ taskEnd: number,
343
+ groupId: string
344
+ ) => {
345
+ const findDuplicates = tasks
346
+ ?.filter(
347
+ (task) =>
348
+ (taskStart >= task.taskStart && taskStart < task.taskEnd) ||
349
+ (taskEnd > task.taskStart && taskEnd < task.taskEnd) ||
350
+ (taskStart <= task.taskStart &&
351
+ taskEnd > task.taskStart &&
352
+ taskEnd >= task.taskEnd &&
353
+ taskStart <= task.taskEnd)
354
+ )
355
+ .filter((task) => task.groupId === groupId);
356
+ return findDuplicates.length > 0;
357
+ };
358
+
359
+ export const getSavedTasks = () => {
360
+ const taskSavedString = window.localStorage.getItem("CalendarTaskSaved");
361
+ if (!taskSavedString) {
362
+ return [];
363
+ }
364
+ const tasksTable: TasksType = JSON.parse(taskSavedString);
365
+
366
+ const savedTasks: TasksType | any = tasksTable.map((task) => {
367
+ const { taskDate, taskExpiryDate, ...rest } = task;
368
+ if (taskExpiryDate) {
369
+ return {
370
+ taskDate: new Date(taskDate),
371
+ taskExpiryDate: new Date(taskExpiryDate),
372
+ ...rest,
373
+ };
374
+ }
375
+ });
376
+ return savedTasks;
377
+ };
378
+
379
+ export const deleteTaskSaved = (taskId: string) => {
380
+ const tasksSavedString = window.localStorage.getItem("CalendarTaskSaved");
381
+ if (!tasksSavedString) return;
382
+ const tasksSavedTable: TasksType = JSON.parse(tasksSavedString);
383
+ const taskIndex = tasksSavedTable.findIndex((task) => task.taskId === taskId);
384
+ if (taskIndex) {
385
+ tasksSavedTable.splice(taskIndex, 1);
386
+ window.localStorage.setItem(
387
+ "CalendarTaskSaved",
388
+ JSON.stringify(tasksSavedTable)
389
+ );
390
+ }
391
+ };
392
+
393
+ export const deleteTasksSaved = () => {
394
+ window.localStorage.removeItem("CalendarTaskSaved");
644
395
  };
396
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-weekly-planning",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "jest",