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
1=== modified file 'lib/lp/app/javascript/date.js'
2--- lib/lp/app/javascript/date.js 2014-07-08 12:32:44 +0000
3+++ lib/lp/app/javascript/date.js 2014-07-08 23:47:16 +0000
4@@ -7,11 +7,11 @@
5
6 namespace.parse_date = function(str) {
7 // Parse an ISO-8601 date
8- var re = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|\+00:00)$/
9- var bits = re.exec(str).slice(1, 8).map(Number)
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);
12 // Adjusting for the fact that Date.UTC uses 0-11 for months
13- bits[1] -= 1
14- return new Date(Date.UTC.apply(null, bits))
15+ bits[1] -= 1;
16+ return new Date(Date.UTC.apply(null, bits));
17 };
18
19 namespace.approximatedate = function(date) {
20@@ -19,28 +19,28 @@
21 // day ago.
22 var now = (new Date).valueOf();
23 var timedelta = now - date;
24- var days = timedelta / 86400000
25- var hours = timedelta / 3600000
26- var minutes = timedelta / 60000
27- var amount = 0
28- var unit = ""
29+ var days = timedelta / 86400000;
30+ var hours = timedelta / 3600000;
31+ var minutes = timedelta / 60000;
32+ var amount = 0;
33+ var unit = "";
34 if (days > 1) {
35 return 'on ' + Y.Date.format(
36 new Date(date), {format: '%Y-%m-%d'});
37 } else {
38 if (hours >= 1) {
39- amount = hours
40- unit = "hour"
41+ amount = hours;
42+ unit = "hour";
43 } else if (minutes >= 1) {
44- amount = minutes
45- unit = "minute"
46+ amount = minutes;
47+ unit = "minute";
48 } else {
49- return "a moment ago"
50+ return "a moment ago";
51 }
52 if (Math.floor(amount) > 1) {
53- unit = unit + 's'
54+ unit = unit + 's';
55 }
56- return Math.floor(amount) + ' ' + unit + ' ago'
57+ return Math.floor(amount) + ' ' + unit + ' ago';
58 }
59 };
60 }, "0.1", {'requires': ['datatype-date']});
61
62=== modified file 'lib/lp/app/javascript/tests/test_date.js'
63--- lib/lp/app/javascript/tests/test_date.js 2014-07-08 12:32:44 +0000
64+++ lib/lp/app/javascript/tests/test_date.js 2014-07-08 23:47:16 +0000
65@@ -3,7 +3,7 @@
66 var tests = Y.namespace('date.test');
67 tests.suite = new Y.Test.Suite("date tests");
68
69- var now = (new Date).valueOf()
70+ var now = (new Date).valueOf();
71 tests.suite.add(new Y.Test.Case({
72 name: 'test_approximatedate',
73
74
75=== modified file 'lib/lp/code/javascript/branchmergeproposal.inlinecomments.js'
76--- lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-07-08 12:32:44 +0000
77+++ lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-07-08 23:47:16 +0000
78@@ -187,7 +187,7 @@
79 if (typeof comment.date === "string") {
80 var comment_date = Y.lp.app.date.parse_date(comment.date);
81 } else {
82- var comment_date = comment.date
83+ var comment_date = comment.date;
84 }
85 var date = Y.lp.app.date.approximatedate(comment_date);
86 headerspan.one('span').set('text', date);
87
88=== modified file 'lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js'
89--- lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-07-08 12:32:44 +0000
90+++ lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-07-08 23:47:16 +0000
91@@ -70,7 +70,7 @@
92 "ws.op=getInlineComments&previewdiff_id=1",
93 mockio.requests[0].config.data);
94 mockio.last_request = mockio.requests[0];
95- var now = (new Date).valueOf()
96+ var now = (new Date).valueOf();
97 published_comments = [
98 {'line_number': '2',
99 'person': person_obj,
100@@ -80,7 +80,7 @@
101 'person': person_obj,
102 'text': 'This is great.',
103 'date': (new Date(now - 12600000)),
104- },
105+ }
106 ];
107 mockio.success({
108 responseText: Y.JSON.stringify(published_comments),
109@@ -88,7 +88,7 @@
110
111 // Published comment is displayed.
112 var first_comments = Y.one('#diff-line-2').next().one('div');
113- var first = first_comments.one('div:first-child')
114+ var first = first_comments.one('div:first-child');
115 Y.Assert.areEqual(
116 'Foo Bar (name16) wrote on 2012-08-12:',
117 first.one('.boardCommentDetails').get('text'));
118@@ -107,11 +107,11 @@
119
120 // Draft comment for line 3 is displayed.
121 var second_comments = Y.one('#diff-line-3').next().one('div');
122- var third = second_comments.one('div:first-child')
123+ var third = second_comments.one('div:first-child');
124 Y.Assert.areEqual(
125 'Foo Bar (name16) wrote 3 hours ago:',
126 third.one('.boardCommentDetails').get('text'));
127- var fourth = third.next()
128+ var fourth = third.next();
129 Y.Assert.areEqual(
130 'Unsaved comment',
131 fourth.one('.boardCommentDetails').get('text'));