Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

date-parser

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date-parser - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

30

lib/zh-TW.js

@@ -183,16 +183,16 @@ // Generated by CoffeeScript 1.8.0

if (period.match(RegExp(words.morning))) {
date.setUTCHours(9 + timezone);
date.endTime.setUTCHours(11 + timezone);
date.setUTCHours(9 - timezone);
date.endTime.setUTCHours(11 - timezone);
} else if (period.match(RegExp(words.noon))) {
date.setUTCHours(12 + timezone);
date.endTime.setUTCHours(13 + timezone);
date.setUTCHours(12 - timezone);
date.endTime.setUTCHours(13 - timezone);
} else if (period.match(RegExp(words.afternoon))) {
date.setUTCHours(14 + timezone);
date.endTime.setUTCHours(16 + timezone);
date.setUTCHours(14 - timezone);
date.endTime.setUTCHours(16 - timezone);
} else if (period.match(RegExp(words.night))) {
date.setUTCHours(18 + timezone);
date.endTime.setUTCHours(20 + timezone);
date.setUTCHours(18 - timezone);
date.endTime.setUTCHours(20 - timezone);
} else if (period.match(RegExp(words.midnight))) {
date.setUTCHours(0 + timezone);
date.endTime.setUTCHours(4 + timezone);
date.setUTCHours(0 - timezone);
date.endTime.setUTCHours(4 - timezone);
}

@@ -211,7 +211,7 @@ return date;

if (time.hour < 12 && !period) {
if (time.hour > (date.getUTCHours() + timezone - 12) && time.hour < (date.getUTCHours() + timezone)) {
if (time.hour > (date.getUTCHours() - timezone - 12) && time.hour < (date.getUTCHours() - timezone)) {
time.hour += 12;
}
}
date.setUTCHours(time.hour + timezone);
date.setUTCHours(time.hour - timezone);
date.setMinutes(time.minute || 0);

@@ -271,3 +271,3 @@ date.setSeconds(time.second || 0);

date = new Date();
date.setUTCHours(0 + timezone);
date.setUTCHours(0 - timezone);
date.setMinutes(0);

@@ -377,3 +377,3 @@ date.setSeconds(0);

if (date.endTime && !match[5]) {
date.endTime.setUTCHours(23 + timezone);
date.endTime.setUTCHours(23 - timezone);
date.endTime.setMinutes(59);

@@ -457,3 +457,3 @@ date.endTime.setSeconds(59);

if (date.endTime && !match[5]) {
date.endTime.setUTCHours(23 + timezone);
date.endTime.setUTCHours(23 - timezone);
date.endTime.setMinutes(59);

@@ -460,0 +460,0 @@ date.endTime.setSeconds(59);

{
"name": "date-parser",
"version": "0.0.4",
"version": "0.0.5",
"description": "將口語的日期時間解析成 Date 物件。",

@@ -5,0 +5,0 @@ "main": "date-parser.js",

@@ -1,1 +0,1 @@

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){(function(){if(window){window.dateParser=require("./date-parser")}}).call(this)},{"./date-parser":2}],2:[function(require,module,exports){(function(){var DateParser;DateParser={LOCALES:{"zh-TW":require("./lib/zh-TW")},DEFAULT_LOCALE:"zh-TW",DEFAULT_TIMEZONE:+8,locale:function(locale){var _ref;if(this.LOCALES[locale]){this.DEFAULT_LOCALE=locale;return(_ref=this.LOCALES[locale].testStrings)!=null?_ref.forEach(function(_this){return function(s){return _this.parse(s)}}(this)):void 0}else{return console.error("No such locale: "+locale)}},timezone:function(timezone){var DEFAULT_TIMEZONE;return DEFAULT_TIMEZONE=parseInt(timezone)},parse:function(text,timezone,locale){var error,expression,expressions,result,_i,_len,_ref,_ref1;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}if(timezone===void 0){timezone=this.DEFAULT_TIMEZONE}expressions=(_ref=this.LOCALES[locale])!=null?_ref.expressions:void 0;if(!expressions){console.error("No such locale: "+locale);return null}_ref1=this.LOCALES[locale].expressions;for(_i=0,_len=_ref1.length;_i<_len;_i++){expression=_ref1[_i];try{result=expression(text,timezone);if(result){return result}}catch(_error){error=_error;console.error("error",error)}}return null},number2integer:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.number2integer==="function"?_ref.number2integer(text):void 0:void 0},time2object:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.time2object==="function"?_ref.time2object(text):void 0:void 0},dayTime2date:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.dayTime2date==="function"?_ref.dayTime2date(text):void 0:void 0},date2object:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.date2object==="function"?_ref.date2object(text):void 0:void 0},dateExpression2date:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.dateExpression2date==="function"?_ref.dateExpression2date(text):void 0:void 0}};DateParser.locale("zh-TW");module.exports=DateParser}).call(this)},{"./lib/zh-TW":3}],3:[function(require,module,exports){(function(){var date2object,dateExpression2date,dayTime2date,expressions,number2integer,time2object,words;words={at:"(?:在|於|@|要在)",zero:"(?:零|0|0)",one:"(?:一|1|1)",two:"(?:二|兩|2|2)",three:"(?:三|3|3)",four:"(?:四|4|4)",five:"(?:五|5|5)",six:"(?:六|6|6)",seven:"(?:七|7|7)",sun:"(?:日|天)",eight:"(?:八|8|8)",nine:"(?:九|9|9)",ten:"十",half:"半",end:"末",dot:"(?:.|點|:|:)",hour:"(?:時|小時|點|:|:)",minute:"(?:分|分鐘|:|:)",second:"秒",morning:"(?:早|早上|早晨|am|AM)",noon:"(?:中午)",afternoon:"(?:下午|午後|pm|PM)",night:"(?:晚|晚上|晚間|夜晚|夜間)",midnight:"(?:午夜|半夜|凌晨)",after:"後",today:"(?:今|今天|今日)",tomorrow:"(?:明|明天|明日)",acquired:"(?:後天|後日)",yesterday:"(?:昨天|昨日)",the_day_before_yesterday:"(?:前天|前日)","this":"(?:這|這個|今)",next:"(?:下|下個|明)",previous:"(?:上|上個|去|昨)",week:"(?:禮拜|星期|週|周)",year:"(?:年|/|-)",year_relative:"(?:今年|去年|明年)",month:"(?:月|/|-)",month_relative:"(?:這個月|上個月|下個月)",day:"(?:日|號|/|-)",to:"(?:到|-|-|~)",event_prefix:"(?:有|舉辦|舉行|要|的|,| )",event_postfix:"(?:在|,| )",interjection:"(?:個|的|,| )",unit:"(?:個)"};words.numbers="(?:"+words.zero+"|"+words.one+"|"+words.two+"|"+words.three+"|"+words.four+"|"+words.five+"|"+words.six+"|"+words.seven+"|"+words.eight+"|"+words.nine+"|"+words.ten+"|"+words.half+"|"+words.unit+")";words.zero_to_nine="(?:"+words.zero+"|"+words.one+"|"+words.two+"|"+words.three+"|"+words.four+"|"+words.five+"|"+words.six+"|"+words.seven+"|"+words.eight+"|"+words.nine+")";words.am="(?:"+words.midnight+"|"+words.morning+")";words.pm="(?:"+words.noon+"|"+words.afternoon+"|"+words.night+")";words.this_previous_next="(?:"+words["this"]+"|"+words.previous+"|"+words.next+")";words.dayPeriods="(?:"+words.morning+"|"+words.noon+"|"+words.afternoon+"|"+words.night+"|"+words.midnight+")";words.time="(?:"+words.numbers+"+"+words.hour+"(?:"+words.numbers+"+)?(?:"+words.minute+")?(?:"+words.numbers+"+)?(?:"+words.second+")?)";words.like_time="(?:"+words.numbers+"+(?:"+words.numbers+"|"+words.hour+"|"+words.minute+"|"+words.second+"){1,12})";words.dayTime="(?:(?:"+words.dayPeriods+"?"+words.interjection+"?"+words.like_time+") ?"+words.dayPeriods+"?|"+words.dayPeriods+")";words.year_month_day="(?:"+words.year+"|"+words.month+"|"+words.day+"|"+words.year_relative+"|"+words.month_relative+")";words.date="(?:(?:(?:(?:"+words.numbers+"{1,4}|"+words.this_previous_next+") ?"+words.year+")? ?(?:"+words.numbers+"{1,3}|"+words.this_previous_next+") ?"+words.month+")? ?"+words.numbers+"{1,3} ?"+words.day+"?)";words.like_date="(?:(?:"+words.numbers+"|"+words.year_month_day+"){1,12}"+words.year_month_day+words.numbers+"{0,3})";words.weekdays="(?:"+words.zero+"|"+words.one+"|"+words.two+"|"+words.three+"|"+words.four+"|"+words.five+"|"+words.six+"|"+words.seven+"|"+words.sun+"|"+words.end+")";words.weekExpression="(?:"+words.this_previous_next+"?"+words.week+words.weekdays+")";words.dateExpression="(?:"+words.like_date+"|"+words.weekExpression+"|"+words.today+"|"+words.tomorrow+"|"+words.acquired+"|"+words.yesterday+"|"+words.the_day_before_yesterday+")";words.separators="(?:"+words.event_prefix+"|"+words.event_postfix+")";number2integer=function(number){var match,n;if(!number){return null}if(match=number.match(RegExp("("+words.zero_to_nine+")("+words.zero_to_nine+")("+words.zero_to_nine+")("+words.zero_to_nine+")"))){return number2integer(match[1])*1e3+number2integer(match[2])*100+number2integer(match[3])*10+number2integer(match[4])}else if(match=number.match(RegExp("("+words.zero_to_nine+")("+words.ten+")?("+words.zero_to_nine+")"+words.unit+"?"))){if(match[1]===words.ten){return number2integer(match[3])+10}else{n=number2integer(match[3]);if(n>=10){n=0}return number2integer(match[1])*10+n}}else if(match=number.match(RegExp("("+words.numbers+"+)"+words.unit+words.half))){return number2integer(match[1])+.5}else if(number.match(RegExp(words.half))){return.5}else if(number.match(RegExp(words.zero))){return 0}else if(number.match(RegExp(words.one))){return 1}else if(number.match(RegExp(words.two))){return 2}else if(number.match(RegExp(words.three))){return 3}else if(number.match(RegExp(words.four))){return 4}else if(number.match(RegExp(words.five))){return 5}else if(number.match(RegExp(words.six))){return 6}else if(number.match(RegExp(words.seven))){return 7}else if(number.match(RegExp(words.sun))){return 7}else if(number.match(RegExp(words.eight))){return 8}else if(number.match(RegExp(words.nine))){return 9}else if(number.match(RegExp(words.ten))){return 10}else{return null}};time2object=function(time){var f,hour,match,minute,second;if(!time){return null}if(match=time.match(RegExp("(?:("+words.numbers+"+)"+words.hour+"("+words.numbers+"*)(?:"+words.minute+")?("+words.numbers+"*)(?:"+words.second+")?)"))){hour=number2integer(match[1])||0;minute=number2integer(match[2])||0;second=number2integer(match[3])||0;if(hour===30){hour=0;minute+=30}if((f=hour%1)>0){hour-=f;minute+=30}while(second>60){second-=60;minute+=1}while(minute>60){minute-=60;hour+=1}return{hour:hour,minute:minute,second:second}}else{return null}};dayTime2date=function(daytime,timezone,date){var match,period,time;if(!daytime){return null}if(match=daytime.match(RegExp("(?:(?:("+words.dayPeriods+")?"+words.interjection+"?("+words.time+") ?("+words.dayPeriods+")?)|("+words.dayPeriods+"))"))){if(period=match[4]){date=date||new Date;date.endTime=(date!=null?date.endTime:void 0)||date&&new Date(date!=null?date.getTime():void 0)||new Date;date.setMinutes(0);date.setSeconds(0);date.endTime.setMinutes(0);date.endTime.setSeconds(0);if(period.match(RegExp(words.morning))){date.setUTCHours(9+timezone);date.endTime.setUTCHours(11+timezone)}else if(period.match(RegExp(words.noon))){date.setUTCHours(12+timezone);date.endTime.setUTCHours(13+timezone)}else if(period.match(RegExp(words.afternoon))){date.setUTCHours(14+timezone);date.endTime.setUTCHours(16+timezone)}else if(period.match(RegExp(words.night))){date.setUTCHours(18+timezone);date.endTime.setUTCHours(20+timezone)}else if(period.match(RegExp(words.midnight))){date.setUTCHours(0+timezone);date.endTime.setUTCHours(4+timezone)}return date}else{period=match[1]||match[3]||"";time=time2object(match[2]);if(!time){return null}if(period.match(RegExp(words.pm))&&time.hour<12){time.hour+=12}date=date&&new Date(date!=null?date.getTime():void 0)||new Date;if(time.hour<12&&!period){if(time.hour>date.getUTCHours()+timezone-12&&time.hour<date.getUTCHours()+timezone){time.hour+=12}}date.setUTCHours(time.hour+timezone);date.setMinutes(time.minute||0);date.setSeconds(time.second||0);return date}}else{return null}};date2object=function(date){var c,day,match,month,now,year,_ref,_ref1,_ref2,_ref3,_ref4,_ref5;if(!date){return null}if(match=date.match(RegExp("(?:(?:(?:("+words.numbers+"+|"+words.this_previous_next+") ?"+words.year+")? ?("+words.numbers+"+||"+words.interjection+words.this_previous_next+") ?"+words.month+")? ?(?:("+words.numbers+"+) ?"+words.day+"?))"))){now=new Date;year=number2integer(match[1])||null;if(year&&year<100){now.getUTCFullYear();c=parseInt(now.getUTCFullYear()/100)*100;year=year+c}month=number2integer(match[2])||null;day=number2integer(match[3])||null;if((_ref=match[1])!=null?_ref.match(RegExp(words["this"])):void 0){year=now.getUTCFullYear()}else if((_ref1=match[1])!=null?_ref1.match(RegExp(words.previous)):void 0){year=now.getUTCFullYear()-1}else if((_ref2=match[1])!=null?_ref2.match(RegExp(words.next)):void 0){year=now.getUTCFullYear()+1}if((_ref3=match[2])!=null?_ref3.match(RegExp(words["this"])):void 0){year=now.getMonth()+1}else if((_ref4=match[2])!=null?_ref4.match(RegExp(words.previous)):void 0){year=now.getMonth()}else if((_ref5=match[2])!=null?_ref5.match(RegExp(words.next)):void 0){year=now.getMonth()+2}return{year:year,month:month,day:day}}else{return null}};dateExpression2date=function(dateExp,timezone){var date,day,diff,match,theDate,_ref,_ref1;if(!dateExp){return null}date=new Date;date.setUTCHours(0+timezone);date.setMinutes(0);date.setSeconds(0);if(match=dateExp.match(RegExp(words.today))){return date}else if(match=dateExp.match(RegExp(words.tomorrow))){date.setDate(date.getDate()+1);return date}else if(match=dateExp.match(RegExp(words.acquired))){date.setDate(date.getDate()+2);return date}else if(match=dateExp.match(RegExp(words.yesterday))){date.setDate(date.getDate()-1);return date}else if(match=dateExp.match(RegExp(words.the_day_before_yesterday))){date.setDate(date.getDate()-2);return date}else if(match=dateExp.match(RegExp("("+words.this_previous_next+")?"+words.week+"("+words.weekdays+")"))){if((_ref=match[1])!=null?_ref.match(RegExp(words.previous)):void 0){date.setDate(date.getDate()-7)}else if((_ref1=match[1])!=null?_ref1.match(RegExp(words.next)):void 0){date.setDate(date.getDate()+7)}day=number2integer(match[2]);if(match[2].match(RegExp(words.end))){day=6}if(day>=7){day=0}diff=day-date.getDay();date.setDate(date.getDate()+diff);if(match[2].match(RegExp(words.end))){date.endTime=new Date(date!=null?date.getTime():void 0);date.endTime.setDate(date.getDate()+1)}return date}else if(match=dateExp.match(RegExp(words.like_date))){theDate=date2object(match[0]);if(!theDate){return null}if(theDate.day){date.setDate(theDate.day)}if(theDate.month){date.setMonth(theDate.month-1)}if(theDate.year){date.setYear(theDate.year)}return date}else{return null}};expressions=[];expressions.push(function(text,timezone){var date,eventName,location,match,time;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+" ?)?("+words.time+")"+words.after+" ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){time=time2object(match[2]);location=match[3];eventName=match[1]||match[4];date=new Date;date.setHours(date.getHours()+time.hour);date.setMinutes(date.getMinutes()+time.minute);date.setSeconds(date.getSeconds()+time.second);if(location){date.location=location}if(eventName){date.eventName=eventName}return date}});expressions.push(function(text,timezone){var date,endTime,eventName,location,match;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+")? ?("+words.dateExpression+") ?("+words.dayTime+")? ?(?:"+words.to+" ?("+words.dateExpression+") ?("+words.dayTime+")? ?) ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){date=dateExpression2date(match[2],timezone)||new Date;if(match[3]){date=dayTime2date(match[3],timezone,date)}if(!match[3]&&!match[5]){date.fullDay=true}endTime=dateExpression2date(match[4],timezone);if(match[5]&&endTime){endTime=dayTime2date(match[5],timezone,endTime)}location=match[6];eventName=match[1]||match[7];if(location){date.location=location}if(eventName){date.eventName=eventName}if(endTime){date.endTime=endTime}if(date.endTime&&!match[5]){date.endTime.setUTCHours(23+timezone);date.endTime.setMinutes(59);date.endTime.setSeconds(59)}return date}});expressions.push(function(text,timezone){var date,endTime,eventName,location,match;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+")? ?(?:("+words.dateExpression+")) ?("+words.dayTime+") ?(?:"+words.to+" ?("+words.dayTime+") ?)? ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){date=dateExpression2date(match[2],timezone)||new Date;if(match[3]){date=dayTime2date(match[3],timezone,date)}endTime=dayTime2date(match[4],timezone,date);location=match[5];eventName=match[1]||match[6];if(location){date.location=location}if(eventName){date.eventName=eventName}if(endTime){date.endTime=endTime}return date}});expressions.push(function(text,timezone){var date,endTime,eventName,location,match;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+")? ?("+words.dayTime+") ?(?:"+words.to+" ?("+words.dayTime+") ?)? ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){if(match[2]){date=dayTime2date(match[2],timezone)}endTime=dayTime2date(match[3],timezone,date);location=match[4];eventName=match[1]||match[5];if(location){date.location=location}if(eventName){date.eventName=eventName}if(endTime){date.endTime=endTime}return date}});expressions.push(function(text,timezone){var date,endTime,eventName,location,match,time;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+")? ?("+words.dateExpression+") ?("+words.dayTime+")? ?(?:"+words.to+" ? ("+words.dateExpression+") ?("+words.dayTime+")? ?)? ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){date=dateExpression2date(match[2],timezone)||new Date;if(match[3]){time=dayTime2date(match[3],timezone,date)}if(!match[3]&&!match[5]){date.fullDay=true}endTime=dateExpression2date(match[5],timezone);if(match[5]&&endTime){endTime=dayTime2date(match[5],timezone,endTime)}location=match[6];eventName=match[1]||match[7];if(location){date.location=location}if(eventName){date.eventName=eventName}if(endTime){date.endTime=endTime}if(date.endTime&&!match[5]){date.endTime.setUTCHours(23+timezone);date.endTime.setMinutes(59);date.endTime.setSeconds(59)}return date}});module.exports={words:words,expressions:expressions,number2integer:number2integer,time2object:time2object,dayTime2date:dayTime2date,date2object:date2object,dateExpression2date:dateExpression2date,testStrings:["明天晚上到下禮拜六早上要開會","10月10號 早上 10:00 ~ 下午 4:00","十月十號"]}}).call(this)},{}]},{},[1]);
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){(function(){if(window){window.dateParser=require("./date-parser")}}).call(this)},{"./date-parser":2}],2:[function(require,module,exports){(function(){var DateParser;DateParser={LOCALES:{"zh-TW":require("./lib/zh-TW")},DEFAULT_LOCALE:"zh-TW",DEFAULT_TIMEZONE:+8,locale:function(locale){var _ref;if(this.LOCALES[locale]){this.DEFAULT_LOCALE=locale;return(_ref=this.LOCALES[locale].testStrings)!=null?_ref.forEach(function(_this){return function(s){return _this.parse(s)}}(this)):void 0}else{return console.error("No such locale: "+locale)}},timezone:function(timezone){var DEFAULT_TIMEZONE;return DEFAULT_TIMEZONE=parseInt(timezone)},parse:function(text,timezone,locale){var error,expression,expressions,result,_i,_len,_ref,_ref1;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}if(timezone===void 0){timezone=this.DEFAULT_TIMEZONE}expressions=(_ref=this.LOCALES[locale])!=null?_ref.expressions:void 0;if(!expressions){console.error("No such locale: "+locale);return null}_ref1=this.LOCALES[locale].expressions;for(_i=0,_len=_ref1.length;_i<_len;_i++){expression=_ref1[_i];try{result=expression(text,timezone);if(result){return result}}catch(_error){error=_error;console.error("error",error)}}return null},number2integer:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.number2integer==="function"?_ref.number2integer(text):void 0:void 0},time2object:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.time2object==="function"?_ref.time2object(text):void 0:void 0},dayTime2date:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.dayTime2date==="function"?_ref.dayTime2date(text):void 0:void 0},date2object:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.date2object==="function"?_ref.date2object(text):void 0:void 0},dateExpression2date:function(text,locale){var _ref;if(!text){text=""}if(!locale){locale=this.DEFAULT_LOCALE}return(_ref=this.LOCALES[locale])!=null?typeof _ref.dateExpression2date==="function"?_ref.dateExpression2date(text):void 0:void 0}};DateParser.locale("zh-TW");module.exports=DateParser}).call(this)},{"./lib/zh-TW":3}],3:[function(require,module,exports){(function(){var date2object,dateExpression2date,dayTime2date,expressions,number2integer,time2object,words;words={at:"(?:在|於|@|要在)",zero:"(?:零|0|0)",one:"(?:一|1|1)",two:"(?:二|兩|2|2)",three:"(?:三|3|3)",four:"(?:四|4|4)",five:"(?:五|5|5)",six:"(?:六|6|6)",seven:"(?:七|7|7)",sun:"(?:日|天)",eight:"(?:八|8|8)",nine:"(?:九|9|9)",ten:"十",half:"半",end:"末",dot:"(?:.|點|:|:)",hour:"(?:時|小時|點|:|:)",minute:"(?:分|分鐘|:|:)",second:"秒",morning:"(?:早|早上|早晨|am|AM)",noon:"(?:中午)",afternoon:"(?:下午|午後|pm|PM)",night:"(?:晚|晚上|晚間|夜晚|夜間)",midnight:"(?:午夜|半夜|凌晨)",after:"後",today:"(?:今|今天|今日)",tomorrow:"(?:明|明天|明日)",acquired:"(?:後天|後日)",yesterday:"(?:昨天|昨日)",the_day_before_yesterday:"(?:前天|前日)","this":"(?:這|這個|今)",next:"(?:下|下個|明)",previous:"(?:上|上個|去|昨)",week:"(?:禮拜|星期|週|周)",year:"(?:年|/|-)",year_relative:"(?:今年|去年|明年)",month:"(?:月|/|-)",month_relative:"(?:這個月|上個月|下個月)",day:"(?:日|號|/|-)",to:"(?:到|-|-|~)",event_prefix:"(?:有|舉辦|舉行|要|的|,| )",event_postfix:"(?:在|,| )",interjection:"(?:個|的|,| )",unit:"(?:個)"};words.numbers="(?:"+words.zero+"|"+words.one+"|"+words.two+"|"+words.three+"|"+words.four+"|"+words.five+"|"+words.six+"|"+words.seven+"|"+words.eight+"|"+words.nine+"|"+words.ten+"|"+words.half+"|"+words.unit+")";words.zero_to_nine="(?:"+words.zero+"|"+words.one+"|"+words.two+"|"+words.three+"|"+words.four+"|"+words.five+"|"+words.six+"|"+words.seven+"|"+words.eight+"|"+words.nine+")";words.am="(?:"+words.midnight+"|"+words.morning+")";words.pm="(?:"+words.noon+"|"+words.afternoon+"|"+words.night+")";words.this_previous_next="(?:"+words["this"]+"|"+words.previous+"|"+words.next+")";words.dayPeriods="(?:"+words.morning+"|"+words.noon+"|"+words.afternoon+"|"+words.night+"|"+words.midnight+")";words.time="(?:"+words.numbers+"+"+words.hour+"(?:"+words.numbers+"+)?(?:"+words.minute+")?(?:"+words.numbers+"+)?(?:"+words.second+")?)";words.like_time="(?:"+words.numbers+"+(?:"+words.numbers+"|"+words.hour+"|"+words.minute+"|"+words.second+"){1,12})";words.dayTime="(?:(?:"+words.dayPeriods+"?"+words.interjection+"?"+words.like_time+") ?"+words.dayPeriods+"?|"+words.dayPeriods+")";words.year_month_day="(?:"+words.year+"|"+words.month+"|"+words.day+"|"+words.year_relative+"|"+words.month_relative+")";words.date="(?:(?:(?:(?:"+words.numbers+"{1,4}|"+words.this_previous_next+") ?"+words.year+")? ?(?:"+words.numbers+"{1,3}|"+words.this_previous_next+") ?"+words.month+")? ?"+words.numbers+"{1,3} ?"+words.day+"?)";words.like_date="(?:(?:"+words.numbers+"|"+words.year_month_day+"){1,12}"+words.year_month_day+words.numbers+"{0,3})";words.weekdays="(?:"+words.zero+"|"+words.one+"|"+words.two+"|"+words.three+"|"+words.four+"|"+words.five+"|"+words.six+"|"+words.seven+"|"+words.sun+"|"+words.end+")";words.weekExpression="(?:"+words.this_previous_next+"?"+words.week+words.weekdays+")";words.dateExpression="(?:"+words.like_date+"|"+words.weekExpression+"|"+words.today+"|"+words.tomorrow+"|"+words.acquired+"|"+words.yesterday+"|"+words.the_day_before_yesterday+")";words.separators="(?:"+words.event_prefix+"|"+words.event_postfix+")";number2integer=function(number){var match,n;if(!number){return null}if(match=number.match(RegExp("("+words.zero_to_nine+")("+words.zero_to_nine+")("+words.zero_to_nine+")("+words.zero_to_nine+")"))){return number2integer(match[1])*1e3+number2integer(match[2])*100+number2integer(match[3])*10+number2integer(match[4])}else if(match=number.match(RegExp("("+words.zero_to_nine+")("+words.ten+")?("+words.zero_to_nine+")"+words.unit+"?"))){if(match[1]===words.ten){return number2integer(match[3])+10}else{n=number2integer(match[3]);if(n>=10){n=0}return number2integer(match[1])*10+n}}else if(match=number.match(RegExp("("+words.numbers+"+)"+words.unit+words.half))){return number2integer(match[1])+.5}else if(number.match(RegExp(words.half))){return.5}else if(number.match(RegExp(words.zero))){return 0}else if(number.match(RegExp(words.one))){return 1}else if(number.match(RegExp(words.two))){return 2}else if(number.match(RegExp(words.three))){return 3}else if(number.match(RegExp(words.four))){return 4}else if(number.match(RegExp(words.five))){return 5}else if(number.match(RegExp(words.six))){return 6}else if(number.match(RegExp(words.seven))){return 7}else if(number.match(RegExp(words.sun))){return 7}else if(number.match(RegExp(words.eight))){return 8}else if(number.match(RegExp(words.nine))){return 9}else if(number.match(RegExp(words.ten))){return 10}else{return null}};time2object=function(time){var f,hour,match,minute,second;if(!time){return null}if(match=time.match(RegExp("(?:("+words.numbers+"+)"+words.hour+"("+words.numbers+"*)(?:"+words.minute+")?("+words.numbers+"*)(?:"+words.second+")?)"))){hour=number2integer(match[1])||0;minute=number2integer(match[2])||0;second=number2integer(match[3])||0;if(hour===30){hour=0;minute+=30}if((f=hour%1)>0){hour-=f;minute+=30}while(second>60){second-=60;minute+=1}while(minute>60){minute-=60;hour+=1}return{hour:hour,minute:minute,second:second}}else{return null}};dayTime2date=function(daytime,timezone,date){var match,period,time;if(!daytime){return null}if(match=daytime.match(RegExp("(?:(?:("+words.dayPeriods+")?"+words.interjection+"?("+words.time+") ?("+words.dayPeriods+")?)|("+words.dayPeriods+"))"))){if(period=match[4]){date=date||new Date;date.endTime=(date!=null?date.endTime:void 0)||date&&new Date(date!=null?date.getTime():void 0)||new Date;date.setMinutes(0);date.setSeconds(0);date.endTime.setMinutes(0);date.endTime.setSeconds(0);if(period.match(RegExp(words.morning))){date.setUTCHours(9-timezone);date.endTime.setUTCHours(11-timezone)}else if(period.match(RegExp(words.noon))){date.setUTCHours(12-timezone);date.endTime.setUTCHours(13-timezone)}else if(period.match(RegExp(words.afternoon))){date.setUTCHours(14-timezone);date.endTime.setUTCHours(16-timezone)}else if(period.match(RegExp(words.night))){date.setUTCHours(18-timezone);date.endTime.setUTCHours(20-timezone)}else if(period.match(RegExp(words.midnight))){date.setUTCHours(0-timezone);date.endTime.setUTCHours(4-timezone)}return date}else{period=match[1]||match[3]||"";time=time2object(match[2]);if(!time){return null}if(period.match(RegExp(words.pm))&&time.hour<12){time.hour+=12}date=date&&new Date(date!=null?date.getTime():void 0)||new Date;if(time.hour<12&&!period){if(time.hour>date.getUTCHours()-timezone-12&&time.hour<date.getUTCHours()-timezone){time.hour+=12}}date.setUTCHours(time.hour-timezone);date.setMinutes(time.minute||0);date.setSeconds(time.second||0);return date}}else{return null}};date2object=function(date){var c,day,match,month,now,year,_ref,_ref1,_ref2,_ref3,_ref4,_ref5;if(!date){return null}if(match=date.match(RegExp("(?:(?:(?:("+words.numbers+"+|"+words.this_previous_next+") ?"+words.year+")? ?("+words.numbers+"+||"+words.interjection+words.this_previous_next+") ?"+words.month+")? ?(?:("+words.numbers+"+) ?"+words.day+"?))"))){now=new Date;year=number2integer(match[1])||null;if(year&&year<100){now.getUTCFullYear();c=parseInt(now.getUTCFullYear()/100)*100;year=year+c}month=number2integer(match[2])||null;day=number2integer(match[3])||null;if((_ref=match[1])!=null?_ref.match(RegExp(words["this"])):void 0){year=now.getUTCFullYear()}else if((_ref1=match[1])!=null?_ref1.match(RegExp(words.previous)):void 0){year=now.getUTCFullYear()-1}else if((_ref2=match[1])!=null?_ref2.match(RegExp(words.next)):void 0){year=now.getUTCFullYear()+1}if((_ref3=match[2])!=null?_ref3.match(RegExp(words["this"])):void 0){year=now.getMonth()+1}else if((_ref4=match[2])!=null?_ref4.match(RegExp(words.previous)):void 0){year=now.getMonth()}else if((_ref5=match[2])!=null?_ref5.match(RegExp(words.next)):void 0){year=now.getMonth()+2}return{year:year,month:month,day:day}}else{return null}};dateExpression2date=function(dateExp,timezone){var date,day,diff,match,theDate,_ref,_ref1;if(!dateExp){return null}date=new Date;date.setUTCHours(0-timezone);date.setMinutes(0);date.setSeconds(0);if(match=dateExp.match(RegExp(words.today))){return date}else if(match=dateExp.match(RegExp(words.tomorrow))){date.setDate(date.getDate()+1);return date}else if(match=dateExp.match(RegExp(words.acquired))){date.setDate(date.getDate()+2);return date}else if(match=dateExp.match(RegExp(words.yesterday))){date.setDate(date.getDate()-1);return date}else if(match=dateExp.match(RegExp(words.the_day_before_yesterday))){date.setDate(date.getDate()-2);return date}else if(match=dateExp.match(RegExp("("+words.this_previous_next+")?"+words.week+"("+words.weekdays+")"))){if((_ref=match[1])!=null?_ref.match(RegExp(words.previous)):void 0){date.setDate(date.getDate()-7)}else if((_ref1=match[1])!=null?_ref1.match(RegExp(words.next)):void 0){date.setDate(date.getDate()+7)}day=number2integer(match[2]);if(match[2].match(RegExp(words.end))){day=6}if(day>=7){day=0}diff=day-date.getDay();date.setDate(date.getDate()+diff);if(match[2].match(RegExp(words.end))){date.endTime=new Date(date!=null?date.getTime():void 0);date.endTime.setDate(date.getDate()+1)}return date}else if(match=dateExp.match(RegExp(words.like_date))){theDate=date2object(match[0]);if(!theDate){return null}if(theDate.day){date.setDate(theDate.day)}if(theDate.month){date.setMonth(theDate.month-1)}if(theDate.year){date.setYear(theDate.year)}return date}else{return null}};expressions=[];expressions.push(function(text,timezone){var date,eventName,location,match,time;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+" ?)?("+words.time+")"+words.after+" ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){time=time2object(match[2]);location=match[3];eventName=match[1]||match[4];date=new Date;date.setHours(date.getHours()+time.hour);date.setMinutes(date.getMinutes()+time.minute);date.setSeconds(date.getSeconds()+time.second);if(location){date.location=location}if(eventName){date.eventName=eventName}return date}});expressions.push(function(text,timezone){var date,endTime,eventName,location,match;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+")? ?("+words.dateExpression+") ?("+words.dayTime+")? ?(?:"+words.to+" ?("+words.dateExpression+") ?("+words.dayTime+")? ?) ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){date=dateExpression2date(match[2],timezone)||new Date;if(match[3]){date=dayTime2date(match[3],timezone,date)}if(!match[3]&&!match[5]){date.fullDay=true}endTime=dateExpression2date(match[4],timezone);if(match[5]&&endTime){endTime=dayTime2date(match[5],timezone,endTime)}location=match[6];eventName=match[1]||match[7];if(location){date.location=location}if(eventName){date.eventName=eventName}if(endTime){date.endTime=endTime}if(date.endTime&&!match[5]){date.endTime.setUTCHours(23-timezone);date.endTime.setMinutes(59);date.endTime.setSeconds(59)}return date}});expressions.push(function(text,timezone){var date,endTime,eventName,location,match;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+")? ?(?:("+words.dateExpression+")) ?("+words.dayTime+") ?(?:"+words.to+" ?("+words.dayTime+") ?)? ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){date=dateExpression2date(match[2],timezone)||new Date;if(match[3]){date=dayTime2date(match[3],timezone,date)}endTime=dayTime2date(match[4],timezone,date);location=match[5];eventName=match[1]||match[6];if(location){date.location=location}if(eventName){date.eventName=eventName}if(endTime){date.endTime=endTime}return date}});expressions.push(function(text,timezone){var date,endTime,eventName,location,match;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+")? ?("+words.dayTime+") ?(?:"+words.to+" ?("+words.dayTime+") ?)? ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){if(match[2]){date=dayTime2date(match[2],timezone)}endTime=dayTime2date(match[3],timezone,date);location=match[4];eventName=match[1]||match[5];if(location){date.location=location}if(eventName){date.eventName=eventName}if(endTime){date.endTime=endTime}return date}});expressions.push(function(text,timezone){var date,endTime,eventName,location,match,time;if(match=text.match(RegExp("^(?:([^"+words.separators+"]+) ?"+words.event_postfix+")? ?("+words.dateExpression+") ?("+words.dayTime+")? ?(?:"+words.to+" ? ("+words.dateExpression+") ?("+words.dayTime+")? ?)? ?(?:"+words.at+" ?([^"+words.separators+"]+))? ?(?:"+words.event_prefix+words.interjection+"?([^"+words.separators+"]+))?$"))){date=dateExpression2date(match[2],timezone)||new Date;if(match[3]){time=dayTime2date(match[3],timezone,date)}if(!match[3]&&!match[5]){date.fullDay=true}endTime=dateExpression2date(match[5],timezone);if(match[5]&&endTime){endTime=dayTime2date(match[5],timezone,endTime)}location=match[6];eventName=match[1]||match[7];if(location){date.location=location}if(eventName){date.eventName=eventName}if(endTime){date.endTime=endTime}if(date.endTime&&!match[5]){date.endTime.setUTCHours(23-timezone);date.endTime.setMinutes(59);date.endTime.setSeconds(59)}return date}});module.exports={words:words,expressions:expressions,number2integer:number2integer,time2object:time2object,dayTime2date:dayTime2date,date2object:date2object,dateExpression2date:dateExpression2date,testStrings:["明天晚上到下禮拜六早上要開會","10月10號 早上 10:00 ~ 下午 4:00","十月十號"]}}).call(this)},{}]},{},[1]);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc