Merge lp:~cjohnston/launchpad/ic-approx-time into lp:launchpad
- ic-approx-time
- Merge into devel
Proposed by
Chris Johnston
Status: | Merged |
---|---|
Merged at revision: | 17101 |
Proposed branch: | lp:~cjohnston/launchpad/ic-approx-time |
Merge into: | lp:launchpad |
Diff against target: |
238 lines (+151/-17) 6 files modified
lib/lp/app/javascript/date.js (+46/-0) lib/lp/app/javascript/tests/test_date.html (+37/-0) lib/lp/app/javascript/tests/test_date.js (+37/-0) lib/lp/code/javascript/branchmergeproposal.inlinecomments.js (+8/-4) lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.html (+2/-0) lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js (+21/-13) |
To merge this branch: | bzr merge lp:~cjohnston/launchpad/ic-approx-time |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
William Grant | code | Approve | |
Review via email:
|
Commit message
Switch ICs to use relative time stamps similar to other comment sections of LP.
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
William Grant (wgrant) wrote : | # |
approximatedate should probably live in lib/lp/
review:
Needs Fixing
(code)
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
William Grant (wgrant) wrote : | # |
Thanks for the fixes. Just a few more trivialities and this will be good to land!
review:
Needs Fixing
(code)
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
William Grant (wgrant) wrote : | # |
Thanks for the fixes. Have you tested this on Lucid?
Also, lib/lp/
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
William Grant (wgrant) : | # |
review:
Needs Fixing
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
William Grant (wgrant) : | # |
review:
Approve
(code)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'lib/lp/app/javascript/date.js' | |||
2 | --- lib/lp/app/javascript/date.js 1970-01-01 00:00:00 +0000 | |||
3 | +++ lib/lp/app/javascript/date.js 2014-07-08 12:33:30 +0000 | |||
4 | @@ -0,0 +1,46 @@ | |||
5 | 1 | /* Copyright 2014 Canonical Ltd. This software is licensed under the | ||
6 | 2 | * GNU Affero General Public License version 3 (see the file LICENSE). */ | ||
7 | 3 | |||
8 | 4 | YUI.add('lp.app.date', function(Y) { | ||
9 | 5 | |||
10 | 6 | var namespace = Y.namespace('lp.app.date'); | ||
11 | 7 | |||
12 | 8 | namespace.parse_date = function(str) { | ||
13 | 9 | // Parse an ISO-8601 date | ||
14 | 10 | var re = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|\+00:00)$/ | ||
15 | 11 | var bits = re.exec(str).slice(1, 8).map(Number) | ||
16 | 12 | // Adjusting for the fact that Date.UTC uses 0-11 for months | ||
17 | 13 | bits[1] -= 1 | ||
18 | 14 | return new Date(Date.UTC.apply(null, bits)) | ||
19 | 15 | }; | ||
20 | 16 | |||
21 | 17 | namespace.approximatedate = function(date) { | ||
22 | 18 | // Display approximate time an event happened when it happened less than 1 | ||
23 | 19 | // day ago. | ||
24 | 20 | var now = (new Date).valueOf(); | ||
25 | 21 | var timedelta = now - date; | ||
26 | 22 | var days = timedelta / 86400000 | ||
27 | 23 | var hours = timedelta / 3600000 | ||
28 | 24 | var minutes = timedelta / 60000 | ||
29 | 25 | var amount = 0 | ||
30 | 26 | var unit = "" | ||
31 | 27 | if (days > 1) { | ||
32 | 28 | return 'on ' + Y.Date.format( | ||
33 | 29 | new Date(date), {format: '%Y-%m-%d'}); | ||
34 | 30 | } else { | ||
35 | 31 | if (hours >= 1) { | ||
36 | 32 | amount = hours | ||
37 | 33 | unit = "hour" | ||
38 | 34 | } else if (minutes >= 1) { | ||
39 | 35 | amount = minutes | ||
40 | 36 | unit = "minute" | ||
41 | 37 | } else { | ||
42 | 38 | return "a moment ago" | ||
43 | 39 | } | ||
44 | 40 | if (Math.floor(amount) > 1) { | ||
45 | 41 | unit = unit + 's' | ||
46 | 42 | } | ||
47 | 43 | return Math.floor(amount) + ' ' + unit + ' ago' | ||
48 | 44 | } | ||
49 | 45 | }; | ||
50 | 46 | }, "0.1", {'requires': ['datatype-date']}); | ||
51 | 0 | 47 | ||
52 | === added file 'lib/lp/app/javascript/tests/test_date.html' | |||
53 | --- lib/lp/app/javascript/tests/test_date.html 1970-01-01 00:00:00 +0000 | |||
54 | +++ lib/lp/app/javascript/tests/test_date.html 2014-07-08 12:33:30 +0000 | |||
55 | @@ -0,0 +1,37 @@ | |||
56 | 1 | <!DOCTYPE html> | ||
57 | 2 | <!-- | ||
58 | 3 | Copyright 2014 Canonical Ltd. This software is licensed under the | ||
59 | 4 | GNU Affero General Public License version 3 (see the file LICENSE). | ||
60 | 5 | --> | ||
61 | 6 | <html> | ||
62 | 7 | <head> | ||
63 | 8 | <title>Test lp-names</title> | ||
64 | 9 | <!-- YUI and test setup --> | ||
65 | 10 | <script type="text/javascript" | ||
66 | 11 | src="../../../../../build/js/yui/yui/yui.js"> | ||
67 | 12 | </script> | ||
68 | 13 | <link rel="stylesheet" | ||
69 | 14 | href="../../../../../build/js/yui/console/assets/console-core.css" /> | ||
70 | 15 | <link rel="stylesheet" | ||
71 | 16 | href="../../../../../build/js/yui/test-console/assets/skins/sam/test-console.css" /> | ||
72 | 17 | <link rel="stylesheet" | ||
73 | 18 | href="../../../../../build/js/yui/test/assets/skins/sam/test.css" /> | ||
74 | 19 | |||
75 | 20 | <script type="text/javascript" | ||
76 | 21 | src="../../../../../build/js/lp/app/testing/testrunner.js"></script> | ||
77 | 22 | <link rel="stylesheet" href="../../../app/javascript/testing/test.css" /> | ||
78 | 23 | |||
79 | 24 | <!-- The module under test. --> | ||
80 | 25 | <script type="text/javascript" src="../date.js"></script> | ||
81 | 26 | |||
82 | 27 | <!-- The test suite. --> | ||
83 | 28 | <script type="text/javascript" src="test_date.js"></script> | ||
84 | 29 | |||
85 | 30 | </head> | ||
86 | 31 | <body class="yui3-skin-sam"> | ||
87 | 32 | <ul id="suites"> | ||
88 | 33 | <li>date.test</li> | ||
89 | 34 | </ul> | ||
90 | 35 | |||
91 | 36 | </body> | ||
92 | 37 | </html> | ||
93 | 0 | 38 | ||
94 | === added file 'lib/lp/app/javascript/tests/test_date.js' | |||
95 | --- lib/lp/app/javascript/tests/test_date.js 1970-01-01 00:00:00 +0000 | |||
96 | +++ lib/lp/app/javascript/tests/test_date.js 2014-07-08 12:33:30 +0000 | |||
97 | @@ -0,0 +1,37 @@ | |||
98 | 1 | YUI.add('date.test', function (Y) { | ||
99 | 2 | |||
100 | 3 | var tests = Y.namespace('date.test'); | ||
101 | 4 | tests.suite = new Y.Test.Suite("date tests"); | ||
102 | 5 | |||
103 | 6 | var now = (new Date).valueOf() | ||
104 | 7 | tests.suite.add(new Y.Test.Case({ | ||
105 | 8 | name: 'test_approximatedate', | ||
106 | 9 | |||
107 | 10 | test_return_moment_ago: function () { | ||
108 | 11 | Y.Assert.areEqual( | ||
109 | 12 | 'a moment ago', | ||
110 | 13 | Y.lp.app.date.approximatedate(new Date(now - 150))); | ||
111 | 14 | }, | ||
112 | 15 | |||
113 | 16 | test_return_minute_ago: function () { | ||
114 | 17 | Y.Assert.areEqual( | ||
115 | 18 | '1 minute ago', | ||
116 | 19 | Y.lp.app.date.approximatedate(new Date(now - 65000))); | ||
117 | 20 | }, | ||
118 | 21 | |||
119 | 22 | test_return_hours_ago: function () { | ||
120 | 23 | Y.Assert.areEqual( | ||
121 | 24 | '3 hours ago', | ||
122 | 25 | Y.lp.app.date.approximatedate(new Date(now - 12600000))); | ||
123 | 26 | }, | ||
124 | 27 | test_return_days_ago: function () { | ||
125 | 28 | Y.Assert.areEqual( | ||
126 | 29 | 'on 2012-08-12', Y.lp.app.date.approximatedate( | ||
127 | 30 | Y.lp.app.date.parse_date( | ||
128 | 31 | '2012-08-12T10:00:00.00001+00:00'))); | ||
129 | 32 | }, | ||
130 | 33 | })); | ||
131 | 34 | |||
132 | 35 | }, '0.1', { | ||
133 | 36 | requires: ['lp.testing.runner', 'test', 'lp', 'lp.app.date'] | ||
134 | 37 | }); | ||
135 | 0 | 38 | ||
136 | === modified file 'lib/lp/code/javascript/branchmergeproposal.inlinecomments.js' | |||
137 | --- lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-05-29 16:30:42 +0000 | |||
138 | +++ lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-07-08 12:33:30 +0000 | |||
139 | @@ -184,9 +184,13 @@ | |||
140 | 184 | // XXX cprov 20140226: the date should be formatted according to | 184 | // XXX cprov 20140226: the date should be formatted according to |
141 | 185 | // the user locale/timezone similar to fmt:displaydate. | 185 | // the user locale/timezone similar to fmt:displaydate. |
142 | 186 | // We should leverage Y.Intl features. | 186 | // We should leverage Y.Intl features. |
146 | 187 | var fmt_date = 'on ' + Y.Date.format( | 187 | if (typeof comment.date === "string") { |
147 | 188 | new Date(comment.date), {format: '%Y-%m-%d'}); | 188 | var comment_date = Y.lp.app.date.parse_date(comment.date); |
148 | 189 | headerspan.one('span').set('text', fmt_date); | 189 | } else { |
149 | 190 | var comment_date = comment.date | ||
150 | 191 | } | ||
151 | 192 | var date = Y.lp.app.date.approximatedate(comment_date); | ||
152 | 193 | headerspan.one('span').set('text', date); | ||
153 | 190 | newrow.one('.boardCommentDetails').append(headerspan); | 194 | newrow.one('.boardCommentDetails').append(headerspan); |
154 | 191 | newrow.one('.boardCommentBody div').append('<span></span>'); | 195 | newrow.one('.boardCommentBody div').append('<span></span>'); |
155 | 192 | newrow.one('.boardCommentBody').one('span').set('text', comment.text); | 196 | newrow.one('.boardCommentBody').one('span').set('text', comment.text); |
156 | @@ -701,4 +705,4 @@ | |||
157 | 701 | namespace.DiffNav = DiffNav; | 705 | namespace.DiffNav = DiffNav; |
158 | 702 | 706 | ||
159 | 703 | }, '0.1', {requires: ['datatype-date', 'event', 'io', 'node', 'widget', | 707 | }, '0.1', {requires: ['datatype-date', 'event', 'io', 'node', 'widget', |
161 | 704 | 'lp.client', 'lp.ui.editor']}); | 708 | 'lp.client', 'lp.ui.editor', 'lp.app.date']}); |
162 | 705 | 709 | ||
163 | === modified file 'lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.html' | |||
164 | --- lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.html 2014-05-19 21:56:02 +0000 | |||
165 | +++ lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.html 2014-07-08 12:33:30 +0000 | |||
166 | @@ -32,6 +32,8 @@ | |||
167 | 32 | <script type="text/javascript" | 32 | <script type="text/javascript" |
168 | 33 | src="../../../../../build/js/lp/app/client.js"></script> | 33 | src="../../../../../build/js/lp/app/client.js"></script> |
169 | 34 | <script type="text/javascript" | 34 | <script type="text/javascript" |
170 | 35 | src="../../../../../build/js/lp/app/date.js"></script> | ||
171 | 36 | <script type="text/javascript" | ||
172 | 35 | src="../../../../../build/js/lp/app/testing/mockio.js"></script> | 37 | src="../../../../../build/js/lp/app/testing/mockio.js"></script> |
173 | 36 | <script type="text/javascript" | 38 | <script type="text/javascript" |
174 | 37 | src="../../../../../build/js/lp/app/ui/ui.js"></script> | 39 | src="../../../../../build/js/lp/app/ui/ui.js"></script> |
175 | 38 | 40 | ||
176 | === modified file 'lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js' | |||
177 | --- lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-05-26 12:44:57 +0000 | |||
178 | +++ lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-07-08 12:33:30 +0000 | |||
179 | @@ -70,25 +70,28 @@ | |||
180 | 70 | "ws.op=getInlineComments&previewdiff_id=1", | 70 | "ws.op=getInlineComments&previewdiff_id=1", |
181 | 71 | mockio.requests[0].config.data); | 71 | mockio.requests[0].config.data); |
182 | 72 | mockio.last_request = mockio.requests[0]; | 72 | mockio.last_request = mockio.requests[0]; |
183 | 73 | var now = (new Date).valueOf() | ||
184 | 73 | published_comments = [ | 74 | published_comments = [ |
185 | 74 | {'line_number': '2', | 75 | {'line_number': '2', |
186 | 75 | 'person': person_obj, | 76 | 'person': person_obj, |
187 | 76 | 'text': 'This is preloaded.', | 77 | 'text': 'This is preloaded.', |
189 | 77 | 'date': '2012-08-12T10:00:00.00001+00:00'} | 78 | 'date': '2012-08-12T10:00:00.00001+00:00'}, |
190 | 79 | {'line_number': '3', | ||
191 | 80 | 'person': person_obj, | ||
192 | 81 | 'text': 'This is great.', | ||
193 | 82 | 'date': (new Date(now - 12600000)), | ||
194 | 83 | }, | ||
195 | 78 | ]; | 84 | ]; |
196 | 79 | mockio.success({ | 85 | mockio.success({ |
197 | 80 | responseText: Y.JSON.stringify(published_comments), | 86 | responseText: Y.JSON.stringify(published_comments), |
198 | 81 | responseHeaders: {'Content-Type': 'application/json'}}); | 87 | responseHeaders: {'Content-Type': 'application/json'}}); |
199 | 82 | 88 | ||
200 | 83 | // Published comment is displayed. | 89 | // Published comment is displayed. |
209 | 84 | var comments = Y.one('#diff-line-2').next().one('div'); | 90 | var first_comments = Y.one('#diff-line-2').next().one('div'); |
210 | 85 | // XXX cprov 20140226: test disabled due to ES4 lack of | 91 | var first = first_comments.one('div:first-child') |
211 | 86 | // ISO8601 support. Although the vast majority of production | 92 | Y.Assert.areEqual( |
212 | 87 | // clients run ES5. | 93 | 'Foo Bar (name16) wrote on 2012-08-12:', |
213 | 88 | //Y.Assert.areEqual( | 94 | first.one('.boardCommentDetails').get('text')); |
206 | 89 | // 'Foo Bar (name16) wrote on 2012-08-12', | ||
207 | 90 | // header.get('text')); | ||
208 | 91 | var first = comments.one('div:first-child') | ||
214 | 92 | Y.Assert.areEqual( | 95 | Y.Assert.areEqual( |
215 | 93 | 'This is preloaded.', | 96 | 'This is preloaded.', |
216 | 94 | first.one('.boardCommentBody').get('text')); | 97 | first.one('.boardCommentBody').get('text')); |
217 | @@ -103,12 +106,17 @@ | |||
218 | 103 | 'Boing!', second.one('.boardCommentBody').get('text')); | 106 | 'Boing!', second.one('.boardCommentBody').get('text')); |
219 | 104 | 107 | ||
220 | 105 | // Draft comment for line 3 is displayed. | 108 | // Draft comment for line 3 is displayed. |
222 | 106 | var third = Y.one('#diff-line-3').next(); | 109 | var second_comments = Y.one('#diff-line-3').next().one('div'); |
223 | 110 | var third = second_comments.one('div:first-child') | ||
224 | 107 | Y.Assert.areEqual( | 111 | Y.Assert.areEqual( |
226 | 108 | 'Unsaved comment', | 112 | 'Foo Bar (name16) wrote 3 hours ago:', |
227 | 109 | third.one('.boardCommentDetails').get('text')); | 113 | third.one('.boardCommentDetails').get('text')); |
230 | 110 | Y.Assert.areEqual( | 114 | var fourth = third.next() |
231 | 111 | 'Zoing!', third.one('.boardCommentBody').get('text')); | 115 | Y.Assert.areEqual( |
232 | 116 | 'Unsaved comment', | ||
233 | 117 | fourth.one('.boardCommentDetails').get('text')); | ||
234 | 118 | Y.Assert.areEqual( | ||
235 | 119 | 'Zoing!', fourth.one('.boardCommentBody').get('text')); | ||
236 | 112 | }, | 120 | }, |
237 | 113 | 121 | ||
238 | 114 | test_draft_handler: function() { | 122 | test_draft_handler: function() { |
Date.now and the ISO 8601 support in Date.parse are relatively new, and we probably want to fall back if they don't work. This will fail at least in IE8, and quite possibly on the Lucid buildbots which use an old WebKit. We probably don't care about IE8 at this point, but buildbot will be a problem.
Also, your bzr whoami is wrong; consider correcting it and recommitting.
And there are a few comments inline.