Date.UTC returns NaN for days outside the month in Docly JavaScript
-
What you'll see
Code that is normal in browsers and Node: the last day of a month as
Date.UTC(year, month + 1, 0), or a date some days ahead asDate.UTC(year, month, day + 7). In a Docly script the result isNaN, and everything built on it — a deadline, a stored timestamp — becomes 1 January 1970 or empty. -
What's actually happening
Docly JavaScript implements
Date.UTCwithout normalising values outside the valid range. Verified 2026-11-28 in a Docly script:Date.UTC(2026, 11, 5, 23, 59, 0)returned 1796515140000, whileDate.UTC(2026, 10, 35, 23, 59, 0)andDate.UTC(2026, 11, 0)both returnedNaN.getUTCDay,getUTCDateandtoISOStringworked as expected, andgetTimezoneOffsetthrew an error. -
What to do
Use only valid dates, and move in time with milliseconds:
var DAY = 24 * 3600 * 1000; // end of the day, seven days ahead - start from a valid date and add whole days var endOfToday = Date.UTC(y, m, d, 23, 59, 0); var deadline = endOfToday + 7 * DAY; // last Sunday of March or October (both have 31 days) var lastSunday = Date.UTC(y, month, 31 - new Date(Date.UTC(y, month, 31)).getUTCDay());When you add days across a change to or from daylight saving time, work out the local offset again for the result. Test date code in a scratch script on the server, not only in Node — see Use a scratch hash file to test Docly functions.
Don't:
Date.UTC(year, month + 1, 0)orDate.UTC(year, month, day + n).
Last reviewed 28 Nov 2026