Changeset 48202 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Sep 9, 2009, 12:02:24 AM (16 years ago)
Author:
[email protected]
Message:

JSON.stringify(Date) loses the milliseconds information
https://bugs.webkit.org/show_bug.cgi?id=29063

Reviewed by Maciej Stachowiak.

Make sure we include milliseconds in the output of toISOString.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/DatePrototype.cpp

    r47780 r48202  
    464464    GregorianDateTime t;
    465465    thisDateObj->msToGregorianDateTime(milli, utc, t);
    466     // Maximum amount of space we need in buffer: 6 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second)
    467     // 6 for formatting and one for null termination = 23.  We add one extra character to allow us to force null termination.
    468     char buffer[24];
    469     snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02dZ", 1900 + t.year, t.month + 1, t.monthDay, t.hour, t.minute, t.second);
     466    // Maximum amount of space we need in buffer: 6 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second) + 4 (. + 3 digits for milliseconds)
     467    // 6 for formatting and one for null termination = 27.  We add one extra character to allow us to force null termination.
     468    char buffer[28];
     469    snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + t.year, t.month + 1, t.monthDay, t.hour, t.minute, t.second, static_cast<int>(fmod(milli, 1000)));
    470470    buffer[sizeof(buffer) - 1] = 0;
    471471    return jsNontrivialString(exec, buffer);
Note: See TracChangeset for help on using the changeset viewer.