couple new, more updated
[webos-internals:modifications.git] / calendar / calendar-week-numbers.patch
1 diff --git a/usr/palm/applications/com.palm.app.calendar/app/controllers/day-assistant.js b/usr/palm/applications/com.palm.app.calendar/app/controllers/day-assistant.js
2 index 8cc09e6..228a3e3 100644
3 --- a/usr/palm/applications/com.palm.app.calendar/app/controllers/day-assistant.js
4 +++ b/usr/palm/applications/com.palm.app.calendar/app/controllers/day-assistant.js
5 @@ -243,6 +243,7 @@ var DayAssistant = Class.create({
6         buildDayTitle: function(doScrim) {
7                 var today = Date.today().clearTime();
8                 var dayDateNoTime = new Date(this.dayDate).clearTime();
9 +               var weekNumber = new Date(this.dayDate).getISO8601Week();
10                 var formatObj = {};
11                 
12          // formatString = "EEE MMM d";
13 @@ -251,18 +252,23 @@ var DayAssistant = Class.create({
14          formatObj.dateComponents = "md";
15                 
16                 if (dayDateNoTime.compareTo(today) === 0) {
17 -                       var template = new Template($L("#{todayStr}, #{dateStr}"));
18 +                       var template = new Template($L("#{todayStr}, #{dateStr}") + ", W#{weekStr}");
19                         var todayStr= Mojo.Format.formatRelativeDate(today, {date: "short"}).capitalize();
20                         
21                         var templateModel = {};
22                         templateModel.todayStr = todayStr;
23                         //templateModel.dateStr = Mojo.Format.formatDate(this.dayDate, $L("EEE MMM d"));
24                         templateModel.dateStr = Mojo.Format.formatDate(this.dayDate, formatObj);
25 +                       templateModel.weekStr = weekNumber;
26                         this.controller.get('dv_title').update(template.evaluate(templateModel)); // Localize this date format string
27                 } else {
28                         //this.controller.get('dv_title').update(Mojo.Format.formatDate(this.dayDate, $L("EEE MMM d, yyyy"))); // Localize this date format string
29                         formatObj.dateComponents = "mdy";
30 -                       this.controller.get('dv_title').update(Mojo.Format.formatDate(this.dayDate, formatObj)); // Localize this date format string
31 +                       var template = new Template($L("#{dateStr}") + ", W#{weekStr}");
32 +                       var templateModel = {};
33 +                       templateModel.weekStr = weekNumber;
34 +                       templateModel.dateStr = Mojo.Format.formatDate(this.dayDate, formatObj);
35 +                       this.controller.get('dv_title').update(template.evaluate(templateModel)); // Localize this date format string
36                 }
37                 
38                 if (doScrim) {
39 diff --git a/usr/palm/applications/com.palm.app.calendar/app/controllers/month-assistant.js b/usr/palm/applications/com.palm.app.calendar/app/controllers/month-assistant.js
40 index f20a9ad..8b48351 100644
41 --- a/usr/palm/applications/com.palm.app.calendar/app/controllers/month-assistant.js
42 +++ b/usr/palm/applications/com.palm.app.calendar/app/controllers/month-assistant.js
43 @@ -133,8 +133,14 @@ var MonthAssistant = Class.create({
44          formatObj.date = "medium";
45          formatObj.dateComponents = "my";
46  
47 +               var wn = new Date(this.monthDate);
48 +               wn.setDate(1);
49 +               var firstWeek = wn.getISO8601Week();    
50 +               wn.setMonth(wn.getMonth()+1);
51 +               wn.setDate(wn.getDate()-1);
52 +               var lastWeek = wn.getISO8601Week();
53                 //this.mvTitle.innerText = Mojo.Format.formatDate(this.monthDate, $L("MMM yyyy")); // Localize this date format string
54 -               this.mvTitle.innerText = Mojo.Format.formatDate(this.monthDate, formatObj); // Localize this date format string
55 +               this.mvTitle.innerText = Mojo.Format.formatDate(this.monthDate, formatObj) + ", " + $L("Week") + " " + firstWeek + "-" + lastWeek; // Localize this date format string
56         },
57  
58         buildDayHeader: function() {
59 diff --git a/usr/palm/applications/com.palm.app.calendar/app/controllers/week-assistant.js b/usr/palm/applications/com.palm.app.calendar/app/controllers/week-assistant.js
60 index 4fa6e78..446997b 100644
61 --- a/usr/palm/applications/com.palm.app.calendar/app/controllers/week-assistant.js
62 +++ b/usr/palm/applications/com.palm.app.calendar/app/controllers/week-assistant.js
63 @@ -137,8 +137,9 @@ var WeekAssistant = Class.create({
64         buildWeekTitle: function() {
65                 var today = Date.today().clearTime();
66                 var dayOfWeek = this.getFirstDayOfWeek(this.weekDate);
67 +               var weekNumber = new Date(this.weekDate).getISO8601Week();
68                 
69 -               var template = new Template($L("Week of #{dateStr}"));
70 +               var template = new Template($L("Week") + " #{weekStr}, " + $L("#{dateStr}"));
71                 var templateModel = {};
72                 var formatObj = {};
73                 // formatString = "MMM d, yyyy";
74 @@ -146,6 +147,7 @@ var WeekAssistant = Class.create({
75          formatObj.dateComponents = "mdy";
76                 //templateModel.dateStr = Mojo.Format.formatDate(dayOfWeek, $L("MMM d, yyyy"));
77                 templateModel.dateStr = Mojo.Format.formatDate(dayOfWeek, formatObj);
78 +               templateModel.weekStr = weekNumber;
79                 this.title.innerHTML = template.evaluate(templateModel);
80                 
81                 if (this.changingWeeks) {
82 diff --git a/usr/palm/applications/com.palm.app.calendar/javascripts/datejs/week.js b/usr/palm/applications/com.palm.app.calendar/javascripts/datejs/week.js
83 new file mode 100644
84 index 0000000..5a8f688
85 --- /dev/null
86 +++ b/usr/palm/applications/com.palm.app.calendar/javascripts/datejs/week.js
87 @@ -0,0 +1,10 @@
88 +Date.prototype.getISO8601Week = function() {
89 +       var d = new Date(this);
90 +       d.setUTCDate(d.getUTCDate() - (d.getUTCDay() + 6) % 7 + 3);
91 +       var e = d.valueOf();
92 +       d.setUTCMonth(0, 4);
93 +       var w = Math.round((e - d.valueOf()) / 604800000) + 1;
94 +       if (w <= 9) { w = "0" + w; }
95 +       return w;
96 +}
97 +
98 diff --git a/usr/palm/applications/com.palm.app.calendar/sources.json b/usr/palm/applications/com.palm.app.calendar/sources.json
99 index 8488b5b..2f271ab 100644
100 --- a/usr/palm/applications/com.palm.app.calendar/sources.json
101 +++ b/usr/palm/applications/com.palm.app.calendar/sources.json
102 @@ -42,4 +42,5 @@
103  ,      {       "source": "app\/controllers\/prefs-options-assistant.js"        }
104  
105  ,      {       "source": "javascripts\/automation\/appinspector.js"            }
106 +,      {       "source": "javascripts\/datejs\/week.js"                }
107  ]