Download automation/scripts/check-dates.ts from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.47 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/scripts/check-dates.ts
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/automation/scripts/check-dates.ts
-
curl -L -o check-dates.ts https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/scripts/check-dates.ts
2.47 kB
| /* Checks the Fusion date format logic (src/fusion/dates.ts) without a browser: `npx tsx scripts/check-dates.ts`. */ | |
| import assert from 'node:assert/strict'; | |
| import { FALLBACK_FORMATS, formatDate, formatFromHint, inferDateFormat, parseDate, reformat } from '../src/fusion/dates'; | |
| const d = new Date(Date.UTC(2026, 10, 14)); // 14 Nov 2026 | |
| const today = new Date(Date.UTC(2026, 10, 14, 6)); | |
| assert.equal(formatDate(d, 'dd.MM.yyyy'), '14.11.2026'); | |
| assert.equal(formatDate(d, 'M/d/yy'), '11/14/26'); | |
| assert.equal(formatDate(d, 'dd-MMM-yyyy'), '14-Nov-2026'); | |
| assert.equal(parseDate('11/14/26', 'M/d/yy')?.toISOString().slice(0, 10), '2026-11-14'); | |
| assert.equal(parseDate('14/11/26', 'M/d/yy'), null); // no 14th month | |
| assert.equal(parseDate('31.02.2026', 'dd.MM.yyyy'), null); // no 31 February | |
| // the demo pod (fa-euth-dev61): Fusion filled Terms Date with 11/14/26 | |
| assert.equal(inferDateFormat(['11/14/26', 'US1 Business Unit', '', '100'], today), 'M/d/yy'); | |
| assert.equal(inferDateFormat(['14.11.2026'], today), 'dd.MM.yyyy'); | |
| assert.equal(inferDateFormat(['14-Nov-2026'], today), 'dd-MMM-yyyy'); | |
| assert.equal(inferDateFormat(['2026-11-14'], today), 'yyyy-MM-dd'); | |
| // 11/10/26 fits both month-first and day-first: the reading nearest today wins (10 Nov, not 11 Oct) | |
| assert.equal(inferDateFormat(['11/10/26'], new Date(Date.UTC(2026, 10, 12))), 'M/d/yy'); | |
| assert.equal(inferDateFormat(['Payables', '1250.00'], today), null); | |
| assert.equal(reformat('14.11.2026', 'dd.MM.yyyy', 'M/d/yy'), '11/14/26'); | |
| assert.equal(reformat('TEST_INV_1', 'dd.MM.yyyy', 'M/d/yy'), 'TEST_INV_1'); | |
| // a field that shows no other date on its page (Create Bank Account Transfer): its own hint says the format | |
| assert.equal(formatFromHint('Example: 11/16/26', today), 'M/d/yy'); | |
| assert.equal(formatFromHint('Example: 16-Nov-2026', today), 'dd-MMM-yyyy'); | |
| assert.equal(formatFromHint('m/d/yy', today), 'M/d/yy'); | |
| assert.equal(formatFromHint('dd-mmm-yyyy', today), 'dd-MMM-yyyy'); | |
| assert.equal(formatFromHint('Transfer Date (Required)', today), null); | |
| assert.equal(formatFromHint('', today), null); | |
| // nothing to read: the common Fusion preferences are tried, month-first short year first; the old pod's last | |
| assert.equal(FALLBACK_FORMATS[0], 'M/d/yy'); | |
| assert.ok(FALLBACK_FORMATS.includes('dd.MM.yyyy')); | |
| assert.equal(reformat('16.11.2026', 'dd.MM.yyyy', FALLBACK_FORMATS[0]), '11/16/26'); | |
| console.log('dates: all checks pass'); | |