mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-28 00:11:54 +00:00
Moved the `ensureDir` utility function from `src/ops.mjs` to `src/utils.mjs` to promote code reuse and centralization. Updated `src/ops.mjs` and `src/services/memory/index.js` to use the shared utility. Added unit tests for `ensureDir` in `test/utils.test.mjs`. Co-authored-by: PR0M3TH3AN <[email protected]>
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
import fs from 'node:fs';
|
|
|
|
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')}`;
|
|
}
|
|
|
|
export function detectPlatform() {
|
|
if (process.env.JULES_API_KEY || process.env.JULES_SESSION_ID) return 'jules';
|
|
if (process.env.CODEX_API_KEY || process.env.CODEX_SESSION_ID) return 'codex';
|
|
if (process.env.GOOSE_API_KEY || process.env.GOOSE_SESSION_ID) return 'goose';
|
|
return null;
|
|
}
|
|
|
|
export function ensureDir(dir) {
|
|
if (!fs.existsSync(dir)) {
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
}
|
|
}
|