react-component / picker

📅 All Date Pickers you need.
https://picker.react-component.now.sh/
MIT License
257 stars 295 forks source link

fix(WeekPicker):cross year select not selected at panel #751

Open huiliangShen opened 5 months ago

huiliangShen commented 5 months ago

fix antd@4.x bug 周选择时间控件选中跨年周时无高亮问题 It's cause isSameWeek function. for example: use 2024 first week, first date is 2023-12-31 (sunday) when local is US. so when I click 2024-01-01, it's will be run the following code. isSameWeek receive generateConfig, US, 2024-01-01 and 2023-12-31, following logic, it's will be return false, because the two date is not same year. we need to use generateConfig.locale.getWeekFirstDate function to calc date then judge is same year.

  const rowClassName = (date: DateType) =>
    classNames(rowPrefixCls, {
      [`${rowPrefixCls}-selected`]: isSameWeek(
        generateConfig,
        locale.locale,
        value,
        date,
      ),
    });
export function isSameWeek<DateType>(
  generateConfig: GenerateConfig<DateType>,
  locale: string,
  date1: NullableDateType<DateType>,
  date2: NullableDateType<DateType>,
) {
  const equal = isNullEqual(date1, date2);
  if (typeof equal === 'boolean') {
    return equal;
  }
  // const weekStartDate1 = generateConfig.locale.getWeekFirstDate(locale, date1!);
  // const weekStartDate2 = generateConfig.locale.getWeekFirstDate(locale, date2!);
  return (
    isSameYear(generateConfig, date1, date2) &&
    generateConfig.locale.getWeek(locale, date1!) === generateConfig.locale.getWeek(locale, date2!)
  );
}
vercel[bot] commented 5 months ago

Someone is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (fd5fe22) 99.09% compared to head (bd3f096) 99.09%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## 2.7.x #751 +/- ## ======================================= Coverage 99.09% 99.09% ======================================= Files 47 47 Lines 2215 2217 +2 Branches 675 675 ======================================= + Hits 2195 2197 +2 Misses 18 18 Partials 2 2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.