- ✅ 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
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
"use strict";
|
|
exports.clamp = clamp;
|
|
var _index = require("./max.js");
|
|
var _index2 = require("./min.js");
|
|
|
|
/**
|
|
* @name clamp
|
|
* @category Interval Helpers
|
|
* @summary Return a date bounded by the start and the end of the given interval
|
|
*
|
|
* @description
|
|
* Clamps a date to the lower bound with the start of the interval and the upper
|
|
* bound with the end of the interval.
|
|
*
|
|
* - When the date is less than the start of the interval, the start is returned.
|
|
* - When the date is greater than the end of the interval, the end is returned.
|
|
* - Otherwise the date is returned.
|
|
*
|
|
* @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 be bounded
|
|
* @param interval - The interval to bound to
|
|
*
|
|
* @returns The date bounded by the start and the end of the interval
|
|
*
|
|
* @example
|
|
* // What is Mar, 21, 2021 bounded to an interval starting at Mar, 22, 2021 and ending at Apr, 01, 2021
|
|
* const result = clamp(new Date(2021, 2, 21), {
|
|
* start: new Date(2021, 2, 22),
|
|
* end: new Date(2021, 3, 1),
|
|
* })
|
|
* //=> Mon Mar 22 2021 00:00:00
|
|
*/
|
|
function clamp(date, interval) {
|
|
return (0, _index2.min)([
|
|
(0, _index.max)([date, interval.start]),
|
|
interval.end,
|
|
]);
|
|
}
|