- ✅ Ticket 1.1: Estructura Clean Architecture en backend - ✅ Ticket 1.2: Schemas Zod compartidos - ✅ Ticket 1.3: Refactorización drugs.ts (1362 → 8 archivos modulares) - ✅ Ticket 1.4: Refactorización procedures.ts (3583 → 6 archivos modulares) - ✅ Ticket 1.5: Eliminación de duplicidades (~50 líneas) Cambios principales: - Creada estructura Clean Architecture en backend/src/ - Schemas Zod compartidos en backend/src/shared/schemas/ - Refactorización modular de drugs y procedures - Utilidades genéricas en src/utils/ (filter, validation) - Eliminados scripts obsoletos y documentación antigua - Corregidos errores: QueryClient, import test-error-handling - Build verificado y funcionando correctamente
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
import { toDate } from "./toDate.mjs";
|
|
|
|
/**
|
|
* @name isWithinInterval
|
|
* @category Interval Helpers
|
|
* @summary Is the given date within the interval?
|
|
*
|
|
* @description
|
|
* Is the given date within the interval? (Including start and end.)
|
|
*
|
|
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
*
|
|
* @param date - The date to check
|
|
* @param interval - The interval to check
|
|
*
|
|
* @returns The date is within the interval
|
|
*
|
|
* @example
|
|
* // For the date within the interval:
|
|
* isWithinInterval(new Date(2014, 0, 3), {
|
|
* start: new Date(2014, 0, 1),
|
|
* end: new Date(2014, 0, 7)
|
|
* })
|
|
* //=> true
|
|
*
|
|
* @example
|
|
* // For the date outside of the interval:
|
|
* isWithinInterval(new Date(2014, 0, 10), {
|
|
* start: new Date(2014, 0, 1),
|
|
* end: new Date(2014, 0, 7)
|
|
* })
|
|
* //=> false
|
|
*
|
|
* @example
|
|
* // For date equal to interval start:
|
|
* isWithinInterval(date, { start, end: date })
|
|
* // => true
|
|
*
|
|
* @example
|
|
* // For date equal to interval end:
|
|
* isWithinInterval(date, { start: date, end })
|
|
* // => true
|
|
*/
|
|
export function isWithinInterval(date, interval) {
|
|
const time = +toDate(date);
|
|
const [startTime, endTime] = [
|
|
+toDate(interval.start),
|
|
+toDate(interval.end),
|
|
].sort((a, b) => a - b);
|
|
|
|
return time >= startTime && time <= endTime;
|
|
}
|
|
|
|
// Fallback for modularized imports:
|
|
export default isWithinInterval;
|