Skip to content

Commit

Permalink
Merge pull request #239 from coatesap/master
Browse files Browse the repository at this point in the history
Allow space before am/pm suffix
  • Loading branch information
spencermountain authored Nov 11, 2020
2 parents 9a2c57a + 927c486 commit 6f63a90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/methods/set/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions test/set.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()')
Expand Down

0 comments on commit 6f63a90

Please sign in to comment.