Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateRangePicker - Error on week number for 2025 #3935

Open
mojimbo80 opened this issue Aug 22, 2024 · 8 comments
Open

DateRangePicker - Error on week number for 2025 #3935

mojimbo80 opened this issue Aug 22, 2024 · 8 comments

Comments

@mojimbo80
Copy link

What version of rsuite are you using?

5.69.0

What version of React are you using?

18

What version of TypeScript are you using (if any)?

No response

What browser are you using?

Chrome

Describe the Bug

On https://rsuitejs.com/components/date-range-picker/, section Show Week Numbers, the DateRangePicker display 53 weeks for 2025.
rsuitedaterangepicker

But in reality there is only 52 weeks for 2025 : https://calendar.online/calendar-weeks/2025

I think it is a bug.

Expected Behavior

No response

To Reproduce

No response

@mojimbo80 mojimbo80 reopened this Aug 23, 2024
@mojimbo80
Copy link
Author

Finally I think, it's real bug.
Can you explain me, why, the first week for 2025, will begin, sunday 4 january ?

@simonguo
Copy link
Member

Finally I think, it's real bug. Can you explain me, why, the first week for 2025, will begin, sunday 4 january ?

This is the week number display, is it different from the week number you see? The calculation of the week number is obtained using the format method of date-fns to get the local week number of the year.

image

@mojimbo80
Copy link
Author

This is the week number display, is it different from the week number you see?
Sorry, i don't understand the difference :-(.

Like you see, when i use my Google Calendar, it display the good week number for 2025 (52) and the first week of 2026 will begin the 28 december.
googlecalendar

I have check the DatePicker of Ant and Material-UI and it display 52 week and the first week of 2026 will begin the 28 december too.

But with Rsuite, we have 53 weeks for 2025 and the first week of 2026 will begin the 4 january, and i think it's wrong. :-(

@simonguo
Copy link
Member

The day the first week of the year starts depends on the region. The ISO 8601 standard is as follows:

Determining Week 1
In practice week 1 (W01 in ISO notation) of any year can be determined as follows:

  • If 1 January falls on a Monday, Tuesday, Wednesday or Thursday, then the week of 1 January is Week 1. Except in the case of 1 January falling on a Monday, this Week 1 includes the last day(s) of the previous year.
  • If 1 January falls on a Friday, Saturday, or Sunday, then 1 January is considered to be part of the last week of the previous year. Week 1 will begin on the first Monday after 1 January.

Examples:

  • Week 1 of 2015 (2015W01 in ISO notation) started on Monday, 29 December 2014 and ended on Sunday, 4 January 2015, > because 1 January 2015 fell on Thursday.
  • Week 1 of 2021 (2021W01 in ISO notation) started on Monday, 4 January 2021 and ended on Sunday, 10 January 2021, because 1 January 2021 fell on Friday.

Week 52 and 53
It is also possible to determine if the last week of the previous year was Week 52 or Week 53 as follows:

  • If 1 January falls on a Friday, then it is part of Week 53 of the previous year (W53-5).
  • If 1 January falls on a Saturday,
    • then it is part of Week 53 of the previous year if that is a leap year (W53-6),
    • and part of Week 52 otherwise (W52-6), i.e. if the previous year is a common year.
  • If 1 January falls on a Sunday, then it is part of Week 52 of the previous year (W52-7).

Please see https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system for more information.

Currently, the firstWeekContainsDate configured in rsuite is 4, which means that the first week of the year is the week that contains January 4th. In future versions, I will consider providing a configuration item that allows users to customize this value.

@mojimbo80
Copy link
Author

Thank you for your explanations.
The possibility to configure the first week will be very usefull and will solve the problem of differences between the regions of the world.
Have a good day !

@simonguo
Copy link
Member

simonguo commented Sep 4, 2024

I found that date-fns sets different firstWeekContainsDate default values for different regions. Based on this, I made a fix. You can see if it solves the problem you encountered.

https://rsuite-nextjs-git-fix-calendar-firstweekcontainsdate-rsuite.vercel.app/guide/i18n/#usage

@mojimbo80
Copy link
Author

mojimbo80 commented Sep 19, 2024

Infortunately i think is not OK :p.
If you see the screenshoot above (google calendar), the 52th month of 2025 begin to the 21 december and finish the 27 december.
With the update (locale Fr) it begin the 28 december and finish the 3 january 2026.

@simonguo
Copy link
Member

Hi @mojimbo80

Google Calendar should be using the week number calculated in US time. I can see the same week number as Google Calendar when I switch the language to en-US.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants