From 8268b964600c0d84cfafe2cc4c93c5bca56fe7c6 Mon Sep 17 00:00:00 2001 From: yuler Date: Fri, 12 Oct 2018 15:58:16 +0800 Subject: [PATCH] Fixed negative decimals less than -10 don't work --- 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() {