tickbin-parser
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -8,2 +8,5 @@ 'use strict'; | ||
exports.default = function (str, timezoneOffset) { | ||
var parserWithDurationRefiner = new _chronoNode2.default.Chrono(); | ||
parserWithDurationRefiner.refiners.push(_durationRefiner2.default); | ||
var patternHour = /(\d*\.{0,1}\d+)\s*(hours|hour|hrs|hr|h)\b/i; | ||
@@ -28,3 +31,3 @@ var patternMin = /(\d*\.{0,1}\d+)\s*(minutes|minute|mins|min|m)\b/i; | ||
var parsedDate = _chronoNode2.default.parse(str)[0]; | ||
var parsedDate = parserWithDurationRefiner.parse(str)[0]; | ||
@@ -54,2 +57,6 @@ if (parsedDate) { | ||
var _durationRefiner = require('./refiners/durationRefiner'); | ||
var _durationRefiner2 = _interopRequireDefault(_durationRefiner); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -49,2 +49,6 @@ 'use strict'; | ||
var _militaryRefiner = require('./refiners/militaryRefiner'); | ||
var _militaryRefiner2 = _interopRequireDefault(_militaryRefiner); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -57,2 +61,3 @@ | ||
parser.refiners.push(_impliedPMStartRefiner2.default); | ||
parser.refiners.push(_dayOverlapRefiner2.default); | ||
parser.refiners.push(_dayOverlapRefiner2.default); | ||
parser.refiners.push(_militaryRefiner2.default); |
@@ -11,10 +11,8 @@ 'use strict'; | ||
var _parseTime = require('../helpers/parseTime'); | ||
var _parseTime2 = _interopRequireDefault(_parseTime); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function parseTime(h24) { | ||
var hour = parseInt(h24.substr(0, h24.length == 3 ? 1 : 2)); | ||
var minute = parseInt(h24.substr(-2)); | ||
return { hour: hour, minute: minute }; | ||
} | ||
function pattern() { | ||
@@ -27,4 +25,4 @@ return (/([0-9]{3,4}) *- *([0-9]{3,4})/ | ||
var index = match.index; | ||
var start = parseTime(match[1]); | ||
var end = parseTime(match[2]); | ||
var start = (0, _parseTime2.default)(match[1]); | ||
var end = (0, _parseTime2.default)(match[2]); | ||
var result = new _chronoNode2.default.ParsedResult({ | ||
@@ -31,0 +29,0 @@ ref: ref, text: match[0], index: index, start: start, end: end |
@@ -11,5 +11,5 @@ 'use strict'; | ||
var _durationParser32 = require('../durationParser'); | ||
var _durationParser35 = require('../durationParser'); | ||
var _durationParser33 = _interopRequireDefault(_durationParser32); | ||
var _durationParser36 = _interopRequireDefault(_durationParser35); | ||
@@ -19,3 +19,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
(0, _tape2.default)('simple hour duration: 5 hours', function (t) { | ||
var _durationParser = (0, _durationParser33.default)('5 hours'), | ||
var _durationParser = (0, _durationParser36.default)('5 hours'), | ||
date = _durationParser.date, | ||
@@ -31,3 +31,3 @@ duration = _durationParser.duration; | ||
(0, _tape2.default)('simple minute duration: 30 minutes', function (t) { | ||
var _durationParser2 = (0, _durationParser33.default)('30 minutes'), | ||
var _durationParser2 = (0, _durationParser36.default)('30 minutes'), | ||
date = _durationParser2.date, | ||
@@ -43,3 +43,3 @@ duration = _durationParser2.duration; | ||
(0, _tape2.default)('hour and minute duration: 5 hours 30 minutes', function (t) { | ||
var _durationParser3 = (0, _durationParser33.default)('5 hours 30 minutes'), | ||
var _durationParser3 = (0, _durationParser36.default)('5 hours 30 minutes'), | ||
date = _durationParser3.date, | ||
@@ -55,3 +55,3 @@ duration = _durationParser3.duration; | ||
(0, _tape2.default)('chrono input: 5:30 hours', function (t) { | ||
var _durationParser4 = (0, _durationParser33.default)('5:30 hours'), | ||
var _durationParser4 = (0, _durationParser36.default)('5:30 hours'), | ||
date = _durationParser4.date, | ||
@@ -67,3 +67,3 @@ duration = _durationParser4.duration; | ||
(0, _tape2.default)('implied date: yesterday 5 hours', function (t) { | ||
var _durationParser5 = (0, _durationParser33.default)('yesterday 5 hours'), | ||
var _durationParser5 = (0, _durationParser36.default)('yesterday 5 hours'), | ||
date = _durationParser5.date, | ||
@@ -78,7 +78,46 @@ duration = _durationParser5.duration; | ||
(0, _tape2.default)('specified date: Aug 15 5 hours', function (t) { | ||
var _durationParser6 = (0, _durationParser33.default)('Aug 15 5 hours'), | ||
(0, _tape2.default)('implied date: Yesterday 7.5 hours', function (t) { | ||
var _durationParser6 = (0, _durationParser36.default)('Yesterday 7.5 hours #stat #robot PR 35'), | ||
date = _durationParser6.date, | ||
duration = _durationParser6.duration; | ||
duration = _durationParser6.duration, | ||
message = _durationParser6.message; | ||
t.ok((0, _moment2.default)().subtract(1, 'day').isSame(date, 'day'), 'parsed as yesterday'); | ||
t.equal(duration, 27000, 'parsed duration'); // 7.5 hours in seconds | ||
t.equal(message, '#stat #robot PR 35', 'parsed message'); | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('implied date: 7.5 hours Yesterday', function (t) { | ||
var _durationParser7 = (0, _durationParser36.default)('7.5 hours Yesterday #stat #robot PR 35'), | ||
date = _durationParser7.date, | ||
duration = _durationParser7.duration, | ||
message = _durationParser7.message; | ||
t.ok((0, _moment2.default)().subtract(1, 'day').isSame(date, 'day'), 'parsed as yesterday'); | ||
t.equal(duration, 27000, 'parsed duration'); // 7.5 hours in seconds | ||
t.equal(message, '#stat #robot PR 35', 'parsed message'); | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('implied date: Yesterday 7 hours', function (t) { | ||
var _durationParser8 = (0, _durationParser36.default)('Yesterday 7 hours #stat #robot PR 35'), | ||
date = _durationParser8.date, | ||
duration = _durationParser8.duration, | ||
message = _durationParser8.message; | ||
t.ok((0, _moment2.default)().subtract(1, 'day').isSame(date, 'day'), 'parsed as yesterday'); | ||
t.equal(duration, 25200, 'parsed duration'); // 7 hours in seconds | ||
t.equal(message, '#stat #robot PR 35', 'parsed message'); | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('specified date: Aug 15 5 hours', function (t) { | ||
var _durationParser9 = (0, _durationParser36.default)('Aug 15 5 hours'), | ||
date = _durationParser9.date, | ||
duration = _durationParser9.duration; | ||
t.equal((0, _moment2.default)(date).date(), 15, 'date is the 15th day'); | ||
@@ -92,5 +131,5 @@ t.equal((0, _moment2.default)(date).month(), 7, 'date is Aug'); | ||
(0, _tape2.default)('units in decimal: 1.5 hours 1.5 minutes', function (t) { | ||
var _durationParser7 = (0, _durationParser33.default)('1.5 hours 1.5 minutes'), | ||
date = _durationParser7.date, | ||
duration = _durationParser7.duration; | ||
var _durationParser10 = (0, _durationParser36.default)('1.5 hours 1.5 minutes'), | ||
date = _durationParser10.date, | ||
duration = _durationParser10.duration; | ||
@@ -104,4 +143,4 @@ t.ok((0, _moment2.default)().isSame(date, 'day'), 'parsed as current date'); | ||
(0, _tape2.default)('returns original message without date or duration', function (t) { | ||
var _durationParser8 = (0, _durationParser33.default)('yesterday 5 hours all the #things'), | ||
message = _durationParser8.message; | ||
var _durationParser11 = (0, _durationParser36.default)('yesterday 5 hours all the #things'), | ||
message = _durationParser11.message; | ||
@@ -114,14 +153,14 @@ t.equal(message, 'all the #things', 'stripped date and time from message'); | ||
(0, _tape2.default)('does not take the first letter from other words', function (t) { | ||
var _durationParser9 = (0, _durationParser33.default)('2 houses'), | ||
dh = _durationParser9.duration; | ||
var _durationParser12 = (0, _durationParser36.default)('2 houses'), | ||
dh = _durationParser12.duration; | ||
t.equal(dh, 0, 'does not take h from \'houses\''); | ||
var _durationParser10 = (0, _durationParser33.default)('2.5 mouses'), | ||
dm = _durationParser10.duration; | ||
var _durationParser13 = (0, _durationParser36.default)('2.5 mouses'), | ||
dm = _durationParser13.duration; | ||
t.equal(dm, 0, 'does not take m from \'mouses\''); | ||
var _durationParser11 = (0, _durationParser33.default)('2:30 houses'), | ||
dc = _durationParser11.duration; | ||
var _durationParser14 = (0, _durationParser36.default)('2:30 houses'), | ||
dc = _durationParser14.duration; | ||
@@ -134,9 +173,9 @@ t.equal(dc, 0, 'does not take h from \'houses\''); | ||
t.test('parses minutes', function (t) { | ||
var _durationParser12 = (0, _durationParser33.default)('30 minutes'), | ||
duration = _durationParser12.duration; | ||
var _durationParser15 = (0, _durationParser36.default)('30 minutes'), | ||
duration = _durationParser15.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser13 = (0, _durationParser33.default)('30minutes'), | ||
duration2 = _durationParser13.duration; | ||
var _durationParser16 = (0, _durationParser36.default)('30minutes'), | ||
duration2 = _durationParser16.duration; | ||
@@ -148,9 +187,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses minute', function (t) { | ||
var _durationParser14 = (0, _durationParser33.default)('30 minute'), | ||
duration = _durationParser14.duration; | ||
var _durationParser17 = (0, _durationParser36.default)('30 minute'), | ||
duration = _durationParser17.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser15 = (0, _durationParser33.default)('30minute'), | ||
duration2 = _durationParser15.duration; | ||
var _durationParser18 = (0, _durationParser36.default)('30minute'), | ||
duration2 = _durationParser18.duration; | ||
@@ -162,9 +201,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses mins', function (t) { | ||
var _durationParser16 = (0, _durationParser33.default)('30 mins'), | ||
duration = _durationParser16.duration; | ||
var _durationParser19 = (0, _durationParser36.default)('30 mins'), | ||
duration = _durationParser19.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser17 = (0, _durationParser33.default)('30mins'), | ||
duration2 = _durationParser17.duration; | ||
var _durationParser20 = (0, _durationParser36.default)('30mins'), | ||
duration2 = _durationParser20.duration; | ||
@@ -176,9 +215,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses min', function (t) { | ||
var _durationParser18 = (0, _durationParser33.default)('30 min'), | ||
duration = _durationParser18.duration; | ||
var _durationParser21 = (0, _durationParser36.default)('30 min'), | ||
duration = _durationParser21.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser19 = (0, _durationParser33.default)('30min'), | ||
duration2 = _durationParser19.duration; | ||
var _durationParser22 = (0, _durationParser36.default)('30min'), | ||
duration2 = _durationParser22.duration; | ||
@@ -190,9 +229,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses m', function (t) { | ||
var _durationParser20 = (0, _durationParser33.default)('30 m'), | ||
duration = _durationParser20.duration; | ||
var _durationParser23 = (0, _durationParser36.default)('30 m'), | ||
duration = _durationParser23.duration; | ||
t.equal(duration, 1800, 'parsed duration'); | ||
var _durationParser21 = (0, _durationParser33.default)('30m'), | ||
duration2 = _durationParser21.duration; | ||
var _durationParser24 = (0, _durationParser36.default)('30m'), | ||
duration2 = _durationParser24.duration; | ||
@@ -204,9 +243,9 @@ t.equal(duration2, 1800, 'parsed duration'); | ||
t.test('parses hours', function (t) { | ||
var _durationParser22 = (0, _durationParser33.default)('1 hours'), | ||
duration = _durationParser22.duration; | ||
var _durationParser25 = (0, _durationParser36.default)('1 hours'), | ||
duration = _durationParser25.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser23 = (0, _durationParser33.default)('1hours'), | ||
duration2 = _durationParser23.duration; | ||
var _durationParser26 = (0, _durationParser36.default)('1hours'), | ||
duration2 = _durationParser26.duration; | ||
@@ -218,9 +257,9 @@ t.equal(duration2, 3600, 'parsed duration'); | ||
t.test('parses hour', function (t) { | ||
var _durationParser24 = (0, _durationParser33.default)('1 hour'), | ||
duration = _durationParser24.duration; | ||
var _durationParser27 = (0, _durationParser36.default)('1 hour'), | ||
duration = _durationParser27.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser25 = (0, _durationParser33.default)('1hour'), | ||
duration2 = _durationParser25.duration; | ||
var _durationParser28 = (0, _durationParser36.default)('1hour'), | ||
duration2 = _durationParser28.duration; | ||
@@ -232,9 +271,9 @@ t.equal(duration2, 3600, 'parsed duration'); | ||
t.test('parses hrs', function (t) { | ||
var _durationParser26 = (0, _durationParser33.default)('1 hrs'), | ||
duration = _durationParser26.duration; | ||
var _durationParser29 = (0, _durationParser36.default)('1 hrs'), | ||
duration = _durationParser29.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser27 = (0, _durationParser33.default)('1hrs'), | ||
duration2 = _durationParser27.duration; | ||
var _durationParser30 = (0, _durationParser36.default)('1hrs'), | ||
duration2 = _durationParser30.duration; | ||
@@ -246,9 +285,9 @@ t.equal(duration2, 3600, 'parsed duration'); | ||
t.test('parses hr', function (t) { | ||
var _durationParser28 = (0, _durationParser33.default)('1 hr'), | ||
duration = _durationParser28.duration; | ||
var _durationParser31 = (0, _durationParser36.default)('1 hr'), | ||
duration = _durationParser31.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser29 = (0, _durationParser33.default)('1hr'), | ||
duration2 = _durationParser29.duration; | ||
var _durationParser32 = (0, _durationParser36.default)('1hr'), | ||
duration2 = _durationParser32.duration; | ||
@@ -260,9 +299,9 @@ t.equal(duration2, 3600, 'parsed duration'); | ||
t.test('parses h', function (t) { | ||
var _durationParser30 = (0, _durationParser33.default)('1 h'), | ||
duration = _durationParser30.duration; | ||
var _durationParser33 = (0, _durationParser36.default)('1 h'), | ||
duration = _durationParser33.duration; | ||
t.equal(duration, 3600, 'parsed duration'); | ||
var _durationParser31 = (0, _durationParser33.default)('1h'), | ||
duration2 = _durationParser31.duration; | ||
var _durationParser34 = (0, _durationParser36.default)('1h'), | ||
duration2 = _durationParser34.duration; | ||
@@ -269,0 +308,0 @@ t.equal(duration2, 3600, 'parsed duration'); |
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _moment = require('moment'); | ||
var _moment2 = _interopRequireDefault(_moment); | ||
var _militaryParser = require('../../parsers/militaryParser'); | ||
@@ -26,4 +30,4 @@ | ||
t.equals(results[0].start.get('minute'), 0, 'start is 8:00 am'); | ||
t.equals(results[0].end.get('hour'), 9, 'start is 9:30 am'); | ||
t.equals(results[0].end.get('minute'), 30, 'start is 9:30 am'); | ||
t.equals(results[0].end.get('hour'), 9, 'end is 9:30 am'); | ||
t.equals(results[0].end.get('minute'), 30, 'end is 9:30 am'); | ||
t.end(); | ||
@@ -37,4 +41,4 @@ }); | ||
t.equals(results[0].start.get('minute'), 0, 'start is 11:00 am'); | ||
t.equals(results[0].end.get('hour'), 13, 'start is 1:00 pm'); | ||
t.equals(results[0].end.get('minute'), 0, 'start is 1:00 pm'); | ||
t.equals(results[0].end.get('hour'), 13, 'end is 1:00 pm'); | ||
t.equals(results[0].end.get('minute'), 0, 'end is 1:00 pm'); | ||
t.end(); | ||
@@ -64,2 +68,50 @@ }); | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('military format and date with a year', function (t) { | ||
var results = parser.parse('Aug 11 2017 1100-2030'); | ||
t.equals(results[0].start.get('day'), 11, 'day is the 11th'); | ||
t.equals(results[0].start.get('month'), 8, 'month is August'); | ||
t.equals(results[0].start.get('year'), 2017, 'year is 2017'); | ||
t.equals(results[0].start.get('hour'), 11, 'start is 11 am'); | ||
t.equals(results[0].start.get('minute'), 0, 'start is 11:00 am'); | ||
t.equals(results[0].end.get('hour'), 20, 'end is 8 pm'); | ||
t.equals(results[0].end.get('minute'), 30, 'end is 8:30 pm'); | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('military format with implied date', function (t) { | ||
var results = parser.parse('Yesterday 1100-2030'); | ||
var yesterday = (0, _moment2.default)().subtract(1, 'day'); | ||
t.equals(results[0].start.get('day'), yesterday.date(), 'day is yesterday'); | ||
// chrono-node starts month count at 1, add 1 to moment to match that convention | ||
t.equals(results[0].start.get('month'), yesterday.month() + 1, 'month is current month'); | ||
t.equals(results[0].start.get('year'), yesterday.year(), 'year is current year'); | ||
t.equals(results[0].start.get('hour'), 11, 'start is 11 am'); | ||
t.equals(results[0].start.get('minute'), 0, 'start is 11:00 am'); | ||
t.equals(results[0].end.get('hour'), 20, 'end is 8 pm'); | ||
t.equals(results[0].end.get('minute'), 30, 'end is 8:30 pm'); | ||
t.end(); | ||
}); | ||
(0, _tape2.default)('military format with mm/dd/yy date format and day span', function (t) { | ||
var results = parser.parse('01/01/17 2000-0230'); | ||
t.equals(results[0].start.get('day'), 1, 'start day is the 1st'); | ||
t.equals(results[0].end.get('day'), 2, 'end day is the 2nd'); | ||
t.equals(results[0].start.get('month'), 1, 'month is January'); | ||
t.equals(results[0].start.get('year'), 2017, 'year is 2017'); | ||
t.equals(results[0].start.get('hour'), 20, 'start is 8 pm'); | ||
t.equals(results[0].start.get('minute'), 0, 'start is 8:00 pm'); | ||
t.equals(results[0].end.get('hour'), 2, 'end is 2 am'); | ||
t.equals(results[0].end.get('minute'), 30, 'end is 2:30 am'); | ||
t.end(); | ||
}); |
{ | ||
"name": "tickbin-parser", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "parse strings into entries", | ||
@@ -19,6 +19,6 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"chrono-node": "^1.3.5", | ||
"duration": "^0.2.0", | ||
"chrono-node": "^1.2.3", | ||
"es6-error": "^4.1.1", | ||
"moment": "^2.13.0", | ||
"es6-error": "^4.0.0", | ||
"shortid": "^2.2.6" | ||
@@ -25,0 +25,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108326
26
1507
Updatedchrono-node@^1.3.5
Updatedes6-error@^4.1.1