summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/node_modules/chrono-node/src/parsers/es/ESTimeAgoFormatParser.js
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/chrono-node/src/parsers/es/ESTimeAgoFormatParser.js')
-rw-r--r--bin/wiki/ImportarDesdeURL/node_modules/chrono-node/src/parsers/es/ESTimeAgoFormatParser.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/chrono-node/src/parsers/es/ESTimeAgoFormatParser.js b/bin/wiki/ImportarDesdeURL/node_modules/chrono-node/src/parsers/es/ESTimeAgoFormatParser.js
new file mode 100644
index 00000000..d78e9d76
--- /dev/null
+++ b/bin/wiki/ImportarDesdeURL/node_modules/chrono-node/src/parsers/es/ESTimeAgoFormatParser.js
@@ -0,0 +1,92 @@
+/*
+
+
+*/
+
+var moment = require('moment');
+var Parser = require('../parser').Parser;
+var ParsedResult = require('../../result').ParsedResult;
+
+var PATTERN = /(\W|^)hace\s*([0-9]+|medi[oa]|una?)\s*(minutos?|horas?|semanas?|d[ií]as?|mes(es)?|años?)(?=(?:\W|$))/i;
+
+exports.Parser = function ESTimeAgoFormatParser(){
+ Parser.apply(this, arguments);
+
+ this.pattern = function() {
+ return PATTERN;
+ }
+
+ this.extract = function(text, ref, match, opt){
+
+ if (match.index > 0 && text[match.index-1].match(/\w/)) return null;
+
+ var text = match[0];
+ text = match[0].substr(match[1].length, match[0].length - match[1].length);
+ index = match.index + match[1].length;
+
+ var result = new ParsedResult({
+ index: index,
+ text: text,
+ ref: ref,
+ });
+
+ var num = parseInt(match[2]);
+ if (isNaN(num)) {
+ if (match[2].match(/medi/)) {
+ num = 0.5;
+ } else {
+ num = 1;
+ }
+ }
+
+ var date = moment(ref);
+
+ if (match[3].match(/hora/) || match[3].match(/minuto/)) {
+ if (match[3].match(/hora/)) {
+
+ date.add(-num, 'hour');
+
+ } else if (match[3].match(/minuto/)) {
+
+ date.add(-num, 'minute');
+ }
+
+ result.start.imply('day', date.date());
+ result.start.imply('month', date.month() + 1);
+ result.start.imply('year', date.year());
+ result.start.assign('hour', date.hour());
+ result.start.assign('minute', date.minute());
+ result.tags['ESTimeAgoFormatParser'] = true;
+ return result;
+ }
+
+ if (match[3].match(/semana/)) {
+ date.add(-num, 'week');
+
+ result.start.imply('day', date.date());
+ result.start.imply('month', date.month() + 1);
+ result.start.imply('year', date.year());
+ result.start.imply('weekday', date.day());
+ return result;
+ }
+
+ if (match[3].match(/d[ií]a/)) {
+ date.add(-num, 'd');
+ }
+
+ if (match[3].match(/mes/)) {
+ date.add(-num, 'month');
+ }
+
+ if (match[3].match(/año/)) {
+
+ date.add(-num, 'year');
+ }
+
+ result.start.assign('day', date.date());
+ result.start.assign('month', date.month() + 1);
+ result.start.assign('year', date.year());
+ return result;
+
+ };
+}