Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

fix week of the year for us spec

ulferts73bf2205fabc
diff --git a/docs/system-admin-guide/calendars-and-dates/README.md b/docs/system-admin-guide/calendars-and-dates/README.md
index 431b0b4d265..f0a4ca47074 100644
--- a/docs/system-admin-guide/calendars-and-dates/README.md
+++ b/docs/system-admin-guide/calendars-and-dates/README.md
@@ -76,7 +76,7 @@ To change this setting, navigate to **Date format** inside of the **Calendar and
If you set **Week starts on**, you must also set the **First week in year contains** or you will probably get inconsistencies in week numbering in calendars and the Gantt chart.
4. **First week in year contains**: select the day that needs to be contained in the first week of the year. This value is used together with _Week starts on_ to determine the first week of the year.
- For European ISO-8601 standard, set **Week starts on** to `Monday` and First week in year to `Thursday`.
- - For US and Canada, set **Week starts on** to `Sunday` and Day of Year to `6`.
+ - For US and Canada, set **First week in year contains** to `Sunday` and Day of Year to `6`.
- If you leave both on `Based on user's language`, the information provided by moment.js will be used: For more information, please also see [this document from moment.js](https://momentjscom.readthedocs.io/en/latest/moment/07-customization/16-dow-doy/).
- For more information on the way the first week of the year is computed according to ISO standards, see [wikipedia](https://en.wikipedia.org/wiki/ISO_week_date#First_week)
5. Do not forget to **save** your changes.
diff --git a/spec/features/work_packages/timeline/timeline_dates_spec.rb b/spec/features/work_packages/timeline/timeline_dates_spec.rb
index fb99a642fee..7d29a44fbaa 100644
--- a/spec/features/work_packages/timeline/timeline_dates_spec.rb
+++ b/spec/features/work_packages/timeline/timeline_dates_spec.rb
@@ -145,21 +145,27 @@ RSpec.describe 'Work package timeline date formatting',
end
describe 'with US/CA settings',
- with_settings: { start_of_week: '7', first_week_of_year: '1' } do
+ # According to our documentation:
+ # https://www.openproject.org/docs/system-admin-guide/calendars-and-dates/#date-format
+ with_settings: { start_of_week: '7', first_week_of_year: '6' } do
let(:current_user) { create(:admin) }
it 'shows english ISO dates' do
expect(page).to have_selector('.wp-timeline--header-element', text: '01')
expect(page).to have_selector('.wp-timeline--header-element', text: '02')
- # According to the Canadian locale (https://savvytime.com/week-number/canada/2022)
- # the first week of the year is the week where 1st of January falls.
- # If that is last year, then we need to add an offset +1 week to the total number of years.
- current_year = Date.current.year
- week_offset = current_year - Date.new(current_year, 1, 1).beginning_of_week.year
-
- weeks_this_year = Date.new(current_year, 12, 28).cweek + week_offset
- expect(page).not_to have_selector('.wp-timeline--header-element', text: weeks_this_year + 1)
+ # The last weekday determines whether there are 52 or 53 weeks
+ # Only if the last day in the year is exactly the day before the day configured to be
+ # the first week of the year's determining weekday are there 52 weeks.
+ weekday_of_last_day = Date.new(Date.current.year, 12, 31).wday
+ number_of_weeks = if weekday_of_last_day == (Setting.first_week_of_year.to_i - 1)
+ 52
+ else
+ 53
+ end
+
+ expect(page).to have_css('.wp-timeline--header-element', text: number_of_weeks)
+ expect(page).not_to have_css('.wp-timeline--header-element', text: number_of_weeks + 1)
# expect moment to return week 01 for start date and due date
expect_date_week work_package.start_date.iso8601, '01'