← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~pkunal-parmar/ubuntu-calendar-app/WeekNumber into lp:ubuntu-calendar-app

 

Kunal Parmar has proposed merging lp:~pkunal-parmar/ubuntu-calendar-app/WeekNumber into lp:ubuntu-calendar-app.

Commit message:
Resolves Bug #1435542
Calendar app displays wrong week number

Requested reviews:
  Ubuntu Calendar Developers (ubuntu-calendar-dev)
Related bugs:
  Bug #1435542 in ubiquity (Ubuntu): "Calendar app displays wrong week number"
  https://bugs.launchpad.net/ubuntu/+source/ubiquity/+bug/1435542

For more details, see:
https://code.launchpad.net/~pkunal-parmar/ubuntu-calendar-app/WeekNumber/+merge/255078

Resolves Bug #1435542
Calendar app displays wrong week number
-- 
Your team Ubuntu Calendar Developers is requested to review the proposed merge of lp:~pkunal-parmar/ubuntu-calendar-app/WeekNumber into lp:ubuntu-calendar-app.
=== modified file 'TimeLineBaseComponent.qml'
--- TimeLineBaseComponent.qml	2015-02-19 13:50:29 +0000
+++ TimeLineBaseComponent.qml	2015-04-02 12:57:21 +0000
@@ -31,7 +31,7 @@
     property var keyboardEventProvider;
 
     property date startDay: DateExt.today();
-    property int weekNumber: startDay.weekNumber();
+    property int weekNumber: startDay.weekNumber(Qt.locale().firstDayOfWeek);
     property bool isActive: false
     property alias contentY: timeLineView.contentY
     property alias contentInteractive: timeLineView.interactive

=== modified file 'TimeLineHeader.qml'
--- TimeLineHeader.qml	2015-02-19 13:50:29 +0000
+++ TimeLineHeader.qml	2015-04-02 12:57:21 +0000
@@ -45,7 +45,7 @@
             Label{
                 id: weekNumLabel
                 objectName: "weeknumber"
-                text: i18n.tr("W") + root.weekNumber
+                text: i18n.tr("W") + startDay.weekNumber(Qt.locale().firstDayOfWeek)
                 fontSize: "small"
                 height: units.gu(5)
                 width: parent.width

=== modified file 'dateExt.js'
--- dateExt.js	2014-08-18 16:48:54 +0000
+++ dateExt.js	2015-04-02 12:57:21 +0000
@@ -85,16 +85,10 @@
     return this.midnight().addDays(1 - this.getDate())
 }
 
-Date.prototype.weekNumber = function() {
-    var date = this.weekStart(1).addDays(3) // Thursday midnight
-    var newYear = new Date(date.getFullYear(), 0 /*Jan*/, 1 /*the 1st*/)
-    var n = 0
-    var tx = date.getTime(), tn = newYear.getTime()
-    while (tn < tx) {
-        tx = tx - Date.msPerWeek
-        n = n + 1
-    }
-    return n
+Date.prototype.weekNumber = function(weekStartDay) {
+    var date = this.weekStart(weekStartDay).addDays(3) // Thursday midnight
+    var onejan = new Date(this.getFullYear(), 0, 3);
+    return Math.ceil((((date - onejan) / 86400000) + onejan.getDay()+1)/7);
 }
 
 Date.prototype.weeksInMonth = function(weekday) {


Follow ups