Docly Developers
Knowledge base Pitfall Workaround available

Date.UTC returns NaN for days outside the month in Docly JavaScript

In shortIn Docly JavaScript, Date.UTC does not roll over: day 0 (the last day of the previous month) and day 35 return NaN. Calculate with whole days in milliseconds, or use only valid dates.
Applies to JavaScript
  1. 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 as Date.UTC(year, month, day + 7). In a Docly script the result is NaN, and everything built on it — a deadline, a stored timestamp — becomes 1 January 1970 or empty.

  2. What's actually happening

    Docly JavaScript implements Date.UTC without normalising values outside the valid range. Verified 2026-11-28 in a Docly script: Date.UTC(2026, 11, 5, 23, 59, 0) returned 1796515140000, while Date.UTC(2026, 10, 35, 23, 59, 0) and Date.UTC(2026, 11, 0) both returned NaN. getUTCDay, getUTCDate and toISOString worked as expected, and getTimezoneOffset threw an error.

  3. 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) or Date.UTC(year, month, day + n).

Last reviewed 28 Nov 2026