diff --git a/public/og/is-gunu-hesaplama.png b/public/og/is-gunu-hesaplama.png new file mode 100644 index 0000000..ee793d7 Binary files /dev/null and b/public/og/is-gunu-hesaplama.png differ diff --git a/public/site.css b/public/site.css index 82a80ff..2250581 100644 --- a/public/site.css +++ b/public/site.css @@ -1953,6 +1953,86 @@ code { overflow-wrap: anywhere; } +/* iş günü hesaplama: options shared by both cards, holiday lists under each result */ +.isg-bar { + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr); + gap: 12px 24px; + align-items: start; + padding: 16px 24px; + border-bottom: 1px solid var(--border); +} + +.isg-bar .opt { + padding: 0; +} + +.isg-arefe { + display: grid; + gap: 6px; +} + +.isg-arefe .seg-radio span { + padding: 0 8px; +} + +.isg-note { + color: var(--muted-foreground); +} + +.isg-hol { + margin-top: 16px; +} + +.found caption { + padding-bottom: 6px; + font-size: 14px; + font-weight: 600; + text-align: left; +} + +.isg-hol td:first-child { + white-space: nowrap; +} + +.isg-more { + margin-top: 8px; + color: var(--muted-foreground); + font-size: 13px; +} + +.isg-more:empty { + display: none; +} + +.hol-table { + max-width: 42em; + margin-top: 24px; +} + +.hol-table caption { + color: var(--muted-foreground); + font-weight: 400; +} + +.hol-table td, +.hol-table th[scope="row"] { + white-space: nowrap; +} + +@media (max-width: 833px) { + .isg-bar { + grid-template-columns: minmax(0, 1fr); + } +} + +@media (max-width: 480px) { + .isg-hol td:first-child, + .hol-table td { + white-space: normal; + } +} + .avg-list { height: auto; min-height: 9.5em; diff --git a/scripts/browser-check.mjs b/scripts/browser-check.mjs index 4038568..2d311ea 100644 --- a/scripts/browser-check.mjs +++ b/scripts/browser-check.mjs @@ -42,6 +42,7 @@ const YAS = "/tr/yas-hesaplama/"; const YUZDE = "/tr/yuzde-hesaplama/"; const ORTALAMA = "/tr/ortalama-hesaplama/"; const GUN = "/tr/gun-hesaplama/"; +const ISG = "/tr/is-gunu-hesaplama/"; const DAYS = "/days-between-dates/"; const LINES = "/remove-line-breaks/"; const HEX = "/hex-to-rgb/"; @@ -1131,18 +1132,97 @@ for (const width of [1440, 390]) { await setDate("start", 15, 5, 1990); await setDate("end", 30, 7, 2026); await page.fill("#shift-days", "90"); + expect((await page.locator(`a[href="${ISG}"]`).count()) >= 2, `${label}: no link to iş günü hesaplama`); await page.screenshot({ path: `${shots}/tr-gun-${width}.png`, fullPage: true }); await langMenu(page, label, "tr", { en: DAYS, tr: GUN }, null); finish(errors, label); await context.close(); } +for (const width of [1440, 390]) { + const label = `isg ${width}`; + const { context, page, errors } = await open(width, ISG, label); + await page.evaluate(() => localStorage.clear()); + await page.reload({ waitUntil: "networkidle" }); + const val = (id) => page.textContent(`#${id}`); + const setDate = async (p, d, m, y) => { + await page.fill(`#${p}-d`, String(d)); + await page.selectOption(`#${p}-m`, String(m)); + await page.fill(`#${p}-y`, String(y)); + }; + const pick = (name, value) => page.locator(`label:has(input[name="${name}"][value="${value}"]) span`).click(); + expect((await page.inputValue("#start-y")) === String(new Date().getFullYear()), `${label}: start is not today`); + expect((await page.locator(".hol-table tbody tr").count()) === 14, `${label}: bayram table rows`); + expect((await page.locator('a[href="/tr/gun-hesaplama/"]').count()) >= 1, `${label}: no link to gün hesaplama`); + + await setDate("start", 1, 1, 2026); + await setDate("end", 31, 1, 2026); + expect((await val("count-main")) === "21 iş günü" && (await val("we")) === "9 gün" && (await val("hol")) === "1 gün", `${label}: January gave ${await val("count-main")}`); + expect((await page.locator("#hol-body tr").count()) === 1 && (await val("hol-body")).includes("Yılbaşı"), `${label}: holiday list`); + await setDate("start", 2, 1, 2026); + expect((await val("count-main")) === "21 iş günü", `${label}: from 2 January gave ${await val("count-main")}`); + await page.uncheck("#include-start"); + expect((await val("count-main")) === "20 iş günü" && (await val("range")).includes("hariç"), `${label}: excluded start gave ${await val("count-main")}`); + await page.check("#include-start"); + + await setDate("start", 1, 1, 2026); + await setDate("end", 31, 12, 2026); + expect((await val("count-main")) === "249,5 iş günü" && (await val("half")) === "3 gün", `${label}: 2026 gave ${await val("count-main")}`); + await pick("arefe", "work"); + expect((await val("count-main")) === "251 iş günü", `${label}: arefe as work gave ${await val("count-main")}`); + await pick("arefe", "off"); + expect((await val("count-main")) === "248 iş günü", `${label}: arefe off gave ${await val("count-main")}`); + await pick("arefe", "half"); + await page.check("#saturday"); + expect((await val("count-main")) === "299,5 iş günü", `${label}: saturday gave ${await val("count-main")}`); + await page.uncheck("#saturday"); + await page.uncheck("#holidays"); + expect((await val("count-main")) === "261 iş günü" && !(await page.isVisible("#hol-wrap")), `${label}: no holidays gave ${await val("count-main")}`); + await page.check("#holidays"); + + await setDate("start", 1, 12, 2035); + await setDate("end", 10, 1, 2037); + expect((await val("years-note")).includes("2036-2037"), `${label}: uncovered years not noted: ${await val("years-note")}`); + await setDate("start", 31, 1, 2026); + await setDate("end", 1, 1, 2026); + expect((await val("count-main")) === "21 iş günü" && (await val("status")).length > 10, `${label}: swap gave ${await val("count-main")}`); + await setDate("end", 31, 2, 2023); + expect((await val("status")).includes("28 gün"), `${label}: missing day not reported`); + + await setDate("base", 2, 12, 2026); + await page.fill("#shift-days", "20"); + expect((await val("shift-out")) === "30 Aralık 2026" && (await val("shift-sub")) === "Çarşamba, 28 takvim günü sonra", `${label}: add gave ${await val("shift-out")} ${await val("shift-sub")}`); + await setDate("base", 18, 3, 2026); + await page.fill("#shift-days", "1"); + expect((await val("shift-out")) === "23 Mart 2026" && (await val("shift-status")).includes("1,5") && (await page.locator("#shift-hol-body tr").count()) === 4, `${label}: arefe shift gave ${await val("shift-out")}`); + await pick("op", "sub"); + await setDate("base", 23, 3, 2026); + expect((await val("shift-out")) === "18 Mart 2026" && (await val("shift-formula")).includes("- 1 iş günü"), `${label}: sub gave ${await val("shift-out")}`); + await page.fill("#shift-days", "abc"); + expect((await val("shift-out")) === "-" && (await val("shift-status")).length > 10, `${label}: bad shift not reported`); + await pick("arefe", "work"); + await page.reload({ waitUntil: "networkidle" }); + expect(await page.isChecked('input[name="op"][value="sub"]'), `${label}: op not remembered`); + expect(await page.isChecked('input[name="arefe"][value="work"]'), `${label}: arefe not remembered`); + + await pick("op", "add"); + await pick("arefe", "half"); + await setDate("start", 1, 3, 2026); + await setDate("end", 31, 5, 2026); + await setDate("base", 2, 12, 2026); + await page.fill("#shift-days", "20"); + await page.screenshot({ path: `${shots}/tr-isg-${width}.png`, fullPage: true }); + await langMenu(page, label, "tr", { en: "/", tr: ISG }, null); + finish(errors, label); + await context.close(); +} + for (const path of OTHER) { for (const width of [1440, 390]) { const label = `${path} ${width}`; const { context, page, errors } = await open(width, path, label); await page.screenshot({ path: `${shots}/page${path.replace(/\//g, "_")}-${width}.png`, fullPage: true }); - if (path !== "/missing-page") expect((await page.locator(".tool-card").count()) === 19, `${label}: index does not list every tool`); + if (path !== "/missing-page") expect((await page.locator(".tool-card").count()) === 20, `${label}: index does not list every tool`); if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/kdv-hesaplama/"]').count()) === 1, `${label}: index does not link KDV`); if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/yas-hesaplama/"]').count()) === 1, `${label}: index does not link yaş hesaplama`); if (path !== "/missing-page") expect((await page.locator(`.tool-card a[href="${path === "/tr/" ? GUN : DAYS}"]`).count()) === 1, `${label}: index does not link days between dates`); @@ -1158,6 +1238,7 @@ for (const path of OTHER) { if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/word-frequency-counter/"]').count()) === 1, `${label}: index does not link the word frequency counter`); if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/yuzde-hesaplama/"]').count()) === 1, `${label}: index does not link yüzde hesaplama`); if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/ortalama-hesaplama/"]').count()) === 1, `${label}: index does not link ortalama hesaplama`); + if (path !== "/missing-page") expect((await page.locator(`.tool-card a[href="${ISG}"]`).count()) === 1, `${label}: index does not link iş günü hesaplama`); const lang = path === "/tr/" ? "tr" : "en"; await langMenu(page, label, lang, HOME, `${shots}/menu${path.replace(/\//g, "_")}-${width}.png`); finish(errors, label); diff --git a/scripts/build.mjs b/scripts/build.mjs index 28e36dd..f8016bf 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -824,7 +824,65 @@ ${dateFields("base", u.base, u, { today: u.today })} `; } -const TOOL_BODY = { paste: pasteTool, linebreaks: lineBreaksTool, case: caseTool, color: colorTool, invisible: invisibleTool, repeater: repeaterTool, chmod: chmodTool, slug: slugTool, special: specialTool, counter: counterTool, frequency: frequencyTool, reverse: caseTool, flip: pasteTool, compare: compareTool, kdv: kdvTool, yas: yasTool, dates: datesTool, yuzde: pctTool, ortalama: avgTool, gun: gunTool }; +/** Holiday rows for one result; the page script fills the body and keeps the wrapper hidden while it is empty. */ +function holTable(id, title, u) { + return ``; +} + +/** Business days: shared counting options on top, then the range count and the date shift, as on the gün hesaplama page. */ +function isgunuTool(page) { + const u = page.ui; + const row = (id, label) => `
${esc(label)}
-
`; + const check = (id, label, hint, on) => ``; + return `
+
+${check("holidays", u.holidays, u.holidaysHint, true)} +${check("saturday", u.saturday, u.saturdayHint, false)} +
${esc(u.arefe)}
${u.arefes.map(([v, l], i) => radio("arefe", v, l, i === 0)).join("")}
+
+
+
+

${esc(u.between.title)}

${esc(u.between.question)}

+${dateFields("start", u.start, u, { today: u.today })} +${dateFields("end", u.end, u, { today: u.today })} +${check("include-start", u.includeStart, u.includeStartHint, true)} +
+
+
${esc(u.resultLabel)}-

+
+${row("cal", u.calendar)} +${row("we", u.weekend)} +${row("hol", u.holidayRow)} +${row("half", u.halfRow)} +
+

+

+

+${holTable("hol", u.holTitle, u)} +
+
+
+
+

${esc(u.shift.title)}

${esc(u.shift.question)}

+${dateFields("base", u.base, u, { today: u.today })} +
${u.ops.map(([v, l], i) => radio("op", v, l, i === 0)).join("")}
+
+
+
+
${esc(u.shift.result)}-

+
+${row("shift-cal", u.shiftCalendar)} +
+

+

+

+${holTable("shift-hol", u.shiftHolTitle, u)} +
+
+
`; +} + +const TOOL_BODY = { paste: pasteTool, linebreaks: lineBreaksTool, case: caseTool, color: colorTool, invisible: invisibleTool, repeater: repeaterTool, chmod: chmodTool, slug: slugTool, special: specialTool, counter: counterTool, frequency: frequencyTool, reverse: caseTool, flip: pasteTool, compare: compareTool, kdv: kdvTool, yas: yasTool, dates: datesTool, yuzde: pctTool, ortalama: avgTool, gun: gunTool, isgunu: isgunuTool }; /** Prose, a list of titled rows with sources, and a dated note; the paste and compare pages build theirs from why and shortcuts. */ function infoSection(page, sec) { @@ -995,7 +1053,7 @@ function manifest(lang) { }; } -const SCRIPTS = ["clean.js", "plain-text.js", "diff.js", "text-compare.js", "kdv.js", "kdv-hesaplama.js", "yas.js", "yas-hesaplama.js", "date-diff.js", "days-between-dates.js", "line-breaks.js", "remove-line-breaks.js", "case.js", "case-converter.js", "color.js", "hex-to-rgb.js", "invisible.js", "invisible-character.js", "repeat.js", "text-repeater.js", "reverse.js", "reverse-text.js", "flip.js", "upside-down-text.js", "chmod.js", "chmod-calculator.js", "slug.js", "slug-generator.js", "special.js", "remove-special-characters.js", "count.js", "karakter-sayaci.js", "frequency.js", "word-frequency-counter.js", "sayi.js", "yuzde.js", "yuzde-hesaplama.js", "ortalama.js", "ortalama-hesaplama.js", "gun-hesaplama.js", "nav.js"]; +const SCRIPTS = ["clean.js", "plain-text.js", "diff.js", "text-compare.js", "kdv.js", "kdv-hesaplama.js", "yas.js", "yas-hesaplama.js", "date-diff.js", "days-between-dates.js", "line-breaks.js", "remove-line-breaks.js", "case.js", "case-converter.js", "color.js", "hex-to-rgb.js", "invisible.js", "invisible-character.js", "repeat.js", "text-repeater.js", "reverse.js", "reverse-text.js", "flip.js", "upside-down-text.js", "chmod.js", "chmod-calculator.js", "slug.js", "slug-generator.js", "special.js", "remove-special-characters.js", "count.js", "karakter-sayaci.js", "frequency.js", "word-frequency-counter.js", "sayi.js", "yuzde.js", "yuzde-hesaplama.js", "ortalama.js", "ortalama-hesaplama.js", "gun-hesaplama.js", "is-gunu.js", "is-gunu-hesaplama.js", "nav.js"]; const sha = (...parts) => { const h = createHash("sha256"); for (const p of parts) h.update(p); diff --git a/scripts/content.mjs b/scripts/content.mjs index 807a850..c1b9e96 100644 --- a/scripts/content.mjs +++ b/scripts/content.mjs @@ -2,6 +2,8 @@ import { flipText, FLIP_TABLE } from "../src/flip.js"; import { toSymbolic } from "../src/chmod.js"; import { STOPWORDS } from "../src/frequency.js"; +import { BAYRAMS, BAYRAM_NAMES, SOURCE_YEARS, countBusinessDays, yearTotal, formatValue } from "../src/is-gunu.js"; +import { MONTHS as AYLAR, WEEKDAYS as GUNLER, addDays, weekday, formatDate as tarih } from "../src/yas.js"; const k = (...keys) => keys.map((key) => `${key}`).join("+"); const a = (href, text) => `${text}`; @@ -709,6 +711,39 @@ export const TOOLS = [ demoAge: "80", }, }, + { + id: "is-gunu-hesaplama", + en: { + path: "/tr/is-gunu-hesaplama/", + lang: "tr", + name: "Business day calculator (Turkish)", + blurb: "Counts the work days between two dates without weekends and Turkish public holidays, and adds work days to a date. In Turkish.", + about: [ + "Counts Monday to Friday between two dates and takes out Turkish public holidays, with the bayram dates Diyanet publishes for 2022 to 2035.", + "Adds or subtracts work days, with options for Saturday work and the half-day arefe. The page is in Turkish only.", + ], + demo: "yas", + demoBefore: "January 2026", + demoBirth: "31 days", + demoAfter: "Work days", + demoAge: "21", + badge: "Turkish", + }, + tr: { + path: "/tr/is-gunu-hesaplama/", + name: "İş günü hesaplama", + blurb: "İki tarih arasındaki iş gününü hafta sonu ve resmî tatiller hariç sayar, bir tarihe iş günü ekler ya da çıkarır; arefe yarım gün sayılır.", + about: [ + "İki tarih arasındaki iş gününü hafta sonlarını ve resmî tatilleri düşerek sayar. 2022-2035 bayram tarihleri Diyanet'in resmî tatil listelerinden gelir.", + "Bir tarihe iş günü ekler ya da çıkarır. Cumartesiyi iş günü sayabilir, arefeyi yarım gün, tam gün ya da tatil olarak seçebilirsin.", + ], + demo: "yas", + demoBefore: "Ocak 2026", + demoBirth: "31 gün", + demoAfter: "İş günü", + demoAge: "21", + }, + }, ]; const tool = TOOLS[0]; @@ -4485,7 +4520,7 @@ const trGun = { title: "Hafta içi günler ve resmî tatiller", paragraphs: [ "Hafta içi satırı aradaki pazartesi-cuma günlerini, hafta sonu satırı cumartesi ve pazarları sayar. Bitiş gününü de say işaretliyse bitiş günü de bu sayıma girer.", - `Resmî tatiller düşülmez. ${a(GUN_SRC.tatil, "2429 sayılı Kanun'a")} göre 1 Ocak, 23 Nisan, 1 Mayıs, 19 Mayıs, 15 Temmuz, 30 Ağustos ve 29 Ekim genel tatildir; 29 Ekim tatili 28 Ekim saat 13.00'te başlar. Ramazan Bayramı arefe günü öğleden sonrasıyla 3,5 gün, Kurban Bayramı 4,5 gün sürer. Bu iki bayram ay takvimine göre belirlendiği için her yıl yaklaşık 11 gün öne kayar. İş günü sayıyorsan aralığa düşen tatil günlerini hafta içi sayısından kendin çıkar.`, + `Resmî tatiller düşülmez. ${a(GUN_SRC.tatil, "2429 sayılı Kanun'a")} göre 1 Ocak, 23 Nisan, 1 Mayıs, 19 Mayıs, 15 Temmuz, 30 Ağustos ve 29 Ekim genel tatildir; 29 Ekim tatili 28 Ekim saat 13.00'te başlar. Ramazan Bayramı arefe günü öğleden sonrasıyla 3,5 gün, Kurban Bayramı 4,5 gün sürer. Bu iki bayram ay takvimine göre belirlendiği için her yıl yaklaşık 11 gün öne kayar. Tatilleri ve arefe yarım günlerini de düşen sayım için İş günü hesaplama sayfasını kullan.`, ], note: "2429 sayılı Kanun 2 Aralık 2026'da mevzuat.gov.tr'deki güncel metinden kontrol edildi.", }, @@ -4528,7 +4563,7 @@ const trGun = { }, { q: "İş günü hesaplanabilir mi?", - a: "Hafta içi satırı pazartesi-cuma günlerini sayar. Resmî tatiller ülkeye ve yıla göre değiştiği için düşülmez; aralığa giren bayram ve tatil günlerini bu sayıdan kendin çıkar.", + a: 'Hafta içi satırı pazartesi-cuma günlerini sayar, resmî tatilleri düşmez. Hafta sonu ve resmî tatiller hariç iş günü sayısı için İş günü hesaplama sayfasını kullan; o sayfa bayram tarihlerini Diyanet\'in listesinden alır ve arefeyi yarım gün sayar.', }, { q: "Excel'de iki tarih arasındaki gün nasıl bulunur?", @@ -4542,8 +4577,234 @@ const trGun = { }; trGun.jsonLd = [toolPage("tr", trGun, days), faqLd(trGun.faq)]; +const isGunu = TOOLS.find((t) => t.id === "is-gunu-hesaplama"); +const ISG_SRC = { + tatil: GUN_SRC.tatil, + netdays: "https://support.microsoft.com/tr-tr/excel/functions/networkdays-intl-function", + workday: "https://support.microsoft.com/tr-tr/excel/functions/workday-intl-function", +}; + +/** Diyanet's yearly "Resmi Tatil Günleri" pages; 2022 has its own address, later years are content pages. */ +const DIYANET_YEAR = Object.fromEntries( + [2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035].map((y, i) => [ + y, + y === 2022 ? "https://vakithesaplama.diyanet.gov.tr/resmitatiller.php?yil=2022" : `https://vakithesaplama.diyanet.gov.tr/icerik.php?icerik=${[155, 156, 157, 158, 159, 193, 194, 195, 196, 197, 198, 199, 200][i - 1]}`, + ]), +); + +/** "19-22 Mart" or "28 Şubat - 4 Mart": the arefe through the last bayram day. */ +function bayramSpan(b) { + const end = addDays(b.arefe, b.kind === "ramazan" ? 3 : 4); + return end.m === b.arefe.m ? `${b.arefe.d}-${end.d} ${AYLAR[end.m - 1]}` : `${b.arefe.d} ${AYLAR[b.arefe.m - 1]} - ${end.d} ${AYLAR[end.m - 1]}`; +} + +function bayramTable() { + const rows = []; + for (let y = SOURCE_YEARS.first; y <= SOURCE_YEARS.last; y++) { + const cell = (kind) => + BAYRAMS.filter((b) => b.kind === kind && b.arefe.y === y) + .map(bayramSpan) + .join(", ") || "-"; + rows.push(`${y}${cell("ramazan")}${cell("kurban")}${formatValue(yearTotal(y))}`); + } + return `
${rows.join("")}
Arefe günüyle birlikte bayram tarihleri ve yılın iş günü sayısı (cumartesi tatil, arefe ve 28 Ekim yarım gün). Yıl bağlantısı Diyanet'in o yılki listesini açar.
Yıl${BAYRAM_NAMES.ramazan}${BAYRAM_NAMES.kurban}İş günü
`; +} + +const ramazan27 = BAYRAMS.find((b) => b.kind === "ramazan" && b.arefe.y === 2027); +const kurban27 = BAYRAMS.find((b) => b.kind === "kurban" && b.arefe.y === 2027); +const bayramDays = (b) => { + const first = addDays(b.arefe, 1); + const last = addDays(b.arefe, b.kind === "ramazan" ? 3 : 4); + return `${first.d}-${last.d} ${AYLAR[last.m - 1]}`; +}; +const y2026 = countBusinessDays({ y: 2026, m: 1, d: 1 }, { y: 2026, m: 12, d: 31 }); +const jan2026 = countBusinessDays({ y: 2026, m: 1, d: 1 }, { y: 2026, m: 1, d: 31 }); + +const trIsGunu = { + kind: "tool", + tool: "isgunu", + script: "is-gunu-hesaplama.js", + lang: "tr", + path: isGunu.tr.path, + og: "is-gunu-hesaplama", + title: "İş günü hesaplama: resmî tatiller ve hafta sonu hariç", + ogTitle: "İş günü hesaplama", + description: "İki tarih arasındaki iş gününü hafta sonu ve resmî tatiller hariç hesapla, tarihe iş günü ekle. Bayramlar Diyanet listesinden, arefe yarım gün.", + h1: "İki tarih arası iş günü hesaplama", + lede: `Başlangıç ve bitiş tarihini seç; hafta sonları ve resmî tatiller düşülmüş iş günü sayısı çıksın, aralığa denk gelen tatiller de tek tek listelensin. Alttaki hesaplayıcı bir tarihe iş günü ekler ya da çıkarır. ${SOURCE_YEARS.first}-${SOURCE_YEARS.last} arasındaki Ramazan ve Kurban bayramı tarihleri Diyanet İşleri Başkanlığı'nın resmî tatil listelerinden alındı. Girdiğin tarihler hiçbir yere gönderilmez.`, + ui: { + toolLabel: "İş günü hesaplama", + optionsLabel: "Sayım ayarları", + holidays: "Resmî tatilleri düş", + holidaysHint: "2429 sayılı Kanun'daki genel tatiller ve bayramlar.", + saturday: "Cumartesi iş günü", + saturdayHint: "Haftada altı gün çalışılan işyerleri için.", + arefe: "Arefe ve 28 Ekim", + arefes: [ + ["half", "Yarım gün"], + ["work", "Tam iş günü"], + ["off", "Tatil"], + ], + start: "Başlangıç tarihi", + end: "Bitiş tarihi", + base: "Tarih", + day: "Gün", + month: "Ay", + year: "Yıl", + dayPh: "GG", + monthPh: "Ay seç", + yearPh: "YYYY", + months: [...AYLAR], + today: "Bugün", + includeStart: "Başlangıç gününü de say", + includeStartHint: "Bitiş günü her zaman sayılır. Süre başlangıcın ertesi gününden işliyorsa işareti kaldır.", + between: { + title: "İki tarih arası iş günü", + question: "Örnek: 1-31 Ocak 2026 arasında kaç iş günü var?", + }, + shift: { + title: "Tarihe iş günü ekle ya da çıkar", + question: "Örnek: 2 Aralık 2026'dan 20 iş günü sonra hangi tarih?", + result: "Sonuç tarihi", + }, + opLabel: "İş günü eklensin mi çıkarılsın mı?", + ops: [ + ["add", "İş günü ekle"], + ["sub", "İş günü çıkar"], + ], + shiftDays: "İş günü sayısı", + shiftPh: "Örneğin 20", + resultLabel: "İş günü sayısı", + calendar: "Takvim günü", + weekend: "Hafta sonu", + holidayRow: "Hafta içine denk gelen tatil", + halfRow: "Yarım gün (arefe, 28 Ekim)", + shiftCalendar: "Takvim günü farkı", + holTitle: "Aralıktaki tatiller", + shiftHolTitle: "Atlanan tatiller", + holDate: "Tarih", + holName: "Tatil", + holEffect: "Sayıma etkisi", + formula: "Hesap", + noscript: "Bu hesaplayıcı JavaScript ister. Elle saymak için aradaki takvim günlerinden cumartesi ve pazarları, sonra hafta içine denk gelen resmî tatilleri çıkar; arefe ve 28 Ekim yarım gün sayılır.", + messages: { + workDays: "{n} iş günü", + range: "{from} ile {to} arası, iki gün de dahil.", + rangeNoStart: "{from} hariç, {to} dahil.", + days: "{n} gün", + formulaCal: "{n} takvim günü", + formulaWeekend: "{n} hafta sonu", + formulaHoliday: "{n} tatil", + formulaHalf: "{n} yarım gün x 0,5", + formulaResult: "{n} iş günü", + effectOff: "Düşüldü", + effectHalf: "Yarım gün sayıldı", + effectWork: "İş günü sayıldı", + effectWeekend: "Hafta sonuna denk geldi", + more: "Listede ilk {shown} tatil var, aralıkta toplam {n} tatil günü bulunuyor.", + fixedOnly: "{years} için bayram tarihleri elimizde yok: bu yıllarda yalnızca sabit tarihli tatiller düşüldü, Ramazan ve Kurban bayramları düşülmedi.", + none: "{years} için tatil düşülmedi, yalnızca hafta sonları çıkarıldı: bugünkü tatil listesi 2017'den beri geçerli.", + formulaAdd: "{base} + {n} iş günü = {out}", + formulaSub: "{base} - {n} iş günü = {out}", + after: "{weekday}, {n} takvim günü sonra", + before: "{weekday}, {n} takvim günü önce", + halfOver: "Arada yarım gün olduğu için bu tarihe kadar {n} iş günü geçmiş olur; {goal} iş günü bu günde dolar.", + badStart: "Başlangıç tarihini gün, ay ve dört haneli yıl olarak gir, örneğin 1 Ocak 2026.", + badEnd: "Bitiş tarihini gün, ay ve dört haneli yıl olarak gir.", + badBase: "Tarihi gün, ay ve dört haneli yıl olarak gir.", + needStart: "Başlangıç tarihini de gir.", + needEnd: "Bitiş tarihini de gir.", + needBase: "Tarihi de gir.", + badShift: "İş günü sayısını 20 gibi bir tam sayı olarak yaz.", + noSuchDay: "{month} {year} {days} gün çekiyor, bu ayda o gün yok.", + outOfRange: "Tarihler 1 ile 9999 yılları arasında kalmalı.", + swapped: "Bitiş tarihi başlangıçtan önceydi, hesaplayıcı ikisinin yerini değiştirdi.", + }, + }, + sections: [ + { + id: "nasil", + title: "İş günü nasıl hesaplanır?", + paragraphs: [ + `İş günü, hafta sonu ya da resmî tatil olmayan gündür. İki tarih arasındaki iş gününü bulmak için aradaki takvim günlerinden önce cumartesi ve pazarlar, sonra hafta içine denk gelen resmî tatiller çıkarılır. Ocak 2026'nın ${jan2026.calendarDays} gününden ${jan2026.weekendDays}'u hafta sonu, 1 Ocak da tatil olduğu için ayda ${formatValue(jan2026.value)} iş günü vardır.`, + "Hesaplayıcı başlangıç ve bitiş gününü de sayar; ikisi aynı iş günüyse sonuç 1 iş günüdür. İlk günün sayılmadığı, sürenin ertesi günden işlediği durumlarda Başlangıç gününü de say işaretini kaldır.", + `İş günü eklerken başlangıç tarihi sayılmaz, sayım ertesi günden başlar. 2 Aralık 2026'ya 20 iş günü eklenince 30 Aralık 2026 çıkar: araya giren dört hafta sonu atlanır. Araya bir bayram girerse sonuç o kadar ileri kayar.`, + "Arefe yarım gün sayıldığında eklenen iş günü her zaman tam bir güne denk gelmez. Böyle bir durumda sonuç, istenen iş gününün dolduğu ilk gündür. 18 Mart 2026'ya 1 iş günü eklenince 23 Mart çıkar, çünkü 19 Mart Ramazan Bayramı arefesi, 20 Mart da bayramın ilk günüdür.", + ], + }, + { + id: "tatiller", + title: "Resmî tatiller ve arefe günleri", + paragraphs: [ + `${a(ISG_SRC.tatil, "2429 sayılı Ulusal Bayram ve Genel Tatiller Hakkında Kanun'a")} göre her yıl aynı tarihte gelen genel tatiller 1 Ocak, 23 Nisan, 1 Mayıs, 19 Mayıs, 15 Temmuz, 30 Ağustos ve 29 Ekim'dir. Cumhuriyet Bayramı 28 Ekim saat 13.00'te başlar.`, + `Kanuna göre Ramazan Bayramı arefe günü saat 13.00'ten itibaren 3,5 gün, Kurban Bayramı 4,5 gün sürer. Bu bayramlar hicri takvime göre belirlendiği için her yıl yaklaşık 11 gün öne kayar. Hesaplayıcı ${SOURCE_YEARS.first}-${SOURCE_YEARS.last} bayram tarihlerini Diyanet İşleri Başkanlığı'nın yıllık resmî tatil listelerinden alır. Bu aralığın dışındaki yıllarda yalnızca sabit tarihli tatiller düşülür ve sonucun altında bunu söyleyen bir uyarı çıkar. 15 Temmuz tatili 2016'da 6752 sayılı Kanun'la eklendiği için 2017'den önceki yıllarda hiç tatil düşülmez.`, + "Arefe günleri ve 28 Ekim, sabah çalışılan ve saat 13.00'ten sonra tatil olan yarım günlerdir. Hesaplayıcı bunları varsayılan olarak yarım iş günü sayar, bu yüzden sonuç 249,5 gibi buçuklu çıkabilir. Bu günleri tam gün çalışılmış ya da tamamen tatil saymak istersen Arefe ve 28 Ekim seçeneğini değiştir.", + "Bayram hafta içine uzandığında kamu personeline Cumhurbaşkanlığı genelgesiyle idari izin verilebilir. İdari izin resmî tatil değildir; hesaplayıcı bu günleri iş günü sayar.", + ], + html: bayramTable(), + note: `2429 sayılı Kanun 2 Aralık 2026'da mevzuat.gov.tr'deki güncel metinden, bayram tarihleri aynı gün Diyanet İşleri Başkanlığı'nın ${SOURCE_YEARS.first}-${SOURCE_YEARS.last} resmî tatil listelerinden kontrol edildi.`, + }, + { + id: "cumartesi", + title: "Cumartesi iş günü sayılır mı?", + paragraphs: [ + "Hesaplayıcı cumartesi ve pazarı varsayılan olarak hafta sonu sayar. Cumartesi de çalışılan bir işyeri için Cumartesi iş günü seçeneğini aç: yalnızca pazarlar düşülür, cumartesiye denk gelen bayram günleri ise tatil olarak çıkarılır.", + "2429 sayılı Kanun'un 2. maddesi, cuma akşamı sona eren bir bayram ya da genel tatilden sonraki cumartesinin de tamamen tatil yapılacağını söyler. Hesaplayıcı bu cumartesileri ayrıca düşmez; cumartesiyi iş günü sayıyorsan ve aralıkta böyle bir hafta varsa sonucu buna göre kontrol et.", + ], + }, + ], + faqTitle: "Sık sorulanlar", + faq: [ + { + q: "İş günü nasıl hesaplanır?", + a: `İki tarih arasındaki takvim günlerinden hafta sonları ve hafta içine denk gelen resmî tatiller çıkarılır. Arefe ve 28 Ekim yarım gün sayılırsa her biri yarım gün düşer. 1-31 Ocak 2026 arasında ${jan2026.calendarDays} takvim gününden ${jan2026.weekendDays} hafta sonu günü ve 1 Ocak çıkınca ${formatValue(jan2026.value)} iş günü kalır.`, + }, + { + q: "İki tarih arasında iş günü nasıl hesaplanır?", + a: "Başlangıç ve bitiş tarihini gir; iki gün de sayıma girer. İlk gün sayılmayacaksa Başlangıç gününü de say işaretini kaldır. Sonucun altında takvim günü, hafta sonu ve tatil sayısı ile aralıktaki her tatilin sayıma etkisi görünür.", + }, + { + q: "1 haftada kaç iş günü var?", + a: "Cumartesi ve pazarın tatil olduğu düzende haftada 5, cumartesi de çalışılan düzende 6 iş günü vardır. Haftaya bir tatil denk gelirse sayı düşer: 25-29 Mayıs 2026 haftasında yalnızca pazartesi tam iş günüdür, salı Kurban Bayramı arefesi olduğu için yarım gündür ve toplam 1,5 iş günü eder.", + }, + { + q: "İş günü cumartesi dahil mi?", + a: "Cumartesinin iş günü sayılıp sayılmadığı işyerinin çalışma düzenine bağlıdır. Hesaplayıcı cumartesiyi varsayılan olarak tatil sayar; altı gün çalışılan bir işyeri için Cumartesi iş günü seçeneğini aç.", + }, + { + q: "Resmî tatil iş günü sayılır mı?", + a: "Hayır. Hafta içine denk gelen resmî tatil iş günü sayılmaz ve hesaplayıcı onu düşer. Hafta sonuna denk gelen tatil zaten iş günü olmadığı için sonucu değiştirmez; listede Hafta sonuna denk geldi olarak görünür.", + }, + { + q: "Arefe günü iş günü mü?", + a: "Ramazan ve Kurban bayramı arefesi ile 28 Ekim, saat 13.00'e kadar çalışılan yarım günlerdir. Hesaplayıcı bunları yarım iş günü sayar; istersen tam iş günü ya da tatil olarak da seçebilirsin.", + }, + { + q: "Resmî tatil günleri nasıl belirlenir?", + a: `Sabit tarihli tatiller 2429 sayılı Kanun'da yazılıdır ve her yıl aynı tarihe gelir. Ramazan ve Kurban bayramı hicri takvime göre belirlenir, tarihlerini Diyanet İşleri Başkanlığı yayımlar. 2027'de Ramazan Bayramı ${bayramDays(ramazan27)}, Kurban Bayramı ${bayramDays(kurban27)} tarihlerindedir; arefeleri ${tarih(ramazan27.arefe)} ${GUNLER[weekday(ramazan27.arefe)]} ve ${tarih(kurban27.arefe)} ${GUNLER[weekday(kurban27.arefe)]} günüdür.`, + }, + { + q: "2026 yılında kaç iş günü var?", + a: `Cumartesi tatil, arefe ve 28 Ekim yarım gün sayıldığında 2026'da ${formatValue(yearTotal(2026))}, 2027'de ${formatValue(yearTotal(2027))} iş günü vardır. 2026'da hafta içine ${y2026.holidayDays} tam gün tatil ve ${y2026.halfDays} yarım gün denk gelir. Öteki yıllar yukarıdaki tabloda.`, + }, + { + q: "Excel'de iş günü nasıl hesaplanır?", + a: `${a(ISG_SRC.netdays, "TAMİŞGÜNÜ.ULUSL")} işlevi iki tarih arasındaki iş gününü, ${a(ISG_SRC.workday, "İŞGÜNÜ.ULUSL")} bir tarihe iş günü eklenmiş tarihi verir. İşlevler resmî tatilleri kendiliğinden bilmez; tarihlerini bir hücre aralığına yazıp tatiller bağımsız değişkenine vermen gerekir. Hafta sonu bağımsız değişkenine 11 yazarsan yalnızca pazar tatil sayılır. Bu işlevler tam günlerle çalışır; arefe gibi yarım günleri ya iş günü ya da tatil olarak girebilirsin.`, + }, + { + q: "İki tarih arasında kaç gün var?", + a: 'Takvim günü satırı, hafta sonları ve tatiller dahil aradaki gün sayısını verir. Yıl, ay ve hafta olarak süre için Gün hesaplama sayfasını kullan.', + }, + { + q: "Girdiğim tarihler bir yere kaydediliyor mu?", + a: "Hayır. Hesap bu sekmedeki JavaScript ile yapılır, tarihler hiçbir sunucuya gönderilmez. Sayfa yalnızca seçtiğin ayarları bu tarayıcıda hatırlar. Sayfa görüntülemeleri Cloudflare Web Analytics ile sayılır, girdiğin tarihleri görmez.", + }, + ], +}; +trIsGunu.jsonLd = [toolPage("tr", trIsGunu, isGunu), faqLd(trIsGunu.faq)]; + export const pages = { - list: [enHome, trHome, enTool, trTool, enCompare, trCompare, trKdv, trYas, enDays, enLines, enCase, trCase, enHex, enInvisible, trInvisible, enRepeat, enReverse, enFlip, trFlip, enChmod, enSlug, enSpecial, trSpecial, trCounter, enFrequency, trYuzde, trOrtalama, trGun], + list: [enHome, trHome, enTool, trTool, enCompare, trCompare, trKdv, trYas, enDays, enLines, enCase, trCase, enHex, enInvisible, trInvisible, enRepeat, enReverse, enFlip, trFlip, enChmod, enSlug, enSpecial, trSpecial, trCounter, enFrequency, trYuzde, trOrtalama, trGun, trIsGunu], notFound: { title: "Page not found: Halit Sever's tools", description: "This page does not exist on tools.halit.org. The list of small browser tools by Halit Sever is one click away, in English and in Turkish.", diff --git a/scripts/og.mjs b/scripts/og.mjs index e4cfd20..fd4f5c5 100644 --- a/scripts/og.mjs +++ b/scripts/og.mjs @@ -129,6 +129,7 @@ const [enHome, trHome] = pages.list; const [t, cmp, kdv, yas, days, lines, cases, colors, blanks, repeater, reversal, flips, chmods, slugs, specials, counters, frequencies] = TOOLS; const yuzde = TOOLS.find((x) => x.id === "yuzde-hesaplama"); const ortalama = TOOLS.find((x) => x.id === "ortalama-hesaplama"); +const isGunu = TOOLS.find((x) => x.id === "is-gunu-hesaplama"); const cards = [ { file: "home", label: "Tools", title: enHome.h1, sub: enHome.lede, url: "tools.halit.org" }, { file: "home-tr", label: "Araçlar", title: trHome.h1, sub: trHome.lede, url: "tools.halit.org/tr" }, @@ -157,6 +158,7 @@ const cards = [ { file: "yuzde-hesaplama", label: "Araçlar", title: yuzde.tr.name, sub: "Yüzde, artış, azalış, indirim ve zam; her sonuç formülüyle.", url: "tools.halit.org/tr/yuzde-hesaplama", tool: { ...yuzde.tr, name: "" } }, { file: "ortalama-hesaplama", label: "Araçlar", title: ortalama.tr.name, sub: "Aritmetik ve ağırlıklı ortalama, medyan ve açıklık; formülüyle.", url: "tools.halit.org/tr/ortalama-hesaplama", tool: { ...ortalama.tr, name: "" } }, { file: "gun-hesaplama", label: "Araçlar", title: days.tr.name, sub: "İki tarih arası kaç gün, hafta ve ay; tarihe gün ekle ya da çıkar.", url: "tools.halit.org/tr/gun-hesaplama", tool: { ...days.tr, name: "" } }, + { file: "is-gunu-hesaplama", label: "Araçlar", title: isGunu.tr.name, sub: "İki tarih arası iş günü, hafta sonu ve resmî tatiller hariç; tarihe iş günü ekle.", url: "tools.halit.org/tr/is-gunu-hesaplama", tool: { ...isGunu.tr, name: "" } }, { file: "metin-karsilastirma", label: "Araçlar", title: cmp.tr.name, sub: "İki metin arasında eklenen ve silinen satırları, kelimeleri gör.", url: "tools.halit.org/tr/metin-karsilastirma", tool: { ...cmp.tr, name: "" } }, ]; diff --git a/src/is-gunu-hesaplama.js b/src/is-gunu-hesaplama.js new file mode 100644 index 0000000..b1ee5a3 --- /dev/null +++ b/src/is-gunu-hesaplama.js @@ -0,0 +1,204 @@ +/** Wires the iş günü hesaplama page. Dates stay in this tab: no network call, and only the options are stored. */ +import { parseDate, parseDateText, daysInMonth, weekday, formatDate, formatNumber, MONTHS, WEEKDAYS } from "./yas.js"; +import { countBusinessDays, shiftBusinessDays, formatValue } from "./is-gunu.js"; + +const $ = (id) => document.getElementById(id); +const t = JSON.parse($("strings").textContent); +const KEY = "tools.is-gunu-hesaplama.options"; +const fields = (p) => ({ d: $(`${p}-d`), m: $(`${p}-m`), y: $(`${p}-y`) }); +const F = { start: fields("start"), end: fields("end"), base: fields("base") }; +const holidays = $("holidays"); +const saturday = $("saturday"); +const includeStart = $("include-start"); +const shiftInput = $("shift-days"); +const radios = (name) => [...document.querySelectorAll(`input[name="${name}"]`)]; +const ops = radios("op"); +const arefes = radios("arefe"); +const picked = (list, fallback) => list.find((r) => r.checked)?.value ?? fallback; +const fill = (tpl, map) => tpl.replace(/\{(\w+)\}/g, (_, k) => map[k] ?? ""); +/** Long ranges can hold thousands of holidays; the first ones are enough to check a result. */ +const MAX_ROWS = 40; + +/** Read at every use so a tab left open past midnight moves to the new day. */ +function today() { + const now = new Date(); + return { y: now.getFullYear(), m: now.getMonth() + 1, d: now.getDate() }; +} + +const opts = () => ({ holidays: holidays.checked, saturday: saturday.checked, arefe: picked(arefes, "half") }); + +function load() { + try { + const o = JSON.parse(localStorage.getItem(KEY) || "{}"); + if (typeof o.holidays === "boolean") holidays.checked = o.holidays; + if (typeof o.saturday === "boolean") saturday.checked = o.saturday; + if (typeof o.includeStart === "boolean") includeStart.checked = o.includeStart; + for (const [list, v] of [ + [ops, o.op], + [arefes, o.arefe], + ]) + if (list.some((r) => r.value === v)) for (const r of list) r.checked = r.value === v; + } catch {} +} + +function save() { + try { + localStorage.setItem(KEY, JSON.stringify({ ...opts(), includeStart: includeStart.checked, op: picked(ops, "add") })); + } catch {} +} + +const read = (f) => parseDate(f.d.value, f.m.value, f.y.value); +const empty = (f) => !f.d.value.trim() && !f.m.value && !f.y.value.trim(); +const complete = (f) => f.d.value.trim() && f.m.value && f.y.value.trim().length === 4; +const long = (date) => `${formatDate(date)} ${WEEKDAYS[weekday(date)]}`; + +function set(f, date) { + f.d.value = String(date.d); + f.m.value = String(date.m); + f.y.value = String(date.y); +} + +/** Names the missing day, e.g. "Şubat 2023 28 gün çekiyor", which says more than a generic error. */ +function dateError(f, generic) { + const d = Number(f.d.value); + const m = Number(f.m.value); + const y = Number(f.y.value); + if (/^\d{4}$/.test(f.y.value.trim()) && m && d > daysInMonth(y, m) && d <= 31) return fill(t.noSuchDay, { month: MONTHS[m - 1], year: y, days: daysInMonth(y, m) }); + return generic; +} + +/** "2036-2040" for a run of years, commas between runs. */ +function yearsText(list) { + const runs = []; + for (const y of list) { + const last = runs.at(-1); + if (last && y === last[1] + 1) last[1] = y; + else runs.push([y, y]); + } + return runs.map(([a, b]) => (a === b ? String(a) : `${a}-${b}`)).join(", "); +} + +function yearsNote(el, years) { + const parts = []; + if (years.none.length) parts.push(fill(t.none, { years: yearsText(years.none) })); + if (years.fixedOnly.length) parts.push(fill(t.fixedOnly, { years: yearsText(years.fixedOnly) })); + el.textContent = parts.join(" "); +} + +const effect = (h) => (h.weekend ? t.effectWeekend : h.value === 0 ? t.effectOff : h.value === 1 ? t.effectWork : t.effectHalf); + +function holidayRows(id, list) { + const wrap = $(`${id}-wrap`); + const body = $(`${id}-body`); + const rows = list.slice(0, MAX_ROWS).map((h) => { + const tr = document.createElement("tr"); + for (const text of [long(h.date), h.name, effect(h)]) { + const td = document.createElement("td"); + td.textContent = text; + tr.append(td); + } + return tr; + }); + body.replaceChildren(...rows); + $(`${id}-more`).textContent = list.length > MAX_ROWS ? fill(t.more, { shown: MAX_ROWS, n: formatNumber(list.length) }) : ""; + wrap.hidden = list.length === 0; +} + +function clearBetween(message) { + for (const id of ["count-main", "cal", "we", "hol", "half"]) $(id).textContent = "-"; + $("range").textContent = ""; + $("formula").textContent = ""; + $("years-note").textContent = ""; + $("status").textContent = message ?? ""; + holidayRows("hol", []); +} + +function renderBetween() { + const start = read(F.start); + const end = read(F.end); + if (empty(F.start) && empty(F.end)) return clearBetween(""); + if (!start) return clearBetween(complete(F.start) ? dateError(F.start, t.badStart) : empty(F.start) ? t.needStart : ""); + if (!end) return clearBetween(complete(F.end) ? dateError(F.end, t.badEnd) : empty(F.end) ? t.needEnd : ""); + const r = countBusinessDays(start, end, { ...opts(), includeStart: includeStart.checked }); + if (!r) return clearBetween(t.outOfRange); + + $("status").textContent = r.swapped ? t.swapped : ""; + $("count-main").textContent = fill(t.workDays, { n: formatValue(r.value) }); + $("range").textContent = fill(includeStart.checked ? t.range : t.rangeNoStart, { from: long(r.from), to: long(r.to) }); + $("cal").textContent = fill(t.days, { n: formatNumber(r.calendarDays) }); + $("we").textContent = fill(t.days, { n: formatNumber(r.weekendDays) }); + $("hol").textContent = fill(t.days, { n: formatNumber(r.holidayDays) }); + $("half").textContent = fill(t.days, { n: formatNumber(r.halfDays) }); + const terms = [fill(t.formulaCal, { n: formatNumber(r.calendarDays) })]; + if (r.weekendDays) terms.push(fill(t.formulaWeekend, { n: formatNumber(r.weekendDays) })); + if (r.holidayDays) terms.push(fill(t.formulaHoliday, { n: formatNumber(r.holidayDays) })); + if (r.halfDays) terms.push(fill(t.formulaHalf, { n: formatNumber(r.halfDays) })); + $("formula").textContent = `${terms.join(" - ")} = ${fill(t.formulaResult, { n: formatValue(r.value) })}`; + yearsNote($("years-note"), r.years); + holidayRows("hol", r.holidays); +} + +function clearShift(message) { + $("shift-out").textContent = "-"; + $("shift-cal").textContent = "-"; + $("shift-sub").textContent = ""; + $("shift-formula").textContent = ""; + $("shift-years").textContent = ""; + $("shift-status").textContent = message ?? ""; + holidayRows("shift-hol", []); +} + +function renderShift() { + const base = read(F.base); + const raw = shiftInput.value.trim().replace(/\./g, ""); + if (empty(F.base) && !raw) return clearShift(""); + if (!base) return clearShift(complete(F.base) ? dateError(F.base, t.badBase) : empty(F.base) ? t.needBase : ""); + if (!raw) return clearShift(""); + if (!/^\d{1,7}$/.test(raw)) return clearShift(t.badShift); + const n = Number(raw); + const sub = picked(ops, "add") === "sub"; + const r = shiftBusinessDays(base, sub ? -n : n, opts()); + if (!r) return clearShift(t.outOfRange); + $("shift-out").textContent = formatDate(r.date); + $("shift-sub").textContent = fill(sub ? t.before : t.after, { weekday: WEEKDAYS[r.weekday], n: formatNumber(r.calendarDays) }); + $("shift-cal").textContent = fill(t.days, { n: formatNumber(r.calendarDays) }); + $("shift-formula").textContent = fill(sub ? t.formulaSub : t.formulaAdd, { base: formatDate(base), n: formatNumber(n), out: formatDate(r.date) }); + $("shift-status").textContent = r.counted > n ? fill(t.halfOver, { n: formatValue(r.counted), goal: formatNumber(n) }) : ""; + yearsNote($("shift-years"), r.years); + holidayRows("shift-hol", r.holidays); +} + +const render = () => { + renderBetween(); + renderShift(); +}; + +for (const f of Object.values(F)) { + /** A whole date pasted or typed into the day field is spread over the three fields. */ + f.d.addEventListener("input", () => { + const date = parseDateText(f.d.value); + if (date) set(f, date); + render(); + }); + f.m.addEventListener("change", render); + f.y.addEventListener("input", render); +} + +for (const b of document.querySelectorAll("[data-today]")) { + b.addEventListener("click", () => { + set(F[b.dataset.today], today()); + render(); + }); +} + +for (const el of [holidays, saturday, includeStart, ...arefes, ...ops]) + el.addEventListener("change", () => { + save(); + render(); + }); +shiftInput.addEventListener("input", renderShift); + +load(); +set(F.start, today()); +set(F.base, today()); +render(); diff --git a/src/is-gunu.js b/src/is-gunu.js new file mode 100644 index 0000000..41a9457 --- /dev/null +++ b/src/is-gunu.js @@ -0,0 +1,196 @@ +/** Business days in Turkey: weekends, the general holidays of Law 2429 and the bayram dates Diyanet publishes. Dates are plain { y, m, d } objects. */ +import { isValidDate, dayNumber, fromDayNumber, weekday, formatNumber } from "./yas.js"; + +/** Years whose bayram dates come from Diyanet's official holiday lists; outside them only the fixed-date holidays are known. */ +export const SOURCE_YEARS = Object.freeze({ first: 2022, last: 2035 }); + +/** 15 Temmuz joined the list through Law 6752 in late 2016, so today's fixed-date list holds from 2017 on. */ +export const FIXED_SINCE = 2017; + +/** Arefe day of each bayram from Diyanet's "Resmi Tatil Günleri" pages; Ramazan Bayramı lasts 3 days after it, Kurban Bayramı 4. 2033 has two Ramazan bayrams. */ +export const BAYRAMS = Object.freeze( + [ + ["ramazan", 2022, 5, 1], + ["kurban", 2022, 7, 8], + ["ramazan", 2023, 4, 20], + ["kurban", 2023, 6, 27], + ["ramazan", 2024, 4, 9], + ["kurban", 2024, 6, 15], + ["ramazan", 2025, 3, 29], + ["kurban", 2025, 6, 5], + ["ramazan", 2026, 3, 19], + ["kurban", 2026, 5, 26], + ["ramazan", 2027, 3, 8], + ["kurban", 2027, 5, 15], + ["ramazan", 2028, 2, 25], + ["kurban", 2028, 5, 4], + ["ramazan", 2029, 2, 13], + ["kurban", 2029, 4, 23], + ["ramazan", 2030, 2, 3], + ["kurban", 2030, 4, 12], + ["ramazan", 2031, 1, 23], + ["kurban", 2031, 4, 1], + ["ramazan", 2032, 1, 13], + ["kurban", 2032, 3, 21], + ["ramazan", 2033, 1, 1], + ["kurban", 2033, 3, 10], + ["ramazan", 2033, 12, 22], + ["kurban", 2034, 2, 28], + ["ramazan", 2034, 12, 11], + ["kurban", 2035, 2, 17], + ["ramazan", 2035, 11, 30], + ].map(([kind, y, m, d]) => Object.freeze({ kind, arefe: Object.freeze({ y, m, d }) })), +); + +export const BAYRAM_NAMES = Object.freeze({ ramazan: "Ramazan Bayramı", kurban: "Kurban Bayramı" }); +const BAYRAM_DAYS = { ramazan: 3, kurban: 4 }; + +/** Month, day, name and whether only the afternoon is off (28 Ekim from 13.00). */ +export const FIXED = Object.freeze([ + [1, 1, "Yılbaşı", false], + [4, 23, "Ulusal Egemenlik ve Çocuk Bayramı", false], + [5, 1, "Emek ve Dayanışma Günü", false], + [5, 19, "Atatürk'ü Anma, Gençlik ve Spor Bayramı", false], + [7, 15, "Demokrasi ve Millî Birlik Günü", false], + [8, 30, "Zafer Bayramı", false], + [10, 28, "Cumhuriyet Bayramı arifesi", true], + [10, 29, "Cumhuriyet Bayramı", false], +]); + +/** "full" when the year's bayram dates are known, "fixed" when only the fixed-date holidays apply, "none" before today's list existed. */ +export function coverage(y) { + if (y >= SOURCE_YEARS.first && y <= SOURCE_YEARS.last) return "full"; + return y >= FIXED_SINCE ? "fixed" : "none"; +} + +const cache = new Map(); + +/** The holidays of one year in date order. Two holidays on the same day become one entry, and a full day beats a half day. */ +export function holidaysOf(y) { + if (cache.has(y)) return cache.get(y); + const byDay = new Map(); + const add = (date, name, half) => { + if (date.y !== y) return; + const n = dayNumber(date); + const prev = byDay.get(n); + if (!prev) return byDay.set(n, { date, day: n, names: [name], half }); + prev.names.push(name); + prev.half = prev.half && half; + }; + if (coverage(y) !== "none") for (const [m, d, name, half] of FIXED) add({ y, m, d }, name, half); + if (coverage(y) === "full") + for (const b of BAYRAMS) { + const start = dayNumber(b.arefe); + add(b.arefe, `${BAYRAM_NAMES[b.kind]} arefesi`, true); + for (let i = 1; i <= BAYRAM_DAYS[b.kind]; i++) add(fromDayNumber(start + i), `${BAYRAM_NAMES[b.kind]} ${i}. gün`, false); + } + const list = [...byDay.values()].sort((a, b) => a.day - b.day).map((h) => Object.freeze({ date: h.date, day: h.day, name: h.names.join(", "), half: h.half })); + const out = { list, byDay: new Map(list.map((h) => [h.day, h])) }; + cache.set(y, out); + return out; +} + +const DEFAULTS = { saturday: false, holidays: true, arefe: "half" }; + +/** The last year looked up, so a long range does not rebuild a date for every day. */ +let span = { y: 0, lo: 1, hi: 0 }; +function yearOfDay(n) { + if (n < span.lo || n > span.hi) { + const y = fromDayNumber(n).y; + span = { y, lo: dayNumber({ y, m: 1, d: 1 }), hi: dayNumber({ y, m: 12, d: 31 }) }; + } + return span.y; +} + +/** + * How much of a work day one date is: 1, 0.5 or 0. Sundays and, unless `saturday` is set, Saturdays are off. + * `arefe` decides the afternoon-off days: "half" counts them as half a day, "work" as a whole one and "off" as a holiday. + */ +function valueOf(n, opts) { + const wd = (((n + 3) % 7) + 7) % 7; + const weekend = wd === 6 || (wd === 5 && !opts.saturday); + const holiday = opts.holidays ? holidaysOf(yearOfDay(n)).byDay.get(n) : undefined; + if (weekend) return { value: 0, weekend, holiday }; + if (!holiday) return { value: 1, weekend, holiday }; + if (!holiday.half) return { value: 0, weekend, holiday }; + return { value: opts.arefe === "work" ? 1 : opts.arefe === "off" ? 0 : 0.5, weekend, holiday }; +} + +function yearsNote(firstYear, lastYear, opts) { + const fixedOnly = []; + const none = []; + if (opts.holidays) + for (let y = firstYear; y <= lastYear; y++) { + const c = coverage(y); + if (c === "fixed") fixedOnly.push(y); + if (c === "none") none.push(y); + } + return { fixedOnly, none }; +} + +/** + * Work days from `start` to `end`, the end date included. `includeStart` false leaves the start date out, as a deadline counted from a notice does. + * Dates in the wrong order are swapped and flagged. Returns null for an invalid date. + */ +export function countBusinessDays(start, end, options = {}) { + if (!isValidDate(start) || !isValidDate(end)) return null; + const opts = { ...DEFAULTS, includeStart: true, ...options }; + let a = dayNumber(start); + let b = dayNumber(end); + const swapped = b < a; + if (swapped) [a, b] = [b, a]; + const from = fromDayNumber(a); + const to = fromDayNumber(b); + const first = opts.includeStart ? a : a + 1; + let value = 0; + let workDays = 0; + let halfDays = 0; + let weekendDays = 0; + let holidayDays = 0; + const holidays = []; + for (let n = first; n <= b; n++) { + const r = valueOf(n, opts); + value += r.value; + if (r.weekend) weekendDays++; + else if (r.value === 1) workDays++; + else if (r.value === 0.5) halfDays++; + else holidayDays++; + if (r.holiday) holidays.push({ ...r.holiday, weekend: r.weekend, value: r.value }); + } + const calendarDays = Math.max(0, b - first + 1); + return { from, to, swapped, value, workDays, halfDays, weekendDays, holidayDays, calendarDays, holidays, years: yearsNote(fromDayNumber(first).y, to.y, opts) }; +} + +/** + * The date `n` work days after `date` (before it when `n` is negative), never counting `date` itself, like Excel's WORKDAY. + * With half days the target is the first date by which at least `n` work days have passed, so `counted` can be half a day more than asked. + * Returns null for an invalid date or a result outside the years 1 to 9999. + */ +export function shiftBusinessDays(date, n, options = {}) { + if (!isValidDate(date) || !Number.isSafeInteger(n)) return null; + const opts = { ...DEFAULTS, ...options }; + const step = n < 0 ? -1 : 1; + const goal = Math.abs(n); + const lo = dayNumber({ y: 1, m: 1, d: 1 }); + const hi = dayNumber({ y: 9999, m: 12, d: 31 }); + let day = dayNumber(date); + let counted = 0; + const holidays = []; + while (counted < goal) { + day += step; + if (day < lo || day > hi) return null; + const r = valueOf(day, opts); + counted += r.value; + if (r.holiday) holidays.push({ ...r.holiday, weekend: r.weekend, value: r.value }); + } + const out = fromDayNumber(day); + const start = dayNumber(date); + const [y1, y2] = step > 0 ? [date.y, out.y] : [out.y, date.y]; + return { date: out, counted, calendarDays: Math.abs(day - start), weekday: weekday(out), holidays, years: yearsNote(y1, y2, opts) }; +} + +/** Work days in a whole calendar year. */ +export const yearTotal = (y, options = {}) => countBusinessDays({ y, m: 1, d: 1 }, { y, m: 12, d: 31 }, options).value; + +/** "249,5" or "1.250": Turkish thousands dot and a decimal comma for the half day. */ +export const formatValue = (v) => formatNumber(Math.floor(v)) + (v % 1 ? ",5" : ""); diff --git a/test/is-gunu.test.mjs b/test/is-gunu.test.mjs new file mode 100644 index 0000000..7425bf7 --- /dev/null +++ b/test/is-gunu.test.mjs @@ -0,0 +1,131 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { countBusinessDays, shiftBusinessDays, holidaysOf, coverage, yearTotal, formatValue, BAYRAMS, SOURCE_YEARS } from "../src/is-gunu.js"; +import { weekday, dayNumber } from "../src/yas.js"; + +const D = (y, m, d) => ({ y, m, d }); + +test("2026 has 249.5 work days and 2027 has 249, with arefe and 28 Ekim as half days", () => { + assert.equal(yearTotal(2026), 249.5); + assert.equal(yearTotal(2027), 249); + assert.equal(yearTotal(2026, { arefe: "work" }), 251); + assert.equal(yearTotal(2026, { arefe: "off" }), 248); + assert.equal(yearTotal(2026, { holidays: false }), 261); +}); + +test("January 2026 counts both ends and drops 1 Ocak", () => { + const r = countBusinessDays(D(2026, 1, 1), D(2026, 1, 31)); + assert.equal(r.value, 21); + assert.equal(r.calendarDays, 31); + assert.equal(r.weekendDays, 9); + assert.equal(r.holidayDays, 1); + assert.deepEqual( + r.holidays.map((h) => h.name), + ["Yılbaşı"], + ); + assert.equal(countBusinessDays(D(2026, 1, 2), D(2026, 1, 31), { includeStart: false }).value, 20); + assert.equal(countBusinessDays(D(2026, 1, 1), D(2026, 1, 31), { holidays: false }).value, 22); +}); + +test("Saturday as a work day adds Saturdays but not a bayram that falls on one", () => { + const r = countBusinessDays(D(2026, 5, 25), D(2026, 5, 31), { saturday: true }); + // Mon work, Tue arefe half, Wed-Sat Kurban Bayramı, Sun off. + assert.equal(r.value, 1.5); + assert.equal(r.halfDays, 1); + assert.equal(r.holidayDays, 4); + assert.equal(r.weekendDays, 1); + assert.equal(countBusinessDays(D(2026, 6, 1), D(2026, 6, 7), { saturday: true }).value, 6); +}); + +test("holidays on a weekend are listed but take nothing off", () => { + const r = countBusinessDays(D(2026, 8, 24), D(2026, 8, 30)); + assert.equal(r.value, 5); + assert.equal(r.holidays.length, 1); + assert.equal(r.holidays[0].weekend, true); +}); + +test("dates in the wrong order are swapped and flagged", () => { + const r = countBusinessDays(D(2026, 1, 31), D(2026, 1, 1)); + assert.equal(r.swapped, true); + assert.equal(r.value, 21); + assert.deepEqual(r.from, D(2026, 1, 1)); +}); + +test("one day and an excluded start", () => { + assert.equal(countBusinessDays(D(2026, 12, 2), D(2026, 12, 2)).value, 1); + const r = countBusinessDays(D(2026, 12, 2), D(2026, 12, 2), { includeStart: false }); + assert.equal(r.value, 0); + assert.equal(r.calendarDays, 0); +}); + +test("adding work days skips weekends and holidays and leaves the start out", () => { + // Wednesday 18 March 2026: 19 is the Ramazan arefe, 20 the bayram, 21-22 a weekend. + let r = shiftBusinessDays(D(2026, 3, 18), 1); + assert.deepEqual(r.date, D(2026, 3, 23)); + assert.equal(r.counted, 1.5); + assert.deepEqual(shiftBusinessDays(D(2026, 3, 18), 1, { arefe: "work" }).date, D(2026, 3, 19)); + r = shiftBusinessDays(D(2026, 3, 23), -1); + assert.deepEqual(r.date, D(2026, 3, 18)); + assert.deepEqual(shiftBusinessDays(D(2026, 12, 4), 1).date, D(2026, 12, 7)); + assert.deepEqual(shiftBusinessDays(D(2026, 12, 2), 20).date, D(2026, 12, 30)); + assert.deepEqual(shiftBusinessDays(D(2026, 12, 2), 0).date, D(2026, 12, 2)); + assert.equal(shiftBusinessDays(D(9999, 12, 31), 1), null); + assert.equal(shiftBusinessDays(D(2026, 2, 30), 1), null); +}); + +test("adding n then counting from the day after gives n when no half day is in between", () => { + for (const [start, n] of [ + [D(2026, 12, 2), 20], + [D(2027, 5, 10), 7], + [D(2025, 3, 25), 10], + ]) { + const r = shiftBusinessDays(start, n, { arefe: "work" }); + assert.equal(countBusinessDays(start, r.date, { includeStart: false, arefe: "work" }).value, n); + } +}); + +test("Diyanet's arefe dates sit one day before a Ramazan or Kurban bayram on the weekday the lists give", () => { + const listed = { "2026-3-19": 3, "2026-5-26": 1, "2027-3-8": 0, "2027-5-15": 5, "2025-3-29": 5, "2025-6-5": 3 }; + for (const [k, wd] of Object.entries(listed)) { + const [y, m, d] = k.split("-").map(Number); + assert.ok(BAYRAMS.some((b) => b.arefe.y === y && b.arefe.m === m && b.arefe.d === d), k); + assert.equal(weekday(D(y, m, d)), wd, k); + } + for (const b of BAYRAMS) assert.ok(b.arefe.y >= SOURCE_YEARS.first && b.arefe.y <= SOURCE_YEARS.last); +}); + +test("holidays on the same day merge and a full day beats a half day", () => { + const may19 = holidaysOf(2027).byDay.get(dayNumber(D(2027, 5, 19))); + assert.equal(may19.name, "Atatürk'ü Anma, Gençlik ve Spor Bayramı, Kurban Bayramı 4. gün"); + assert.equal(may19.half, false); + const apr23 = holidaysOf(2029).byDay.get(dayNumber(D(2029, 4, 23))); + assert.equal(apr23.half, false); + assert.match(apr23.name, /Kurban Bayramı arefesi/); + assert.equal(holidaysOf(2026).list.length, 17); + assert.equal(holidaysOf(2033).list.filter((h) => /Ramazan/.test(h.name)).length, 8); +}); + +test("outside 2022-2035 only the fixed-date holidays apply, and none before 2017", () => { + assert.equal(coverage(2026), "full"); + assert.equal(coverage(2036), "fixed"); + assert.equal(coverage(2017), "fixed"); + assert.equal(coverage(2016), "none"); + assert.equal(holidaysOf(2036).list.length, 8); + assert.equal(holidaysOf(2016).list.length, 0); + const r = countBusinessDays(D(2035, 12, 1), D(2037, 1, 10)); + assert.deepEqual(r.years, { fixedOnly: [2036, 2037], none: [] }); + assert.deepEqual(countBusinessDays(D(2035, 12, 1), D(2037, 1, 10), { holidays: false }).years, { fixedOnly: [], none: [] }); + assert.deepEqual(shiftBusinessDays(D(2016, 12, 30), 1).years, { fixedOnly: [2017], none: [2016] }); +}); + +test("long ranges stay exact", () => { + const r = countBusinessDays(D(1, 1, 1), D(9999, 12, 31), { holidays: false }); + assert.equal(r.calendarDays, 3652059); + assert.equal(r.value + r.weekendDays, r.calendarDays); +}); + +test("formatValue writes Turkish numbers with a half", () => { + assert.equal(formatValue(249.5), "249,5"); + assert.equal(formatValue(1250), "1.250"); + assert.equal(formatValue(0.5), "0,5"); +});