Skip to content

🐞 - DateRange + minLength / maxLength (with month / year params) has incorrect limits #1884

Open
@nsbarsukov

Description

Which package(s) are the source of the bug?

@maskito/kit

Playground Link

https://maskito.dev/kit/date-range/API?maxLength$=1

Description

Reproduction

Case 1

  1. Open https://maskito.dev/kit/date-range/API?maxLength$=1 (maxLength: {month: 1})
  2. Enter 01.01.2025 – 01.02.2025

Expected behavior: 31.01.2025 is max allowed end of date range
Actual behavior: mask allows to enter 01.02.2025

Case 2

  1. Open https://maskito.dev/kit/date-range/API?maxLength$=1 (maxLength: {month: 1})
  2. Enter 31.01.2025 – 03.03.2025

Expected behavior: 27.02.2025 is max allowed end of date range
Actual behavior: mask allows to enter 03.03.2025


Why the current behavior is incorrect ?

Explore Taiga UI's CalendarRange behavior:
https://taiga-ui.dev/components/calendar-range/API?maxLength$=1 (maxLength: {month: 1})

calendar-range.mov

How to solve this issue ?

Modify the following logic

export function appendDate(
initialDate: Date,
{day, month, year}: Partial<MaskitoDateSegments<number>> = {},
): Date {
const date = new Date(initialDate);
if (day) {
date.setDate(date.getDate() + day);
}
if (month) {
date.setMonth(date.getMonth() + month);
}
if (year) {
date.setFullYear(date.getFullYear() + year);
}
return date;

to satisfy Taiga UI behavior.

Maskito version

3.2.0

Which browsers have you used?

  • Chrome
  • Firefox
  • Safari
  • Edge

Which operating systems have you used?

  • macOS
  • Windows
  • Linux
  • iOS
  • Android

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingscope: kitRelated to @maskito/kit

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions