diff --git a/cookies.txt b/cookies.txt index bf5f9aa..a0cd3af 100644 --- a/cookies.txt +++ b/cookies.txt @@ -2,4 +2,4 @@ # https://curl.se/docs/http-cookies.html # This file was generated by libcurl! Edit at your own risk. -#HttpOnly_localhost FALSE / FALSE 1755333401 connect.sid s%3AjMs5qISzQqgSDWVwymmCwD7sNZeqwqW5.o9F18DbCy7ZfD1L%2BShBKs4vzlzFslz979pQixekMpmg +#HttpOnly_localhost FALSE / FALSE 1755333603 connect.sid s%3AQqa7VC9Kmev2sSuyP6rb67zs4VszjTJP.RwnrDHc4pdPJyIwe93Hg9PTGpAF73AsiSmjdDq4MC4c diff --git a/replit.md b/replit.md index fcb4967..bf9446d 100644 --- a/replit.md +++ b/replit.md @@ -29,7 +29,7 @@ The platform is built with a clear separation of concerns, utilizing a modern fu - **Data Synchronization:** Logic is implemented to ensure data consistency between development (in-memory storage) and production (PostgreSQL) environments, particularly for order status and relationships. **Feature Specifications:** -- **Weather Integration:** A comprehensive, modern weather interface displays detailed weather conditions sourced directly from the Visual Crossing API with French language support. +- **Weather Integration:** A comprehensive, modern weather interface displays detailed weather conditions sourced directly from the Visual Crossing API with French language support. Features intelligent date comparison using the same day of the week from the previous year for more relevant weather pattern analysis (e.g., Friday August 15, 2025 vs Friday August 16, 2024). - **Order and Delivery Management:** Full CRUD operations for orders and deliveries, including linking orders to deliveries and managing their statuses. - **Reconciliation:** Functionality for reconciling Bills of Lading (BL) and invoices with immediate UI updates. - **User and Permission Management:** Granular access controls ensuring that users (e.g., employees) have appropriate permissions for tasks like creating customer orders. diff --git a/server/weatherService.ts b/server/weatherService.ts index e9a7a5b..bb4b865 100644 --- a/server/weatherService.ts +++ b/server/weatherService.ts @@ -93,12 +93,45 @@ export class WeatherService { } /** - * Calcule la date de l'année précédente pour la même date + * Calcule la date de l'année précédente pour le même jour de la semaine */ getPreviousYearDate(date: Date = new Date()): string { - const previousYear = new Date(date); - previousYear.setFullYear(date.getFullYear() - 1); - return previousYear.toISOString().split('T')[0]; // Format YYYY-MM-DD + const currentYear = date.getFullYear(); + const currentMonth = date.getMonth(); + const currentDayOfWeek = date.getDay(); // 0 = dimanche, 1 = lundi, etc. + + // Créer une date pour l'année précédente, même mois + const previousYear = new Date(currentYear - 1, currentMonth, 1); + + // Trouver le premier jour de la semaine correspondant dans ce mois + const firstDayOfMonth = previousYear.getDay(); + const daysToAdd = (currentDayOfWeek - firstDayOfMonth + 7) % 7; + + // Calculer quelle semaine nous sommes dans le mois actuel + const currentDate = date.getDate(); + const currentWeekOfMonth = Math.ceil(currentDate / 7); + + // Aller à la même semaine du mois l'année précédente + const targetDate = new Date(currentYear - 1, currentMonth, 1 + daysToAdd + (currentWeekOfMonth - 1) * 7); + + // Si la date calculée dépasse le mois, prendre la dernière occurrence de ce jour dans le mois + if (targetDate.getMonth() !== currentMonth) { + // Revenir en arrière d'une semaine + targetDate.setDate(targetDate.getDate() - 7); + } + + console.log(`🗓️ [DATE-CALC] Aujourd'hui: ${date.toISOString().split('T')[0]} (${this.getDayName(currentDayOfWeek)})`); + console.log(`🗓️ [DATE-CALC] Année précédente: ${targetDate.toISOString().split('T')[0]} (${this.getDayName(targetDate.getDay())})`); + + return targetDate.toISOString().split('T')[0]; // Format YYYY-MM-DD + } + + /** + * Retourne le nom du jour de la semaine + */ + private getDayName(dayOfWeek: number): string { + const days = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi']; + return days[dayOfWeek]; } /**