1 |
From 29673deac7e1c34127b0ac1484d0e7766ecc9acc Mon Sep 17 00:00:00 2001 |
2 |
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org> |
3 |
Date: Thu, 13 Nov 2014 15:14:56 +0000 |
4 |
Subject: [PATCH] calendar: Stop computing week number ourselves |
5 |
|
6 |
Correctly computing the ISO week number is tricky and we already |
7 |
have code in the platform to do it, so just refer its computation |
8 |
to GDateTime rather than doing it ourselves. |
9 |
|
10 |
https://bugzilla.gnome.org/show_bug.cgi?id=736722 |
11 |
--- |
12 |
js/ui/calendar.js | 19 +------------------ |
13 |
1 file changed, 1 insertion(+), 18 deletions(-) |
14 |
|
15 |
diff --git a/js/ui/calendar.js b/js/ui/calendar.js |
16 |
index bc51d20..6edf69f 100644 |
17 |
--- a/js/ui/calendar.js |
18 |
+++ b/js/ui/calendar.js |
19 |
@@ -88,23 +88,6 @@ function _formatEventTime(event, clockFormat, periodBegin, periodEnd) { |
20 |
return ret; |
21 |
} |
22 |
|
23 |
-function _getCalendarWeekForDate(date) { |
24 |
- // Based on the algorithms found here: |
25 |
- // http://en.wikipedia.org/wiki/Talk:ISO_week_date |
26 |
- let midnightDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()); |
27 |
- // Need to get Monday to be 1 ... Sunday to be 7 |
28 |
- let dayOfWeek = 1 + ((midnightDate.getDay() + 6) % 7); |
29 |
- let nearestThursday = new Date(midnightDate.getFullYear(), midnightDate.getMonth(), |
30 |
- midnightDate.getDate() + (4 - dayOfWeek)); |
31 |
- |
32 |
- let jan1st = new Date(nearestThursday.getFullYear(), 0, 1); |
33 |
- let diffDate = nearestThursday - jan1st; |
34 |
- let dayNumber = Math.floor(Math.abs(diffDate) / MSECS_IN_DAY); |
35 |
- let weekNumber = Math.floor(dayNumber / 7) + 1; |
36 |
- |
37 |
- return weekNumber; |
38 |
-} |
39 |
- |
40 |
function _getCalendarDayAbbreviation(dayNumber) { |
41 |
let abbreviations = [ |
42 |
/* Translators: Calendar grid abbreviation for Sunday. |
43 |
@@ -672,7 +655,7 @@ const Calendar = new Lang.Class({ |
44 |
this._buttons.push(button); |
45 |
|
46 |
if (this._useWeekdate && iter.getDay() == 4) { |
47 |
- let label = new St.Label({ text: _getCalendarWeekForDate(iter).toString(), |
48 |
+ let label = new St.Label({ text: iter.toLocaleFormat('%V'), |
49 |
style_class: 'calendar-day-base calendar-week-number'}); |
50 |
layout.attach(label, rtl ? 7 : 0, row, 1, 1); |
51 |
} |
52 |
-- |
53 |
2.1.0 |