Merge "Update gr-date-formatter to suport showing time and date"
This commit is contained in:
@@ -195,6 +195,7 @@ limitations under the License.
|
|||||||
<span class="date">
|
<span class="date">
|
||||||
<gr-date-formatter
|
<gr-date-formatter
|
||||||
has-tooltip
|
has-tooltip
|
||||||
|
show-date-and-time
|
||||||
date-str="[[message.date]]"></gr-date-formatter>
|
date-str="[[message.date]]"></gr-date-formatter>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
@@ -202,6 +203,7 @@ limitations under the License.
|
|||||||
<a class="date" href$="[[_computeMessageHash(message)]]" on-tap="_handleLinkTap">
|
<a class="date" href$="[[_computeMessageHash(message)]]" on-tap="_handleLinkTap">
|
||||||
<gr-date-formatter
|
<gr-date-formatter
|
||||||
has-tooltip
|
has-tooltip
|
||||||
|
show-date-and-time
|
||||||
date-str="[[message.date]]"></gr-date-formatter>
|
date-str="[[message.date]]"></gr-date-formatter>
|
||||||
</a>
|
</a>
|
||||||
</template>
|
</template>
|
||||||
|
@@ -30,7 +30,7 @@ limitations under the License.
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<span>
|
<span>
|
||||||
[[_computeDateStr(dateStr, _timeFormat, _relative)]]
|
[[_computeDateStr(dateStr, _timeFormat, _relative, showDateAndTime)]]
|
||||||
</span>
|
</span>
|
||||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||||
</template>
|
</template>
|
||||||
|
@@ -37,6 +37,10 @@
|
|||||||
value: null,
|
value: null,
|
||||||
notify: true,
|
notify: true,
|
||||||
},
|
},
|
||||||
|
showDateAndTime: {
|
||||||
|
type: Boolean,
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When true, the detailed date appears in a GR-TOOLTIP rather than in the
|
* When true, the detailed date appears in a GR-TOOLTIP rather than in the
|
||||||
@@ -131,7 +135,7 @@
|
|||||||
diff < 180 * Duration.DAY;
|
diff < 180 * Duration.DAY;
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeDateStr(dateStr, timeFormat, relative) {
|
_computeDateStr(dateStr, timeFormat, relative, showDateAndTime) {
|
||||||
if (!dateStr) { return ''; }
|
if (!dateStr) { return ''; }
|
||||||
const date = moment(util.parseDate(dateStr));
|
const date = moment(util.parseDate(dateStr));
|
||||||
if (!date.isValid()) { return ''; }
|
if (!date.isValid()) { return ''; }
|
||||||
@@ -147,9 +151,14 @@
|
|||||||
let format = TimeFormats.MONTH_DAY_YEAR;
|
let format = TimeFormats.MONTH_DAY_YEAR;
|
||||||
if (this._isWithinDay(now, date)) {
|
if (this._isWithinDay(now, date)) {
|
||||||
format = timeFormat;
|
format = timeFormat;
|
||||||
} else if (this._isWithinHalfYear(now, date)) {
|
} else {
|
||||||
|
if (this._isWithinHalfYear(now, date)) {
|
||||||
format = TimeFormats.MONTH_DAY;
|
format = TimeFormats.MONTH_DAY;
|
||||||
}
|
}
|
||||||
|
if (this.showDateAndTime) {
|
||||||
|
format = `${format} ${timeFormat}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
return date.format(format);
|
return date.format(format);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -55,7 +55,8 @@ limitations under the License.
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDates(nowStr, dateStr, expected, expectedTooltip, done) {
|
function testDates(nowStr, dateStr, expected, expectedWithDateAndTime,
|
||||||
|
expectedTooltip, done) {
|
||||||
// Normalize and convert the date to mimic server response.
|
// Normalize and convert the date to mimic server response.
|
||||||
dateStr = normalizedDate(dateStr)
|
dateStr = normalizedDate(dateStr)
|
||||||
.toJSON().replace('T', ' ').slice(0, -1);
|
.toJSON().replace('T', ' ').slice(0, -1);
|
||||||
@@ -65,6 +66,9 @@ limitations under the License.
|
|||||||
const span = element.$$('span');
|
const span = element.$$('span');
|
||||||
assert.equal(span.textContent.trim(), expected);
|
assert.equal(span.textContent.trim(), expected);
|
||||||
assert.equal(element.title, expectedTooltip);
|
assert.equal(element.title, expectedTooltip);
|
||||||
|
element.showDateAndTime = true;
|
||||||
|
flushAsynchronousOperations();
|
||||||
|
assert.equal(span.textContent.trim(), expectedWithDateAndTime);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -98,25 +102,33 @@ limitations under the License.
|
|||||||
test('Within 24 hours on same day', done => {
|
test('Within 24 hours on same day', done => {
|
||||||
testDates('2015-07-29 20:34:14.985000000',
|
testDates('2015-07-29 20:34:14.985000000',
|
||||||
'2015-07-29 15:34:14.985000000',
|
'2015-07-29 15:34:14.985000000',
|
||||||
'15:34', 'Jul 29, 2015, 15:34:14', done);
|
'15:34',
|
||||||
|
'15:34',
|
||||||
|
'Jul 29, 2015, 15:34:14', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Within 24 hours on different days', done => {
|
test('Within 24 hours on different days', done => {
|
||||||
testDates('2015-07-29 03:34:14.985000000',
|
testDates('2015-07-29 03:34:14.985000000',
|
||||||
'2015-07-28 20:25:14.985000000',
|
'2015-07-28 20:25:14.985000000',
|
||||||
'Jul 28', 'Jul 28, 2015, 20:25:14', done);
|
'Jul 28',
|
||||||
|
'Jul 28 20:25',
|
||||||
|
'Jul 28, 2015, 20:25:14', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('More than 24 hours but less than six months', done => {
|
test('More than 24 hours but less than six months', done => {
|
||||||
testDates('2015-07-29 20:34:14.985000000',
|
testDates('2015-07-29 20:34:14.985000000',
|
||||||
'2015-06-15 03:25:14.985000000',
|
'2015-06-15 03:25:14.985000000',
|
||||||
'Jun 15', 'Jun 15, 2015, 03:25:14', done);
|
'Jun 15',
|
||||||
|
'Jun 15 03:25',
|
||||||
|
'Jun 15, 2015, 03:25:14', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('More than six months', done => {
|
test('More than six months', done => {
|
||||||
testDates('2015-09-15 20:34:00.000000000',
|
testDates('2015-09-15 20:34:00.000000000',
|
||||||
'2015-01-15 03:25:00.000000000',
|
'2015-01-15 03:25:00.000000000',
|
||||||
'Jan 15, 2015', 'Jan 15, 2015, 03:25:00', done);
|
'Jan 15, 2015',
|
||||||
|
'Jan 15, 2015 03:25',
|
||||||
|
'Jan 15, 2015, 03:25:00', done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -135,7 +147,9 @@ limitations under the License.
|
|||||||
test('Within 24 hours on same day', done => {
|
test('Within 24 hours on same day', done => {
|
||||||
testDates('2015-07-29 20:34:14.985000000',
|
testDates('2015-07-29 20:34:14.985000000',
|
||||||
'2015-07-29 15:34:14.985000000',
|
'2015-07-29 15:34:14.985000000',
|
||||||
'3:34 PM', 'Jul 29, 2015, 3:34:14 PM', done);
|
'3:34 PM',
|
||||||
|
'3:34 PM',
|
||||||
|
'Jul 29, 2015, 3:34:14 PM', done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -153,13 +167,17 @@ limitations under the License.
|
|||||||
test('Within 24 hours on same day', done => {
|
test('Within 24 hours on same day', done => {
|
||||||
testDates('2015-07-29 20:34:14.985000000',
|
testDates('2015-07-29 20:34:14.985000000',
|
||||||
'2015-07-29 15:34:14.985000000',
|
'2015-07-29 15:34:14.985000000',
|
||||||
'5 hours ago', 'Jul 29, 2015, 3:34:14 PM', done);
|
'5 hours ago',
|
||||||
|
'5 hours ago',
|
||||||
|
'Jul 29, 2015, 3:34:14 PM', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('More than six months', done => {
|
test('More than six months', done => {
|
||||||
testDates('2015-09-15 20:34:00.000000000',
|
testDates('2015-09-15 20:34:00.000000000',
|
||||||
'2015-01-15 03:25:00.000000000',
|
'2015-01-15 03:25:00.000000000',
|
||||||
'8 months ago', 'Jan 15, 2015, 3:25:00 AM', done);
|
'8 months ago',
|
||||||
|
'8 months ago',
|
||||||
|
'Jan 15, 2015, 3:25:00 AM', done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user