diff --git a/src/methods/set/set.js b/src/methods/set/set.js index 050366c9..f63b4166 100644 --- a/src/methods/set/set.js +++ b/src/methods/set/set.js @@ -91,10 +91,10 @@ module.exports = { //support setting time by '4:25pm' - this isn't very-well developed.. time: (s, str) => { - let m = str.match(/([0-9]{1,2}):([0-9]{1,2})(am|pm)?/) + let m = str.match(/([0-9]{1,2}):([0-9]{1,2}) ?(am|pm)?/) if (!m) { //fallback to support just '2am' - m = str.match(/([0-9]{1,2})(am|pm)/) + m = str.match(/([0-9]{1,2}) ?(am|pm)/) if (!m) { return s.epoch } diff --git a/test/set.test.js b/test/set.test.js index 6092f1dc..60fa32b8 100644 --- a/test/set.test.js +++ b/test/set.test.js @@ -69,6 +69,18 @@ test('set', (t) => { t.equal(s.hour(), 17, 'time-hour-pm()') t.equal(s.minute(), 20, 'time-minute-pm()') + s = s.time('5:20 pm') + t.equal(s.hour(), 17, 'time-hour-pm-with-space()') + t.equal(s.minute(), 20, 'time-minute-pm-with-space()') + + s = s.time('5pm') + t.equal(s.hour(), 17, 'time-hour-pm-hour-only()') + t.equal(s.minute(), 0, 'time-minute-pm-hour-only()') + + s = s.time('6 pm') + t.equal(s.hour(), 18, 'time-hour-pm-hour-only-with-space()') + t.equal(s.minute(), 0, 'time-minute-pm-hour-only-with-space()') + s = s.time('13:20pm') t.equal(s.hour(), 13, 'time-hour-24h()') t.equal(s.minute(), 20, 'time-minute-24h()')