new Date("…") gives Invalid Date or the wrong day on V8
Symptoms after migrating: Invalid Date in logs, NaN in sheets, or every date showing one day early.
Why it happens
Only the ISO format is standardised. Everything else ("12/31/2025", "Dec 31 2025 10:00", "31.12.2025") is engine-specific, so Rhino and V8 disagree on some strings. And a date-only ISO string is read as UTC midnight:
new Date('2026-01-05'); // 2026-01-05T00:00Z → shows Jan 4, 7pm in New York
new Date('2026-01-05T00:00:00'); // local midnight
The fix: build dates from parts
// Fragile
var cutoff = new Date('12/31/2025');
// Explicit (local time, month is 0-based)
var cutoff = new Date(2025, 11, 31);
// Parse a known format from a sheet or API
function parseYmd(s) {
var p = s.split('-');
return new Date(+p[0], +p[1] - 1, +p[2]);
}
Dates read with Range.getValues() from real date cells are already Date objects — don't round-trip them through strings.
How V8Shift handles it
Literal M/D/YYYY strings are rewritten to new Date(y, m - 1, d) (same meaning, explicit). Other literal date strings and Date.parse() calls are flagged with advice.