chrono-node
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -10,3 +10,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"directories": { | ||
@@ -13,0 +13,0 @@ "source": "./src", |
@@ -9,6 +9,17 @@ /* | ||
var PATTERN = /(\W|^)((\,|\(|\()\s*)?((this|last|next)\s*)?(Sunday|Sun|Monday|Mon|Tuesday|Tues|Tue|Wednesday|Wed|Thursday|Thurs|Thur|Friday|Fri|Saturday|Sat)(\s*(\,|\)|\)))?(\W|$)/i; | ||
var PATTERN = new RegExp('(\\W|^)' + | ||
'(?:(?:\\,|\\(|\\()\\s*)?' + | ||
'(?:(this|last|next)\\s*)?' + | ||
'(Sunday|Sun|Monday|Mon|Tuesday|Tues|Tue|Wednesday|Wed|Thursday|Thurs|Thur|Friday|Fri|Saturday|Sat)' + | ||
'(?:\\s*(?:\\,|\\)|\\)))?' + | ||
'(?:\\s*(this|last|next)\\s*week)?' + | ||
'(?=\\W|$)', 'i'); | ||
var DAYS_OFFSET = { 'sunday': 0, 'sun': 0, 'monday': 1, 'mon': 1,'tuesday': 2, 'tues':2, 'tue':2, 'wednesday': 3, 'wed': 3, | ||
'thursday': 4, 'thurs':4, 'thur': 4, 'thu': 4,'friday': 5, 'fri': 5,'saturday': 6, 'sat': 6,} | ||
var PREFIX_GROUP = 2; | ||
var WEEKDAY_GROUP = 3; | ||
var POSTFIX_GROUP = 4; | ||
exports.Parser = function ENWeekdayParser() { | ||
@@ -22,3 +33,3 @@ Parser.call(this); | ||
var index = match.index + match[1].length; | ||
var text = match[0].substr(match[1].length, match[0].length - match[9].length - match[1].length); | ||
var text = match[0].substr(match[1].length, match[0].length - match[1].length); | ||
var result = new ParsedResult({ | ||
@@ -29,4 +40,4 @@ index: index, | ||
}); | ||
var dayOfWeek = match[6].toLowerCase(); | ||
var dayOfWeek = match[WEEKDAY_GROUP].toLowerCase(); | ||
var offset = DAYS_OFFSET[dayOfWeek]; | ||
@@ -36,14 +47,16 @@ if(offset === undefined) return null; | ||
var startMoment = moment(ref); | ||
var prefix = match[5]; | ||
if (prefix) { | ||
prefix = prefix.toLowerCase(); | ||
var prefix = match[PREFIX_GROUP]; | ||
var postfix = match[POSTFIX_GROUP]; | ||
if (prefix || postfix) { | ||
var norm = prefix || postfix; | ||
norm = norm.toLowerCase(); | ||
if(prefix == 'last') | ||
if(norm == 'last') | ||
startMoment.day(offset - 7) | ||
else if(prefix == 'next') | ||
else if(norm == 'next') | ||
startMoment.day(offset + 7) | ||
else if(prefix== 'this') | ||
else if(norm== 'this') | ||
startMoment.day(offset); | ||
} | ||
else{ | ||
} else{ | ||
var refOffset = startMoment.day(); | ||
@@ -50,0 +63,0 @@ |
@@ -90,3 +90,3 @@ var moment = require('moment'); | ||
// Javascript Date Object return minus timezone offset | ||
var currentTimezoneOffset = -new Date().getTimezoneOffset(); | ||
var currentTimezoneOffset = -dateMoment.zone(); | ||
var targetTimezoneOffset = this.isCertain('timezoneOffset') ? | ||
@@ -93,0 +93,0 @@ this.get('timezoneOffset') : currentTimezoneOffset; |
@@ -90,2 +90,44 @@ | ||
} | ||
var text = "Let's have a meeting on Friday next week"; | ||
var results = chrono.casual.parse(text, new Date(2015, 3, 18)); | ||
ok(results.length == 1, JSON.stringify( results ) ) | ||
var result = results[0]; | ||
if(result){ | ||
ok(result.index == 24, 'Wrong index') | ||
ok(result.text == 'Friday next week', result.text ) | ||
ok(result.start, JSON.stringify(result.start) ) | ||
ok(result.start.get('year') == 2015, 'Test Result - (Year) ' + JSON.stringify(result.start) ) | ||
ok(result.start.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.start) ) | ||
ok(result.start.get('day') == 24, 'Test Result - (Day) ' + JSON.stringify(result.start) ) | ||
ok(result.start.get('weekday') == 5, 'Test Result - (Weekday) ' + JSON.stringify(result.start) ) | ||
var resultDate = result.start.date(); | ||
var expectDate = new Date(2015, 3, 24, 12); | ||
ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate) | ||
} | ||
var text = "I plan on taking the day off on Tuesday, next week"; | ||
var results = chrono.casual.parse(text, new Date(2015, 3, 18)); | ||
ok(results.length == 1, JSON.stringify( results ) ) | ||
var result = results[0]; | ||
if(result){ | ||
ok(result.index == 32, 'Wrong index') | ||
ok(result.text == 'Tuesday, next week', result.text ) | ||
ok(result.start, JSON.stringify(result.start) ) | ||
ok(result.start.get('year') == 2015, 'Test Result - (Year) ' + JSON.stringify(result.start) ) | ||
ok(result.start.get('month') == 4, 'Test Result - (Month) ' + JSON.stringify(result.start) ) | ||
ok(result.start.get('day') == 21, 'Test Result - (Day) ' + JSON.stringify(result.start) ) | ||
ok(result.start.get('weekday') == 2, 'Test Result - (Weekday) ' + JSON.stringify(result.start) ) | ||
var resultDate = result.start.date(); | ||
var expectDate = new Date(2015, 3, 21, 12); | ||
ok(Math.abs(expectDate.getTime() - resultDate.getTime()) < 100000, 'Test result.startDate ' + resultDate +'/' +expectDate) | ||
} | ||
}); | ||
@@ -92,0 +134,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
2003558
22097