From 5122672333dc0009af90c6e728c7d79031516f61 Mon Sep 17 00:00:00 2001 From: Dan Wilson Date: Tue, 14 May 2013 18:18:22 +0100 Subject: [PATCH] Fixed date-parsing logic so that it works on oldIE. Issue #323. --- src/view.timeline.js | 10 +++++----- test/view.timeline.test.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/view.timeline.js b/src/view.timeline.js index 40aa7563..81b02784 100644 --- a/src/view.timeline.js +++ b/src/view.timeline.js @@ -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; } }, diff --git a/test/view.timeline.test.js b/test/view.timeline.test.js index 0b6637d8..5e3bf148 100644 --- a/test/view.timeline.test.js +++ b/test/view.timeline.test.js @@ -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': '
Date: 2012-03-20
title: 1
' }, { - 'startDate': new Date('2012-03-25'), + 'startDate': moment('2012-03-25').toDate(), 'endDate': null, 'headline': '2', 'text': '
Date: 2012-03-25
title: 2
'