From be32715d3c0486912614bcf84d7fdae01fd48217 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Sat, 9 Apr 2011 10:15:24 -0700 Subject: [PATCH] parse unix timestamps with decimal points (issue 826) --- src/date_util.js | 4 ++-- tests/sources.html | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/date_util.js b/src/date_util.js index d94e366..9e2037a 100644 --- a/src/date_util.js +++ b/src/date_util.js @@ -146,8 +146,8 @@ function parseDate(s, ignoreTimezone) { // ignoreTimezone defaults to true return new Date(s * 1000); } if (typeof s == 'string') { - if (s.match(/^\d+$/)) { // a UNIX timestamp - return new Date(parseInt(s, 10) * 1000); + if (s.match(/^\d+(\.\d+)?$/)) { // a UNIX timestamp + return new Date(parseFloat(s) * 1000); } if (ignoreTimezone === undefined) { ignoreTimezone = true; diff --git a/tests/sources.html b/tests/sources.html index d3c6129..e2ecde6 100644 --- a/tests/sources.html +++ b/tests/sources.html @@ -83,6 +83,10 @@ start: new Date(y, m, 28), end: new Date(y, m, 29), url: 'http://google.com/' + }, + { + title: 'Float String Timestamp Event', + start: '1295078400.0' } ];