/** * Relaxed day-view keyboard clamping — allows navigation past min/max within the * same calendar month, but blocks escape to a fully-outside month. * Temporary measure; strict clamping may be restored. * @see https://transferwise.atlassian.net/browse/DS-8518 */ export function clampToDayViewBoundary( date: Date, min: Date | null, max: Date | null, ): Date { if (min && date < min) { const sameMonth = date.getMonth() === min.getMonth() && date.getFullYear() === min.getFullYear(); if (sameMonth) return date; return new Date(min.getFullYear(), min.getMonth(), 1); } if (max && date > max) { const sameMonth = date.getMonth() === max.getMonth() && date.getFullYear() === max.getFullYear(); if (sameMonth) return date; return new Date(max.getFullYear(), max.getMonth() + 1, 0); } return date; }