Fixed date-parsing logic so that it works on oldIE. Issue #323.

This commit is contained in:
Dan Wilson 2013-05-14 18:18:22 +01:00
parent cf700f4ac0
commit 5122672333
2 changed files with 7 additions and 7 deletions

View File

@ -134,14 +134,14 @@ my.Timeline = Backbone.View.extend({
if (!date) {
return null;
}
var out = date.trim();
var out = $.trim(date);
out = out.replace(/(\d)th/g, '$1');
out = out.replace(/(\d)st/g, '$1');
out = out.trim() ? moment(out) : null;
if (out.toDate() == 'Invalid Date') {
return null;
} else {
out = $.trim(out) ? moment(out) : null;
if (out && out.isValid()) {
return out.toDate();
} else {
return null;
}
},

View File

@ -19,13 +19,13 @@ test('extract dates and timelineJSON', function () {
'headline': '',
'date': [
{
'startDate': new Date('2012-03-20'),
'startDate': moment('2012-03-20').toDate(),
'endDate': null,
'headline': '1',
'text': '<div class="recline-record-summary"><div class="Date"><strong>Date</strong>: 2012-03-20</div><div class="title"><strong>title</strong>: 1</div></div>'
},
{
'startDate': new Date('2012-03-25'),
'startDate': moment('2012-03-25').toDate(),
'endDate': null,
'headline': '2',
'text': '<div class="recline-record-summary"><div class="Date"><strong>Date</strong>: 2012-03-25</div><div class="title"><strong>title</strong>: 2</div></div>'