fix: unify tender countdowns and add monthly calendar navigation

This commit is contained in:
2026-09-06 08:47:44 +03:00
parent a291b186df
commit b94ab97241
8 changed files with 123 additions and 49 deletions
+29
View File
@@ -36,3 +36,32 @@ export function createTenderICS(t, now = new Date()) {
`DESCRIPTION:${escapeICS('İKN: '+t.ikn+' — '+t.kurum)}`,
'END:VEVENT','END:VCALENDAR',''].map(fold).join('\r\n');
}
export const istanbulDateKey = (now = new Date()) => new Date(now.getTime() + 3 * 3600000).toISOString().slice(0,10);
export function tenderDateKey(t) {
const m = /^(\d{2})\.(\d{2})\.(\d{4})(?:$|\s)/.exec(String(t?.tarih || ''));
if (!m) return null;
const key = `${m[3]}-${m[2]}-${m[1]}`;
const date = new Date(key + 'T00:00:00Z');
return !Number.isNaN(date.getTime()) && date.toISOString().slice(0,10) === key ? key : null;
}
export function deadlineInfo(t, now = new Date()) {
const dateKey = tenderDateKey(t);
if (!dateKey) return {dateKey:null,days:null,expired:null,label:'Tarih doğrulanmalı',deadline:null};
const days = Math.round((Date.parse(dateKey+'T00:00:00Z') - Date.parse(istanbulDateKey(now)+'T00:00:00Z')) / 86400000);
let deadline = null;
try { deadline = tenderDeadline(t); } catch { /* an unknown time is not midnight */ }
const expired = deadline ? deadline.getTime() <= now.getTime() : days < 0 ? true : null;
const label = expired ? 'Süresi geçti' : `${days === 0 ? 'BUGÜN' : days + ' gün'}${deadline ? '' : ' · saat doğrulanmalı'}`;
return {dateKey,days,expired,label,deadline};
}
export function calendarMonthDays(month) {
if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(month)) return [];
const [year,m] = month.split('-').map(Number);
const count = new Date(Date.UTC(year,m,0)).getUTCDate();
return Array.from({length:count},(_,i)=>{
const day=String(i+1).padStart(2,'0');
return {key:`${month}-${day}`,date:`${day}.${String(m).padStart(2,'0')}.${year}`,
label:new Date(`${month}-${day}T12:00:00Z`).toLocaleDateString('tr-TR',{weekday:'short',timeZone:'Europe/Istanbul'})};
});
}