UNPKG

serina

Version:

Natural Language Parser for date and time in Javascript

3 lines (2 loc) 18.6 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).serina=e()}(this,function(){function t(t,e,n){void 0===n&&(n=!0);const s=new RegExp(n?`\\b${e}\\b`:e,"ig");return t.toLowerCase().match(s)}function e(t,e,n){return void 0===n&&(n=!0),new RegExp(n?`\\b${e}\\b`:e,"i").test(t.toLowerCase())}function n(t){return t.replace(/ {2}/g," ").trim()}function s(t,e,s){void 0===s&&(s=!0);const r=new RegExp(s?`\\b${e}\\b`:e,"ig");return n(t.replace(r,""))}class r{constructor(t,e){void 0===t&&(t=""),this._pattern=void 0,this._wordBoundary=void 0,this._pattern=t,this._wordBoundary=e}parseText(e){const s=t(e,this._pattern,this._wordBoundary);return s?s.map(t=>{const s=this.parseStringToDateObj(t);return function(t,e,s){const r=new RegExp(e,"ig"),i=t.replace(r,""),[a]=t.match(r);return{text:n(i),dateTime:s,matched:n(a)}}(e,t,s)}):null}parseStringToDateObj(t){return isNaN(Date.parse(t))?new Date("2000-01-01T00:00:00Z"):new Date(t)}}function i(t){return`(${t})`}const a="(mon)(day)?",o="(tue(s)?)(day)?",u="(wed|wedn(es)?)(day)?",c="(thu(r)?(s)?)(day)?",h="(fri)(day)?",T="(sat(ur)?)(day)?",R="(sun)(day)?",_=i([a,o,u,c,h,T,R].join("|")),E="last|prev(ious)?",d={WITH_FUTURE_PAST_WORDS:`((\\b(for|next|this|current|on|${E})\\b)( ))?${_}`,ANY:_,SINGLE:{MONDAY:a,TUESDAY:o,WEDNESDAY:u,THURSDAY:c,FRIDAY:h,SATURDAY:T,SUNDAY:R},PAST_WORDS:E};function l(t,e){return new Date(Date.UTC(t,e+1,0)).getUTCDate()}class I{constructor(t){this._dateTime=void 0,this._dateTime=t?new Date(t.getTime()):new Date}get millisecond(){return this._dateTime.getUTCMilliseconds()}set millisecond(t){this._dateTime.setUTCMilliseconds(t)}get second(){return this._dateTime.getUTCSeconds()}set second(t){this._dateTime.setUTCSeconds(t)}get minute(){return this._dateTime.getUTCMinutes()}set minute(t){this._dateTime.setUTCMinutes(t)}get hour(){return this._dateTime.getUTCHours()}set hour(t){this._dateTime.setUTCHours(t)}get day(){return this._dateTime.getUTCDate()}set day(t){this._dateTime.setUTCDate(t)}get weekday(){return this._dateTime.getUTCDay()}set weekday(t){this.set({day:this.day+(this.weekday-t)})}get weekdayName(){return this._dateTime.toLocaleString("default",{weekday:"long"})}get month(){return this._dateTime.getUTCMonth()+1}set month(t){this._dateTime.setUTCMonth(t-1)}get nativeMonth(){return this._dateTime.getUTCMonth()}get monthName(){return this._dateTime.toLocaleString("default",{month:"long"})}get year(){return this._dateTime.getUTCFullYear()}set year(t){this._dateTime.setUTCFullYear(t)}get leapYear(){return 29===new Date(Date.UTC(this.year,1,29)).getUTCDate()}get daysInMonth(){return l(this.year,this.nativeMonth)}toDate(){return this._dateTime}toISOString(){return this._dateTime.toISOString()}toString(){return this.toISOString()}now(){return this._dateTime.valueOf()}set(t){return function(t){const e=[];return["millisecond","second","minute","hour","day","week","weekday","month","year"].forEach(n=>{t.includes(n)&&e.push(n)}),e}(Object.keys(t)).forEach(e=>{const n=t[e];switch(e){case"second":this.second=n;break;case"minute":this.minute=n;break;case"hour":this.hour=n;break;case"day":this.day=n<1?1:n>this.daysInMonth?this.daysInMonth:n;break;case"weekday":this.day+=n-this.weekday;break;case"month":this.month=n<1?1:n>12?12:n;break;case"year":this.year=n;break;default:throw"Cannot perform .set() operation with unknown unit"}}),this}plus(t,e){switch(e){case"millisecond":this.millisecond+=t;break;case"second":this.second+=t;break;case"minute":this.minute+=t;break;case"hour":this.hour+=t;break;case"day":this.day+=t;break;case"week":this.day+=7*t;break;case"month":this.month+=t;break;case"year":this.year+=t;break;default:throw"Cannot perform .plus() operation with unknown unit"}return this}minus(t,e){switch(e){case"millisecond":this.millisecond-=t;break;case"second":this.second-=t;break;case"minute":this.minute-=t;break;case"hour":this.hour-=t;break;case"day":this.day-=t;break;case"week":this.day-=7*t;break;case"month":this.month-=t;break;case"year":this.year-=t;break;default:throw"Cannot perform .minus() operation with unknown unit"}return this}next(t,e){switch(e){case"millisecond":this.millisecond+=t;break;case"second":this.second+=t;break;case"minute":this.minute+=t;break;case"hour":this.hour+=t;break;case"day":this.day+=t;break;case"week":this.day+=7*t;break;case"month":this._dateTime=function(t,e){const n=t.getUTCDate(),s=t.getUTCMonth(),r=t.getUTCFullYear();let i=e;for(;n>l(r,s+i);){if(i>100)throw"Possible infinite loop within nextMonths()";i++}const a=t;return a.setUTCMonth(s+i),a}(this._dateTime,t);break;case"year":this.year+=t;break;default:throw"Cannot perform .next() operation with unknown unit"}return this}prev(t,e){return this.previous(t,e)}previous(t,e){switch(e){case"millisecond":this.millisecond-=t;break;case"second":this.second-=t;break;case"minute":this.minute-=t;break;case"hour":this.hour-=t;break;case"day":this.day-=t;break;case"week":this.day-=7*t;break;case"month":this.month-=t;break;case"year":this.year-=t;break;default:throw"Cannot perform .prev() or .previous() operation with unknown unit"}return this}start(t){return this.startOf(t)}startOf(t){switch(t){case"millisecond":case"second":this.millisecond=0;break;case"minute":this.millisecond=0,this.second=0;break;case"hour":this.millisecond=0,this.second=0,this.minute=0;break;case"day":this.millisecond=0,this.second=0,this.minute=0,this.hour=0;break;case"week":this.millisecond=0,this.second=0,this.minute=0,this.hour=0,this.day=(n=this.day,0===(e=this.weekday)?n-6:n-e+1);break;case"month":this.millisecond=0,this.second=0,this.minute=0,this.hour=0,this.day=1;break;case"year":this.millisecond=0,this.second=0,this.minute=0,this.hour=0,this.day=1,this.month=1;break;default:throw"Cannot perform .start() or .startOf() operation with unknown unit"}var e,n;return this}end(t){return this.endOf(t)}endOf(t){switch(t){case"second":this.millisecond=999;break;case"minute":this.millisecond=999,this.second=59;break;case"hour":this.millisecond=999,this.second=59,this.minute=59;break;case"day":this.millisecond=999,this.second=59,this.minute=59,this.hour=23;break;case"month":this.millisecond=999,this.second=59,this.minute=59,this.hour=23,this.day=new Date(Date.UTC(this.year,this.month,0)).getUTCDate();break;case"year":this.millisecond=999,this.second=59,this.minute=59,this.hour=23,this.day=new Date(Date.UTC(this.year,this.month,0)).getUTCDate(),this.month=12;break;default:throw"Cannot perform .end() or .endOf() operation with unknown unit"}return this}}function A(t){return new I(t)}function D(t,n){let s=null;const r=A().weekday;return Object.keys(d.SINGLE).forEach((n,r)=>{e(t,d.SINGLE[n])&&(s=r+1)}),s?(s<=r&&(s+=7),n&&(s-=7),s):null}class N extends r{constructor(){super(d.WITH_FUTURE_PAST_WORDS)}parseStringToDateObj(n){return function(n){const[s]=t(n,d.ANY),r=D(s,e(n,d.PAST_WORDS));return A().set({weekday:r}).startOf("day").toDate()}(n)}}const m="((3[0-1])|([1-2][0-9])|(0?[1-9]))",S=`${m}(st|nd|rd|th)`,y={ANY:`${m}(st|nd|rd|th)?`,WITH_ORDINAL:S,NUMBERS:m,FILLER_WORDS:"on (the )?",WITH_FILLER_WORDS_AND_ORDINAL:`(on (the )?)?${S}`};class O extends r{constructor(){super(y.WITH_FILLER_WORDS_AND_ORDINAL)}parseStringToDateObj(n){return function(n){const s=A();let r=null,i=s.month;if(e(n,y.ANY)){const[e]=t(n,y.ANY);r=parseInt(e,10),r<s.day&&(i+=1)}return r?A().set({day:r,month:i}).start("day").toDate():null}(n)}}const M="jan(uary)?",Y="feb(ruary)?",p="mar(ch)?",U="apr(il)?",f="may",L="jun(e)?",g="jul(y)?",b="aug(ust)?",w="sep(tember)?",k="oct(ober)?",$="nov(ember)?",W="dec(ember)?",H="(last|prev(ious)?)",j=i([M,Y,p,U,f,L,g,b,w,k,$,W].join("|")),F={WITH_FUTURE_PAST_WORDS:`(((for|next|this|current|in)|${H}) )?${j}`,ANY:j,SINGLE:{JANUARY:M,FEBRUARY:Y,MARCH:p,APRIL:U,MAY:f,JUNE:L,JULY:g,AUGUST:b,SEPTEMBER:w,OCTOBER:k,NOVEMBER:$,DECEMBER:W},NUMBERS:"(1[0-2]|0?[1-9])",PAST_WORDS:H};function V(t){let n=null;return Object.keys(F.SINGLE).forEach((s,r)=>{e(t,F.SINGLE[s])&&(n=r+1)}),n}class C extends r{constructor(){super(F.WITH_FUTURE_PAST_WORDS)}parseStringToDateObj(t){return function(t){const n=V(t);if(null===n)return null;let s=A().year;return n<A().month&&(s+=1),e(t,`${F.PAST_WORDS} ${F.ANY}`)&&(s-=1),A().set({month:n,year:s}).startOf("month").start("day").toDate()}(t)}}const x="(\\b[0-9]{4}\\b)",B="(in( )((the( ))?year( ))?)",P={ANY:x,FILLER_WORDS:B,WITH_FILLER_WORDS:`${B}?${x}`};class X extends r{constructor(){super(P.WITH_FILLER_WORDS)}parseStringToDateObj(n){return function(n){let s;if(e(n,P.ANY)){const[e]=t(n,P.ANY);s=parseInt(e,10)}return s?A().set({year:s}).startOf("year").toDate():null}(n)}}const v="am|a.m.|am.",G="pm|p.m.|pm.",Q=`(${v}|${G})`,J="([0-9]{1,2})",q="([0-5][0-9])",K="(to|until)",Z="(after|past)",z=i([K,Z].join("|")),tt="half",et="quarter",nt=i([tt,et].join("|")),st="(min|mins|minute|minutes)",rt=`${J}( )?${Q}`,it=[J,q].join("(:)"),at=`${nt}( )${z}( )(${rt}|${J})`,ot=`${q}( )(${st}( ))?${z}( )(${rt}|${J})`,ut=i([rt,`${it}( )?${Q}`,it].join("|")),ct=i([at,ot].join("|")),ht=i([ut,ct].join("|")),Tt={WITH_FILLER_WORDS:`((at|by)( ))?${ht}`,ANY:ht,FORMAT_NORMAL:ut,FORMAT_RELATIVE:ct,RELATIVE_TIME_FILLER_WORDS:z,HOUR_PART:J,MINUTE_PART:q,DIVIDER:"(:)",MERIDIEM:Q,AM:v,PM:G,TO:K,PAST:Z,HALF:tt,QUARTER:et,VERBAL_QUANTIFIERS:nt,MINUTE_IDENTIFIER:st,FILLER_WORDS:"(at|by)"};function Rt(e,n){const s=t(e,n,!1);if(!s||0===s.length)return null;const[r]=s;return r}function _t(t){let n,s;if(e(t,Tt.RELATIVE_TIME_FILLER_WORDS))if(e(t,Tt.VERBAL_QUANTIFIERS)){try{n=Rt(t,`(?<=${Tt.RELATIVE_TIME_FILLER_WORDS}( ))${Tt.HOUR_PART}`)}catch{const e=Rt(t,`(${Tt.RELATIVE_TIME_FILLER_WORDS}( ))${Tt.HOUR_PART}`);n=Rt(e,Tt.HOUR_PART)}e(t,Tt.HALF)&&(s="30"),e(t,Tt.QUARTER)&&(s="15")}else{try{n=Rt(t,`(?<=${Tt.RELATIVE_TIME_FILLER_WORDS}( ))${Tt.HOUR_PART}(?=((( )${Tt.MERIDIEM}))?)`)}catch{const e=Rt(t,`(${Tt.RELATIVE_TIME_FILLER_WORDS}( ))${Tt.HOUR_PART}(?=((( )${Tt.MERIDIEM}))?)`);n=Rt(e,Tt.HOUR_PART)}s=Rt(t,`\\b${Tt.MINUTE_PART}(?=(( )(${Tt.MINUTE_IDENTIFIER}( ))?${Tt.RELATIVE_TIME_FILLER_WORDS}))`)}else if(e(t,Tt.DIVIDER)){n=Rt(t,`\\b${Tt.HOUR_PART}(?=${Tt.DIVIDER})`);try{s=Rt(t,`(?<=${Tt.DIVIDER})${Tt.MINUTE_PART}`)}catch{const e=Rt(t,`(${Tt.DIVIDER})${Tt.MINUTE_PART}`);s=Rt(e,Tt.MINUTE_PART)}}else n=Rt(t,`\\b${Tt.HOUR_PART}(?=(( )?${Tt.MERIDIEM}))`),s="0";return function(t,n,s){return isNaN(n)||isNaN(s)||n<0||n>23||s<0||s>59?null:(e(t,Tt.AM,!1)&&12===n&&(n=24),e(t,Tt.TO)&&n>0&&(n-=1),e(t,Tt.TO)&&(s=60-s),e(t,Tt.PM,!1)&&n<12&&(n+=12),24===n&&(n=0),{hour:n,minute:s})}(t,parseInt(n,10),parseInt(s,10))}class Et extends r{constructor(){super(Tt.WITH_FILLER_WORDS,!1)}parseStringToDateObj(t){return function(t){const e=_t(t);if(!e)return null;const{hour:n,minute:s}=e;return A().set({hour:n,minute:s}).startOf("minute").toDate()}(t)}}const dt=i([i([y.NUMBERS,F.NUMBERS,P.ANY].join("-")),i([y.NUMBERS,F.NUMBERS,P.ANY].join("/"))].join("|")),lt=i([i([F.NUMBERS,y.NUMBERS,P.ANY].join("-")),i([F.NUMBERS,y.NUMBERS,P.ANY].join("/"))].join("|")),It=i([i([P.ANY,F.NUMBERS,y.NUMBERS].join("-")),i([P.ANY,F.NUMBERS,y.NUMBERS].join("/"))].join("|")),At="((,)? )",Dt=i([y.ANY,F.ANY,P.ANY].join(At)),Nt=i([F.ANY,y.ANY,P.ANY].join(At)),mt=[dt,lt,It,Dt,Nt].join("|"),St={WITH_FILLER_WORDS:`(((on|by) (the )?))?(${mt})`,ANY:mt,NUM_DAY_MONTH_YEAR:dt,NUM_MONTH_DAY_YEAR:lt,NUM_YEAR_MONTH_DAY:It,TXT_DAY_MONTH_YEAR:Dt,TXT_MONTH_DAY_YEAR:Nt,FILLER_WORDS:"((on|by) (the )?)",NUM_DIVIDER:"(/|(-))",TXT_DIVIDER:At};function yt(t){let n,s,r;const i=new RegExp(St.NUM_DIVIDER,"g"),a=new RegExp(St.TXT_DIVIDER,"gi");return e(t,St.NUM_DAY_MONTH_YEAR,!1)?[n,s,r]=t.replace(i," ").split(" "):e(t,St.NUM_MONTH_DAY_YEAR,!1)?[s,n,r]=t.replace(i," ").split(" "):e(t,St.NUM_YEAR_MONTH_DAY,!1)?[r,s,n]=t.replace(i," ").split(" "):e(t,St.TXT_DAY_MONTH_YEAR,!1)?([n,s,r]=t.replace(a," ").split(" "),s=V(s).toString()):e(t,St.TXT_MONTH_DAY_YEAR,!1)&&([s,n,r]=t.replace(a," ").split(" "),s=V(s).toString()),n&&s&&r?A().set({day:parseInt(n),month:parseInt(s),year:parseInt(r)}).start("day").toDate():null}class Ot extends r{constructor(){super(St.WITH_FILLER_WORDS,!1)}parseStringToDateObj(t){return yt(s(t,St.FILLER_WORDS))}}const Mt=i([F.NUMBERS,P.ANY].join(St.NUM_DIVIDER)),Yt=i([P.ANY,F.NUMBERS].join(St.NUM_DIVIDER)),pt=i([F.NUMBERS,y.NUMBERS].join(St.NUM_DIVIDER)),Ut=i([y.NUMBERS,F.NUMBERS].join(St.NUM_DIVIDER)),ft=i([F.ANY,y.ANY].join(St.TXT_DIVIDER)),Lt=i([y.ANY,F.ANY].join(St.TXT_DIVIDER)),gt=i([F.ANY,P.ANY].join(St.TXT_DIVIDER)),bt=i([P.ANY,F.ANY].join(St.TXT_DIVIDER)),wt=i([Mt,Yt,pt,Ut,gt,ft,bt,Lt].join("|")),kt={WITH_FILTER_WORDS:`(${St.FILLER_WORDS})?(${wt})`,ANY:wt,NUM_MONTH_YEAR:Mt,NUM_YEAR_MONTH:Yt,NUM_MONTH_DAY:pt,NUM_DAY_MONTH:Ut,TXT_MONTH_YEAR:gt,TXT_MONTH_DAY:ft,TXT_DAY_MONTH:Lt,TXT_YEAR_MONTH:bt};function $t(t,e){const n=A(),s=n.year,r=parseInt(t,10),i=parseInt(e,10);return A().set({month:r,day:i,year:s})<n?(s+1).toString():s.toString()}function Wt(t){let n,s,r,i;return e(t,kt.NUM_MONTH_YEAR)?(i=new RegExp(St.NUM_DIVIDER,"g"),[s,r]=t.replace(i," ").split(" "),n="1"):e(t,kt.NUM_YEAR_MONTH)?(i=new RegExp(St.NUM_DIVIDER,"g"),[r,s]=t.replace(i," ").split(" "),n="1"):e(t,kt.NUM_DAY_MONTH)?(i=new RegExp(St.NUM_DIVIDER,"g"),[n,s]=t.replace(i," ").split(" "),r=$t(s,n)):e(t,kt.NUM_MONTH_DAY)?(i=new RegExp(St.NUM_DIVIDER,"g"),[s,n]=t.replace(i," ").split(" "),r=$t(s,n)):e(t,kt.TXT_MONTH_YEAR)?(i=new RegExp(St.TXT_DIVIDER,"g"),[s,r]=t.replace(i," ").split(" "),n="1",s=V(s).toString()):e(t,kt.TXT_YEAR_MONTH)?(i=new RegExp(St.TXT_DIVIDER,"g"),[r,s]=t.replace(i," ").split(" "),n="1",s=V(s).toString()):e(t,kt.TXT_DAY_MONTH)?(i=new RegExp(St.TXT_DIVIDER,"g"),[n,s]=t.replace(i," ").split(" "),s=V(s).toString(),r=$t(s,n)):e(t,kt.TXT_MONTH_DAY)&&(i=new RegExp(St.TXT_DIVIDER,"g"),[s,n]=t.replace(i," ").split(" "),s=V(s).toString(),r=$t(s,n)),n&&s&&r?A().set({day:parseInt(n),month:parseInt(s),year:parseInt(r)}).start("day").toDate():null}const Ht="today",jt="tomorrow",Ft="yesterday",Vt={ANY:i([Ht,jt,Ft].join("|")),TODAY:Ht,TOMORROW:jt,YESTERDAY:Ft},Ct="((in|after) )?",xt="( (from now|from today|later|after))",Bt="(days|day)",Pt="(weeks|week|wks|wk)",Xt="(months|month)",vt="(years|year|yrs|yr)",Gt={DAYS:Bt,WEEKS:Pt,MONTHS:Xt,YEARS:vt,ANY:i([Bt,Pt,Xt,vt].join("|"))},Qt="(next|following)",Jt="a",qt={ANY:[Qt,Jt].join("|"),NEXT:Qt,ONE:Jt},Kt=`([0-9]+|${qt.ANY})( )${Gt.ANY}`,Zt=`${Ct}?${Kt}`,zt=`${Kt}${xt}`,te={ANY:[zt,Zt].join("|"),ARGUMENT_AFTER:Zt,ARGUMENT_FIRST:zt},ee=i([Vt.ANY,te.ANY].join("|")),ne=[Ct,xt].join("|"),se={WITH_FILLER_WORDS:`(${St.FILLER_WORDS})?${ee}`,ANY:ee,RELATIVE_ADVERB:Vt,RELATIVE_EXPRESSION:te,FILLER_WORDS:ne,TIME_UNITS:Gt,VERBAL_QUANTIFIERS:qt};function re(n){const r=s(n,se.FILLER_WORDS);return e(r,se.RELATIVE_ADVERB.ANY)?e(i=r,se.RELATIVE_ADVERB.TODAY)?A().start("day").toDate():e(i,se.RELATIVE_ADVERB.YESTERDAY)?A().minus(1,"day").start("day").toDate():A().plus(1,"day").start("day").toDate():function(n){const r=t(n,se.TIME_UNITS.ANY);if(!r)return null;const[i]=r,a=function(t,n){const s=Object.keys(t);if(s.length)for(const r of s)if(e(t[r],n))return r;return null}(se.TIME_UNITS,i);if(!a)return null;const o=function(t){switch(t){case"DAYS":return"day";case"WEEKS":return"week";case"MONTHS":return"month";case"YEARS":return"year";case"ANY":return null}}(a),u=s(n,a);let c;if(e(u,se.VERBAL_QUANTIFIERS.ONE))c=1;else{if(e(u,se.VERBAL_QUANTIFIERS.NEXT))return A().start(o).next(1,o).toDate();c=parseInt(u,10)}return A().plus(c,o).start("day").toDate()}(r);var i}const ie=`(${St.FILLER_WORDS})?(${[St.ANY,kt.ANY,se.ANY].join("|")})`,ae=`(${Tt.FILLER_WORDS}( ))?${Tt.ANY}`,oe={ANY:[[ie,ae].join(" "),[ae,ie].join(" ")].join("|")};class ue extends r{constructor(){super(oe.ANY,!1)}parseStringToDateObj(n){return function(n){const r=function(e){const n=t(s(e,St.FILLER_WORDS),`(${St.ANY}|${kt.ANY}|${se.ANY})`);return n?n[0]:null}(n),i=function(e){const n=t(s(e,Tt.FILLER_WORDS),Tt.ANY);return n?n[0]:null}(n);if(!r||!i)return null;const a=function(t){let n;if(e(t,St.ANY)){const{day:e,month:s,year:r}=A(yt(t));n={day:e,month:s,year:r}}else if(e(t,`${kt.ANY}`)){const{day:e,month:s,year:r}=A(Wt(t));n={day:e,month:s,year:r}}else{const{day:e,nativeMonth:s,year:r}=A(re(t));n={day:e,month:s,year:r}}return n||null}(r),o=_t(i);if(!a||!o)return null;const{day:u,month:c,year:h}=a,{hour:T,minute:R}=o;return A().set({day:u,month:c,year:h,hour:T,minute:R}).start("minute").toDate()}(n)}}const ce=d.WITH_FUTURE_PAST_WORDS,he=`(${Tt.FILLER_WORDS}( ))?${Tt.FORMAT_NORMAL}`,Te={ANY:`${he}( )${ce}|${ce}( )${he}`};class Re extends r{constructor(){super(Te.ANY)}parseStringToDateObj(n){return function(n){const s=function(e,n){const s=t(e,n);if(!s)return null;const[r]=s;return r}(n,Tt.ANY),{hour:r,minute:i}=_t(s),[a]=t(n,d.ANY),o=D(a,e(n,d.PAST_WORDS));return A().set({weekday:o,hour:r,minute:i}).startOf("minute").toDate()}(n)}}const _e="(in|after) ",Ee=" (from now|later|after)",de="(hours|hour|hrs|hr)",le="(minutes|minute|mins|min)",Ie="(seconds|second|secs|sec)",Ae={ANY:i([de,le,Ie].join("|")),HOURS:de,MINUTES:le,SECONDS:Ie},De="(half (an|a))",Ne="(a quarter of (a|an))",me="(a|an|one)",Se={ANY:i([De,Ne,me].join("|")),HALF:De,QUARTER:Ne,ONE:me},ye=`([0-9]+|${Se.ANY}) ${Ae.ANY}`,Oe=`${_e}${ye}`,Me=`${ye}${Ee}`,Ye={ANY:i([Me,Oe].join("|")),ARGUMENT_AFTER:Oe,ARGUMENT_FIRST:Me,FILLER_WORDS:[_e,Ee].join("|"),TIME_UNITS:Ae,VERBAL_QUANTIFIERS:Se};class pe extends r{constructor(){super(Ye.ANY,!1)}parseStringToDateObj(t){return function(t){const e=s(t,Ye.FILLER_WORDS);return A(this.addRelativeTimeToCurrentTime(e)).startOf("millisecond").toDate()}(t)}}class Ue extends r{constructor(){super(se.WITH_FILLER_WORDS,!1)}parseStringToDateObj(t){return function(t){const e=re(t);return e?A(e).start("day").toDate():null}(t)}}const fe="(midnight|mid night|mid-night)",Le="(noon|midday|mid day|mid-day)",ge={WITH_FILLER_WORDS:`((at|by|around)( ))?${i([fe,Le].join("|"))}`,MID_NIGHT:fe,MID_DAY:Le};class be extends r{constructor(){super(ge.WITH_FILLER_WORDS,!1)}parseStringToDateObj(t){return function(t){let n=A().day,s=null;const r=A().hour;return e(t,`${ge.MID_DAY}`)&&(s=12,r>12&&(n+=1)),e(t,`${ge.MID_NIGHT}`)&&(s=0,n+=1),null===s?null:A().startOf("minute").set({day:n,hour:s,minute:0}).toDate()}(t)}}class we extends r{constructor(){super(kt.WITH_FILTER_WORDS,!1)}parseStringToDateObj(t){return Wt(s(t,St.FILLER_WORDS))}}return t=>{const e={original:t,isValid:!1,matches:[]};return[N,O,C,X,Et,Ot,we,ue,pe,Ue,Re,be].forEach(n=>{const s=(new n).parseText(t);s&&s.length&&(e.matches=e.matches.concat(s))}),e.matches.length&&(e.isValid=!0),e}}); //# sourceMappingURL=serina.umd.js.map