UNPKG

serina

Version:

Natural Language Parser for date and time in Javascript

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