taiga-family / taiga-ui

Angular UI Kit and components library for awesome people
https://taiga-ui.dev
Apache License 2.0
3.1k stars 408 forks source link

🐞 - TuiDay не корректно парсит дату #7964

Closed evoytenkoapps closed 6 days ago

evoytenkoapps commented 1 week ago

Playground Link

No response

Description

при дате '2024-1-20'; месяц уходит в дату при '2024-01-20'; все норм мне кажется что если есть тире, то это однозначный разделитель дат.

  it('Должен конвертировать в дату тайги, через тире', () => {
    const data = '2024-1-20';
    const convertedData = {day: 20, month: 0, year: 2024} as TuiDay;

    expect(service.formatTuiDay(data, 'YMD')).toEqual(convertedData);
  });
// сам метод
    formatTuiDay(date: string, dateMode?: TuiDateMode): TuiDay {
    return TuiDay.normalizeParse(date, dateMode);
  }
Снимок экрана 2024-06-27 в 12 31 48

Angular version

No response

Taiga UI version

No response

Which browsers have you used?

Which operating systems have you used?

hakimio commented 6 days ago

When you are using YMD format, it expects 2 digit day and month: yyyy-mm-dd. Your 2024-1-20 date doesn't match the format. It should be 2024-01-20 instead.

Parsing logic: https://github.com/taiga-family/taiga-ui/blob/b4ca77b9fbd84ed6776d9605262fc975e65088d0/projects/cdk/date-time/day.ts#L124

waterplea commented 6 days ago

hakimio is right, you should also see [parseRawDateString]: wrong date string length assertion error in console. You are welcome to create a PR if you want to support this format, but currently it is working as planned. As a workaround TuiDay.fromLocalNativeDate(new Date('2024-1-20')) seems to work.