Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-14 03:31:28 +00:00
parent 7052d4f4b5
commit 9a64997884
37 changed files with 656 additions and 390 deletions

View File

@@ -1,48 +1,36 @@
async function findAvailableSlots(a,b,c){
const d=await import('https://esm.sh/date-fns@3.6.0')
const {parseISO,formatISO,max,min,addMinutes,isBefore}=d
const p=t=>parseISO(t)
const wh=(dt,s)=>{
const [H,M]=s.split(':')
const x=new Date(dt)
x.setHours(H,M,0,0)
return x
const f=await import('https://esm.sh/date-fns')
const p=f.parseISO,d=f.addMinutes,x=f.max,y=f.min,i=f.isBefore,j=f.isAfter
const {durationMinutes:r,searchRange:s,workHours:w}=c
const h=t=>t.split(':').map(n=>+n)
const [ws,we]=[h(w.start),h(w.end)]
const z=(d0,[H,M])=>{d0=new Date(d0);d0.setHours(H,M,0,0);return d0.toISOString()}
const S=p(s.start),E=p(s.end)
let u=[...a,...b].map(o=>({start:p(o.start),end:p(o.end)}))
u=u.sort((A,B)=>A.start-B.start)
let m=[]
for(let k of u){
if(!m.length||k.start>m[m.length-1].end)m.push({start:k.start,end:k.end})
else m[m.length-1].end=new Date(Math.max(m[m.length-1].end,k.end))
}
const rng=[p(c.searchRange.start),p(c.searchRange.end)]
const dur=c.durationMinutes
const norm=x=>x.map(v=>[p(v.start),p(v.end)])
const A=norm(a),B=norm(b)
const merge=x=>{
let r=x.sort((x,y)=>x[0]-y[0]),o=[r[0]]
for(let i=1;i<r.length;i++){
let [s,e]=r[i],l=o[o.length-1]
if(s<=l[1]) l[1]=new Date(Math.max(e,l[1]))
else o.push([s,e])
let q=[]
let st=S
for(let k of m){
if(i(st,k.start)){
let fs=x(st,S),fe=y(k.start,E)
if(i(fs,fe))q.push({start:fs,end:fe})
}
return o
st=k.end
}
const busy=merge(A.concat(B))
const free=[]
let cur=rng[0]
for(let i=0;i<=busy.length;i++){
let s=i<busy.length?max(cur,busy[i][1]):cur
let e=i<busy.length?max(cur,busy[i][0]):rng[1]
if(i<busy.length){
if(busy[i][0]>cur) free.push([cur,busy[i][0]])
cur=max(cur,busy[i][1])
}else free.push([s,e])
}
const out=[]
for(let [s,e]of free){
s=max(s,rng[0])
e=min(e,rng[1])
let ws=wh(s,c.workHours.start)
let we=wh(s,c.workHours.end)
if(ws>we){let t=ws;ws=we;we=t}
let ss=max(s,ws),ee=min(e,we)
while(isBefore(addMinutes(ss,dur),ee)){
out.push({start:formatISO(ss),end:formatISO(addMinutes(ss,dur))})
ss=addMinutes(ss,dur)
if(i(st,E))q.push({start:x(st,S),end:E})
let out=[]
for(let v of q){
let cs=z(v.start,ws),ce=z(v.start,we)
cs=p(cs);ce=p(ce)
let ss=x(v.start,cs),ee=y(v.end,ce)
for(let t=ss;i(d(t,r),ee)||+d(t,r)==+ee;t=d(t,r)){
let e=d(t,r)
if(!j(t,ss)||i(e,ee))out.push({start:t.toISOString(),end:e.toISOString()})
}
}
return out