import { describe, it } from 'node:test' import assert from 'node:assert/strict' import { calcOvertimeHours, DEFAULT_OVERTIME_WINDOWS, type RestDayResolver } from './oa-overtime-hours' /** 固定:2026-08-07 周五工作日,08-08 周六休息日 */ const restMap: Record = { '2026-08-07': false, '2026-08-08': true, '2026-08-09': true } function isRestDay(ymd: string): boolean { if (ymd in restMap) return restMap[ymd] const d = new Date(ymd + 'T00:00:00') const w = d.getDay() return w === 0 || w === 6 } describe('calcOvertimeHours', () => { const w = DEFAULT_OVERTIME_WINDOWS it('weekday 18:00-20:00 => 2.0', () => { assert.equal( calcOvertimeHours('2026-08-07 18:00', '2026-08-07 20:00', w, isRestDay), 2.0 ) }) it('weekday 14:00-18:00 => 0.5', () => { assert.equal( calcOvertimeHours('2026-08-07 14:00', '2026-08-07 18:00', w, isRestDay), 0.5 ) }) it('weekday 17:30 to next 08:30 => 15.0', () => { assert.equal( calcOvertimeHours('2026-08-07 17:30', '2026-08-08 08:30', w, isRestDay), 15.0 ) }) it('Saturday 09:00-15:00 => 4.0', () => { assert.equal( calcOvertimeHours('2026-08-08 09:00', '2026-08-08 15:00', w, isRestDay), 4.0 ) }) it('Fri 18:00 - Sat 12:00 => 17.5', () => { assert.equal( calcOvertimeHours('2026-08-07 18:00', '2026-08-08 12:00', w, isRestDay), 17.5 ) }) it('end <= start => null', () => { assert.equal( calcOvertimeHours('2026-08-07 20:00', '2026-08-07 18:00', w, isRestDay), null ) }) })