From 5ee55a7dc1b1becc338c26b77e3d9a8cdcde236d Mon Sep 17 00:00:00 2001 From: Devin Spikowski Date: Mon, 14 May 2018 04:23:52 -0400 Subject: [PATCH 1/2] Fix parsing of decimal input values Previously, `1.5 hours` would parse as `5 hours`, or `1.0 hours` as `0 hours` This was presumably working in 2012 with PR #2 but has since broken. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fde6006..4dae082 100644 --- a/index.js +++ b/index.js @@ -54,11 +54,11 @@ function parseTimestring (string, returnUnit, opts) { let groups = string .toLowerCase() .replace(/[^.\w+-]+/g, '') - .match(/[-+]?[0-9]+[a-z]+/g) + .match(/[-+]?[0-9\.]+[a-z]+/g) if (groups !== null) { groups.forEach(group => { - let value = group.match(/[0-9]+/g)[0] + let value = group.match(/[0-9\.]+/g)[0] let unit = group.match(/[a-z]+/g)[0] totalSeconds += getSeconds(value, unit, unitValues) From a3f5260e551486afce8114897fd56a6800b90b08 Mon Sep 17 00:00:00 2001 From: Devin Spikowski Date: Mon, 14 May 2018 04:30:57 -0400 Subject: [PATCH 2/2] Remove unnecessary escape characters --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 4dae082..b21f71e 100644 --- a/index.js +++ b/index.js @@ -54,11 +54,11 @@ function parseTimestring (string, returnUnit, opts) { let groups = string .toLowerCase() .replace(/[^.\w+-]+/g, '') - .match(/[-+]?[0-9\.]+[a-z]+/g) + .match(/[-+]?[0-9.]+[a-z]+/g) if (groups !== null) { groups.forEach(group => { - let value = group.match(/[0-9\.]+/g)[0] + let value = group.match(/[0-9.]+/g)[0] let unit = group.match(/[a-z]+/g)[0] totalSeconds += getSeconds(value, unit, unitValues)