feat: add absence notification and analytics features

- Implemented AbsenceNotifyView for notifying absence with session details.
- Created AnalyticsView for displaying group analytics and managing students at risk.
- Added ClassAttendanceView for marking attendance in classes.
- Defined new schemas for analytics and attendance in shared package.
This commit is contained in:
Jose Selesan
2026-09-23 16:24:45 -03:00
parent a363e9e8fc
commit 2e184845e1
59 changed files with 3854 additions and 23 deletions

View File

@@ -22,7 +22,7 @@ export type NextClassOccurrence = {
};
// Convierte un tiempo de "pared" (wall clock) expresado en `timeZone` al instante absoluto.
function zonedWallClockToUtc(wall: string, timeZone: string): Date {
export function zonedWallClockToUtc(wall: string, timeZone: string): Date {
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/.exec(wall);
if (!match) {
throw new Error(`Invalid wall clock: ${wall}`);
@@ -64,7 +64,7 @@ function zonedWallClockToUtc(wall: string, timeZone: string): Date {
return new Date(asUtc.getTime() + offsetMs);
}
function wallDateInTimeZone(now: Date, timeZone: string): { year: number; month: number; day: number } {
export function wallDateInTimeZone(now: Date, timeZone: string): { year: number; month: number; day: number } {
const wall = new Intl.DateTimeFormat('en-US', {
timeZone,
year: 'numeric',
@@ -143,4 +143,46 @@ export function nextClassOccurrence(opt: {
function pad(value: number): string {
return String(value).padStart(2, '0');
}
// Instante absoluto de la clase de HOY (aunque la hora ya haya pasado), o null si el grupo
// no tiene clase programada para el día de `now` en `timeZone`.
export function todayOccurrence(opt: {
days: WeekDay[];
time: string;
now: Date;
timeZone: string;
}): Date | null {
const { days, time, now, timeZone } = opt;
if (days.length === 0 || !time) {
return null;
}
const [hour, minute] = time.split(':').map(Number);
if (
Number.isNaN(hour) ||
Number.isNaN(minute) ||
hour < 0 ||
hour > 23 ||
minute < 0 ||
minute > 59
) {
return null;
}
const { year, month, day } = wallDateInTimeZone(now, timeZone);
const dow = new Date(Date.UTC(year, month - 1, day)).getUTCDay();
const dayMatches = days.some((d) => WEEKDAY_TO_DOW[d] === dow);
if (!dayMatches) {
return null;
}
const wall = `${year}-${pad(month)}-${pad(day)}T${pad(hour)}:${pad(minute)}`;
return zonedWallClockToUtc(wall, timeZone);
}
// Primer instante del día de `now` en `timeZone` (medianoche local).
export function startOfDayInTimeZone(now: Date, timeZone: string): Date {
const { year, month, day } = wallDateInTimeZone(now, timeZone);
return zonedWallClockToUtc(`${year}-${pad(month)}-${pad(day)}T00:00`, timeZone);
}