From 2669f23e99be0bb6b65d365151884de52434301c Mon Sep 17 00:00:00 2001 From: YuLe Date: Tue, 4 Dec 2018 00:16:20 +0800 Subject: [PATCH] Fixed negative decimals less than -10 don't work (#111) --- index.js | 2 +- tests.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 7229750..a1d2ea4 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ function parse(str) { if (str.length > 100) { return; } - var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( + var match = /^((?:\d+)?-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( str ); if (!match) { diff --git a/tests.js b/tests.js index 3e94007..9427390 100644 --- a/tests.js +++ b/tests.js @@ -71,6 +71,7 @@ describe('ms(string)', function() { it('should work with negative decimals', function() { expect(ms('-1.5h')).to.be(-5400000); + expect(ms('-10.5h')).to.be(-37800000); }); it('should work with negative decimals starting with "."', function() {