Files
TORCH/src/utils.mjs
T
google-labs-jules[bot]andPR0M3TH3AN 433b81d2d3 feat: implement scheduler ratcheting by excluding completed tasks
- Update `torch-lock check` to scan `task-logs/<cadence>` for completed tasks.
- Add `--log-dir` and `--ignore-logs` flags to `check` command.
- Implement `getIsoWeekStr` utility for robust weekly cadence checking.
- Ensure completed agents are added to the `excluded` list, enabling the scheduler to skip them.
- Add comprehensive tests for log checking and date utilities.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 18:29:20 +00:00

30 lines
1.1 KiB
JavaScript

export function todayDateStr() {
return new Date().toISOString().slice(0, 10);
}
export function nowUnix() {
return Math.floor(Date.now() / 1000);
}
export function getIsoWeekStr(dateInput) {
// Parse input to ensure we work with a Date object
// If dateInput is YYYY-MM-DD string, new Date() treats it as UTC.
const d = dateInput ? new Date(dateInput) : new Date();
// If valid date, use UTC components to avoid local timezone issues
if (isNaN(d.getTime())) return '';
// Copy date so we don't mutate the original if passed by reference (though new Date() handles that)
const date = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
// ISO week date system: Thursday determines the year
// day: 0 (Sun) -> 6 (Sat). We want 1 (Mon) -> 7 (Sun)
const day = date.getUTCDay() || 7;
date.setUTCDate(date.getUTCDate() + 4 - day);
const yearStart = new Date(Date.UTC(date.getUTCFullYear(), 0, 1));
const weekNo = Math.ceil((((date - yearStart) / 86400000) + 1) / 7);
return `${date.getUTCFullYear()}-W${String(weekNo).padStart(2, '0')}`;
}