This commit is contained in:
nessar committed 2026-10-07 00:28:29 +02:00
1 parent 03841c6e3d
commit 036a8c0e1e
32 files changed
+1805 -89

No files matched your search

+12 -26
View File
@@ -1,6 +1,6 @@
import { Injectable, inject } from '@angular/core';
import { DateRange } from '@angular/material/datepicker';
import Holidays, { HolidaysTypes } from 'date-holidays';
import { frenchPublicHolidaysForYear } from './declared-non-working-days';
import dayjs from 'dayjs';
import weekOfYear from 'dayjs/plugin/weekOfYear';
import isoWeek from 'dayjs/plugin/isoWeek';
@@ -18,12 +18,6 @@ import { addPlanningDays, addPlanningYears, planningDateInParis } from './planni
dayjs.extend(weekOfYear);
dayjs.extend(isoWeek);
const lang = 'en';
const allTypesOptions: HolidaysTypes.Options = {
languages: [lang],
};
@Injectable({
providedIn: 'root',
})
@@ -39,7 +33,7 @@ export class CalendarService {
}
selectedDatesForPlan(
plan: Pick<PlanOutcome, 'placements'> & {
plan: Pick<PlanOutcome, 'placements' | 'declaredDays'> & {
horizon?: { start: string; end: string };
timeOffPeriods?: PlanOutcome['timeOffPeriods'];
},
@@ -55,7 +49,14 @@ export class CalendarService {
const selected = projectionHorizon
? this.getSelectedDatesForHorizon(projectionHorizon)
: this.getSelectedDatesForYear();
for (const placement of plan.placements) {
for (const placement of [
...plan.placements,
...(plan.declaredDays ?? []).filter(
(day) =>
!plan.horizon ||
(day.date >= plan.horizon.start && day.date < plan.horizon.end),
),
]) {
selected.push(
new SelectedDate(
dayTypeForLeaveType[placement.type],
@@ -69,8 +70,6 @@ export class CalendarService {
return selected;
}
private readonly holidaysByYear = new Map<number, number[]>();
// Get selected dates from current date to the next year
getSelectedDatesFromNow(): SelectedDates {
const _holidays = this.getHolidays();
@@ -156,21 +155,8 @@ export class CalendarService {
getHolidays(startYear = this.dateCache.getCurrentYear(), lastYear = startYear + 1): Date[] {
const dates: Date[] = [];
for (let year = startYear; year <= lastYear; year++) {
let timestamps = this.holidaysByYear.get(year);
if (!timestamps) {
const calendar = new Holidays('FR', allTypesOptions);
timestamps = calendar
.getHolidays(year, lang)
.filter((holiday) => holiday.type === 'public')
.map((holiday) => {
const dateOnly = String(holiday.date).match(/^\d{4}-\d{2}-\d{2}/)?.[0];
return (
dateOnly ? new Date(`${dateOnly}T00:00:00`) : new Date(holiday.date)
).getTime();
});
this.holidaysByYear.set(year, timestamps);
}
dates.push(...timestamps.map((timestamp) => new Date(timestamp)));
for (const date of frenchPublicHolidaysForYear(year))
dates.push(new Date(`${date}T00:00:00`));
}
return dates;
}