Opened 7 years ago

Last modified 6 years ago

#14907 open bug

jQuery UI Datepicker showing incorrect week number

Reported by: Cameron Owned by:
Priority: major Milestone: none
Component: ui.datepicker Version: 1.11.3
Keywords: Cc:
Blocked by: Blocking:


When using the jQuery UI Datepicker and starting the week on a Sunday, the week numbers are incorrect. For example, 3rd Jan 2016 should be week 1 as all of the dates (3rd to 9th) are in the same year. But as you can see in the screenshot below, the UI shows it as week 53.

Here is the code to render the datepicker:

$("#datepicker" ).datepicker({
    showWeek: true,
    firstDay: 0

So nothing special, other than showing the week numbers and starting the week on Sunday instead of Monday (as per default).

Here is a fiddle of the issue:

Change History (5)

comment:1 Changed 7 years ago by dasago87

I got the same problem. If firstDay is set to 1 it works fine.

comment:2 Changed 7 years ago by Scott González

#14910 is a duplicate of this ticket.

comment:3 Changed 7 years ago by Scott González

Status: newopen

comment:4 Changed 7 years ago by Asaf Jaffi

This issue happens because the print date of the work week is taken from the first date of the picker's rows. When the first date is a Sunday (firstDay: 0), then it's passed to iso8601Week which states that it will "Find Thursday of this week starting on Monday", and Sundays just count as last week.

comment:5 Changed 6 years ago by Russell G

This isn't so much a problem with the way iso8601Week calculates dates as it is the way the week number is displayed in its own column on the left side of the calendar when firstDay is set to 0 for Sunday. The ISO 8601 spec says that week numbers start on Monday, so the first day of week 1 in 2016 is Monday the 4th. But there's no good way to display Sunday the 3rd as week 53 and Monday the 4th as week 1, both on the same row. Maybe the showWeek option should be disabled when firstDay is set to 0, or maybe the week number should be displayed in each Monday cell, as Google Calendar does it, instead of in a separate column for the whole row.

Note: See TracTickets for help on using tickets.