summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-20 09:20:02 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-20 09:20:02 +0200
commitfc6290e5394287a13235720cd1cc5a0c2eca7f5a (patch)
treed257f5515a26df7c29d4658f489225cf1777ec23
parent8e2c52911ce2879166b4444fd5e821cb25b80fff (diff)
downloadkube-fc6290e5394287a13235720cd1cc5a0c2eca7f5a.tar.gz
kube-fc6290e5394287a13235720cd1cc5a0c2eca7f5a.zip
Display the week number
-rw-r--r--views/calendar/qml/WeekView.qml46
1 files changed, 46 insertions, 0 deletions
diff --git a/views/calendar/qml/WeekView.qml b/views/calendar/qml/WeekView.qml
index 2d16b772..80e41bea 100644
--- a/views/calendar/qml/WeekView.qml
+++ b/views/calendar/qml/WeekView.qml
@@ -32,6 +32,37 @@ FocusScope {
32 property date startDate: currentDate 32 property date startDate: currentDate
33 property var calendarFilter 33 property var calendarFilter
34 34
35 /**
36 * Returns the week number for this date. dowOffset is the day of week the week
37 * "starts" on for your locale - it can be from 0 to 6. If dowOffset is 1 (Monday),
38 * the week returned is the ISO 8601 week number.
39 * @param int dowOffset
40 * @return int
41 */
42 function getWeek(date, dowOffset) {
43 var newYear = new Date(date.getFullYear(),0,1);
44 var day = newYear.getDay() - dowOffset; //the day of week the year begins on
45 day = (day >= 0 ? day : day + 7);
46 var daynum = Math.floor((date.getTime() - newYear.getTime() -
47 (date.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
48 var weeknum;
49 //if the year starts before the middle of a week
50 if(day < 4) {
51 weeknum = Math.floor((daynum+day-1)/7) + 1;
52 if(weeknum > 52) {
53 nYear = new Date(date.getFullYear() + 1,0,1);
54 nday = nYear.getDay() - dowOffset;
55 nday = nday >= 0 ? nday : nday + 7;
56 /*if the next year starts before the middle of
57 the week, it is week #1 of that year*/
58 weeknum = nday < 4 ? 1 : 53;
59 }
60 }
61 else {
62 weeknum = Math.floor((daynum+day-1)/7);
63 }
64 return weeknum;
65 }
35 Item { 66 Item {
36 anchors { 67 anchors {
37 top: parent.top 68 top: parent.top
@@ -42,6 +73,21 @@ FocusScope {
42 width: root.dayWidth * root.daysToShow + Kube.Units.gridUnit * 2 73 width: root.dayWidth * root.daysToShow + Kube.Units.gridUnit * 2
43 height: root.height 74 height: root.height
44 75
76 Item {
77 id: weekNumber
78 anchors {
79 top: parent.top
80 left: parent.left
81 }
82 width: Kube.Units.gridUnit * 2
83 height: Kube.Units.gridUnit * 2
84 Label {
85 anchors.centerIn: parent
86 text: getWeek(startDate, 1)
87 font.bold: true
88 }
89 }
90
45 DayLabels { 91 DayLabels {
46 id: dayLabels 92 id: dayLabels
47 anchors.top: parent.top 93 anchors.top: parent.top