Skip to content

Commit

Permalink
(js) Fix computation of week number
Browse files Browse the repository at this point in the history
Fixes #3973, 3976
  • Loading branch information
cgx committed Jan 5, 2017
1 parent e7e1283 commit 02a1ad4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -34,6 +34,7 @@ Bug fixes
- [web] append ics file extension when importing events (#2308)
- [web] handle URI in vCard photos (#2683)
- [web] handle semicolon in values during LDIF import (#1760)
- [web] fixed computation of week number (#3973, #3976)
- [eas] properly skip folders we don't want to synchronize (#3943)
- [eas] fixed 30 mins freebusy offset with S Planner
- [eas] now correctly handles reminders on tasks (#3964)
Expand Down
20 changes: 18 additions & 2 deletions UI/WebServerResources/js/Common/utils.js
Expand Up @@ -325,6 +325,22 @@ Date.prototype.beginOfDay = function() {
return beginOfDay;
};

/**
* See [SOGoUser dayOfWeekForDate:]
*/
Date.prototype.dayOfWeek = function(localeProvider) {
var offset, baseDayOfWeek, dayOfWeek;

offset = localeProvider.firstDayOfWeek;
baseDayOfWeek = this.getDay();
if (offset > baseDayOfWeek)
baseDayOfWeek += 7;

dayOfWeek = baseDayOfWeek - offset;

return dayOfWeek;
};

/**
* See [SOGoUser firstWeekOfYearForDate:]
*/
Expand All @@ -336,10 +352,10 @@ Date.prototype.firstWeekOfYearForDate = function(localeProvider) {
januaryFirst = new Date(this.getTime());
januaryFirst.setMonth(0);
januaryFirst.setDate(1);
dayOfWeek = januaryFirst.getDay();
dayOfWeek = januaryFirst.dayOfWeek(localeProvider);

if (firstWeekRule == 'First4DayWeek') {
if ((dayOfWeek + localeProvider.firstDayOfWeek) % 7 < 4)
if (dayOfWeek < 4)
firstWeek = januaryFirst.beginOfWeek(localeProvider.firstDayOfWeek);
else
firstWeek = januaryFirst.addDays(7).beginOfWeek(localeProvider.firstDayOfWeek);
Expand Down

0 comments on commit 02a1ad4

Please sign in to comment.