Merge lp:~cjohnston/launchpad/js-timestamp-fixes into lp:launchpad

Proposed by Chris Johnston
Status: Merged
Merged at revision: 17102
Proposed branch: lp:~cjohnston/launchpad/js-timestamp-fixes
Merge into: lp:launchpad
Diff against target: 131 lines (+23/-23)
4 files modified
lib/lp/app/javascript/date.js (+16/-16)
lib/lp/app/javascript/tests/test_date.js (+1/-1)
lib/lp/code/javascript/branchmergeproposal.inlinecomments.js (+1/-1)
lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js (+5/-5)
To merge this branch: bzr merge lp:~cjohnston/launchpad/js-timestamp-fixes
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+226032@code.launchpad.net

Commit message

Minor JS fixes from the earlier diff comments timestamp changes

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/app/javascript/date.js'
--- lib/lp/app/javascript/date.js 2014-07-08 12:32:44 +0000
+++ lib/lp/app/javascript/date.js 2014-07-08 23:47:16 +0000
@@ -7,11 +7,11 @@
77
8namespace.parse_date = function(str) {8namespace.parse_date = function(str) {
9 // Parse an ISO-8601 date9 // Parse an ISO-8601 date
10 var re = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|\+00:00)$/10 var re = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|\+00:00)$/;
11 var bits = re.exec(str).slice(1, 8).map(Number)11 var bits = re.exec(str).slice(1, 8).map(Number);
12 // Adjusting for the fact that Date.UTC uses 0-11 for months12 // Adjusting for the fact that Date.UTC uses 0-11 for months
13 bits[1] -= 113 bits[1] -= 1;
14 return new Date(Date.UTC.apply(null, bits))14 return new Date(Date.UTC.apply(null, bits));
15};15};
1616
17namespace.approximatedate = function(date) {17namespace.approximatedate = function(date) {
@@ -19,28 +19,28 @@
19 // day ago.19 // day ago.
20 var now = (new Date).valueOf();20 var now = (new Date).valueOf();
21 var timedelta = now - date;21 var timedelta = now - date;
22 var days = timedelta / 8640000022 var days = timedelta / 86400000;
23 var hours = timedelta / 360000023 var hours = timedelta / 3600000;
24 var minutes = timedelta / 6000024 var minutes = timedelta / 60000;
25 var amount = 025 var amount = 0;
26 var unit = ""26 var unit = "";
27 if (days > 1) {27 if (days > 1) {
28 return 'on ' + Y.Date.format(28 return 'on ' + Y.Date.format(
29 new Date(date), {format: '%Y-%m-%d'});29 new Date(date), {format: '%Y-%m-%d'});
30 } else {30 } else {
31 if (hours >= 1) {31 if (hours >= 1) {
32 amount = hours32 amount = hours;
33 unit = "hour"33 unit = "hour";
34 } else if (minutes >= 1) {34 } else if (minutes >= 1) {
35 amount = minutes35 amount = minutes;
36 unit = "minute"36 unit = "minute";
37 } else {37 } else {
38 return "a moment ago"38 return "a moment ago";
39 }39 }
40 if (Math.floor(amount) > 1) {40 if (Math.floor(amount) > 1) {
41 unit = unit + 's'41 unit = unit + 's';
42 }42 }
43 return Math.floor(amount) + ' ' + unit + ' ago'43 return Math.floor(amount) + ' ' + unit + ' ago';
44 }44 }
45};45};
46}, "0.1", {'requires': ['datatype-date']});46}, "0.1", {'requires': ['datatype-date']});
4747
=== modified file 'lib/lp/app/javascript/tests/test_date.js'
--- lib/lp/app/javascript/tests/test_date.js 2014-07-08 12:32:44 +0000
+++ lib/lp/app/javascript/tests/test_date.js 2014-07-08 23:47:16 +0000
@@ -3,7 +3,7 @@
3 var tests = Y.namespace('date.test');3 var tests = Y.namespace('date.test');
4 tests.suite = new Y.Test.Suite("date tests");4 tests.suite = new Y.Test.Suite("date tests");
55
6 var now = (new Date).valueOf()6 var now = (new Date).valueOf();
7 tests.suite.add(new Y.Test.Case({7 tests.suite.add(new Y.Test.Case({
8 name: 'test_approximatedate',8 name: 'test_approximatedate',
99
1010
=== modified file 'lib/lp/code/javascript/branchmergeproposal.inlinecomments.js'
--- lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-07-08 12:32:44 +0000
+++ lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-07-08 23:47:16 +0000
@@ -187,7 +187,7 @@
187 if (typeof comment.date === "string") {187 if (typeof comment.date === "string") {
188 var comment_date = Y.lp.app.date.parse_date(comment.date);188 var comment_date = Y.lp.app.date.parse_date(comment.date);
189 } else {189 } else {
190 var comment_date = comment.date190 var comment_date = comment.date;
191 }191 }
192 var date = Y.lp.app.date.approximatedate(comment_date);192 var date = Y.lp.app.date.approximatedate(comment_date);
193 headerspan.one('span').set('text', date);193 headerspan.one('span').set('text', date);
194194
=== modified file 'lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js'
--- lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-07-08 12:32:44 +0000
+++ lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-07-08 23:47:16 +0000
@@ -70,7 +70,7 @@
70 "ws.op=getInlineComments&previewdiff_id=1",70 "ws.op=getInlineComments&previewdiff_id=1",
71 mockio.requests[0].config.data);71 mockio.requests[0].config.data);
72 mockio.last_request = mockio.requests[0];72 mockio.last_request = mockio.requests[0];
73 var now = (new Date).valueOf()73 var now = (new Date).valueOf();
74 published_comments = [74 published_comments = [
75 {'line_number': '2',75 {'line_number': '2',
76 'person': person_obj,76 'person': person_obj,
@@ -80,7 +80,7 @@
80 'person': person_obj,80 'person': person_obj,
81 'text': 'This is great.',81 'text': 'This is great.',
82 'date': (new Date(now - 12600000)),82 'date': (new Date(now - 12600000)),
83 },83 }
84 ];84 ];
85 mockio.success({85 mockio.success({
86 responseText: Y.JSON.stringify(published_comments),86 responseText: Y.JSON.stringify(published_comments),
@@ -88,7 +88,7 @@
8888
89 // Published comment is displayed.89 // Published comment is displayed.
90 var first_comments = Y.one('#diff-line-2').next().one('div');90 var first_comments = Y.one('#diff-line-2').next().one('div');
91 var first = first_comments.one('div:first-child')91 var first = first_comments.one('div:first-child');
92 Y.Assert.areEqual(92 Y.Assert.areEqual(
93 'Foo Bar (name16) wrote on 2012-08-12:',93 'Foo Bar (name16) wrote on 2012-08-12:',
94 first.one('.boardCommentDetails').get('text'));94 first.one('.boardCommentDetails').get('text'));
@@ -107,11 +107,11 @@
107107
108 // Draft comment for line 3 is displayed.108 // Draft comment for line 3 is displayed.
109 var second_comments = Y.one('#diff-line-3').next().one('div');109 var second_comments = Y.one('#diff-line-3').next().one('div');
110 var third = second_comments.one('div:first-child')110 var third = second_comments.one('div:first-child');
111 Y.Assert.areEqual(111 Y.Assert.areEqual(
112 'Foo Bar (name16) wrote 3 hours ago:',112 'Foo Bar (name16) wrote 3 hours ago:',
113 third.one('.boardCommentDetails').get('text'));113 third.one('.boardCommentDetails').get('text'));
114 var fourth = third.next()114 var fourth = third.next();
115 Y.Assert.areEqual(115 Y.Assert.areEqual(
116 'Unsaved comment',116 'Unsaved comment',
117 fourth.one('.boardCommentDetails').get('text'));117 fourth.one('.boardCommentDetails').get('text'));