Fix DateMath.cpp to compile with -Wshorten-64-to-32
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Jan 2013 18:27:23 +0000 (18:27 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Jan 2013 18:27:23 +0000 (18:27 +0000)
commitb1e624703fbc27174b5a670af066f655428281fb
tree75c3aea78bd2e0ca166d02dd9eb00dc645fcba67
parenta326aade7041bf06224a70dc0c6097486fb8b714
Fix DateMath.cpp to compile with -Wshorten-64-to-32
<http://webkit.org/b/107503>

Reviewed by Darin Adler.

Source/JavaScriptCore:

* runtime/JSDateMath.cpp:
(JSC::parseDateFromNullTerminatedCharacters): Remove unneeded
static_cast<int>().

Source/WTF:

Fixes the following build errors with -Wshorten-64-to-32:

    DateMath.cpp:742:47: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
        if (month == 2 && day > 28 && !isLeapYear(year))
                                       ~~~~~~~~~~ ^~~~
    DateMath.cpp:757:48: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
        double dateSeconds = ymdhmsToSeconds(year, month, day, hours, minutes, seconds) - timeZoneSeconds;
                             ~~~~~~~~~~~~~~~       ^~~~~
    DateMath.cpp:757:55: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
        double dateSeconds = ymdhmsToSeconds(year, month, day, hours, minutes, seconds) - timeZoneSeconds;
                             ~~~~~~~~~~~~~~~              ^~~
    DateMath.cpp:757:60: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
        double dateSeconds = ymdhmsToSeconds(year, month, day, hours, minutes, seconds) - timeZoneSeconds;
                             ~~~~~~~~~~~~~~~                   ^~~~~
    DateMath.cpp:757:67: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
        double dateSeconds = ymdhmsToSeconds(year, month, day, hours, minutes, seconds) - timeZoneSeconds;
                             ~~~~~~~~~~~~~~~                          ^~~~~~~
    DateMath.cpp:996:59: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
                        offset = ((o / 100) * 60 + (o % 100)) * sgn;
                               ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
    DateMath.cpp:998:37: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
                        offset = o * 60 * sgn;
                               ~ ~~~~~~~^~~~~
    DateMath.cpp:1005:40: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
                    offset = (o * 60 + o2) * sgn;
                           ~ ~~~~~~~~~~~~~~^~~~~
    DateMath.cpp:1041:40: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
        return ymdhmsToSeconds(year, month + 1, day, hour, minute, second) * msPerSecond;
               ~~~~~~~~~~~~~~~       ~~~~~~^~~
    DateMath.cpp:1041:45: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
        return ymdhmsToSeconds(year, month + 1, day, hour, minute, second) * msPerSecond;
               ~~~~~~~~~~~~~~~                  ^~~
    DateMath.cpp:1041:50: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
        return ymdhmsToSeconds(year, month + 1, day, hour, minute, second) * msPerSecond;
               ~~~~~~~~~~~~~~~                       ^~~~
    DateMath.cpp:1041:56: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
        return ymdhmsToSeconds(year, month + 1, day, hour, minute, second) * msPerSecond;
               ~~~~~~~~~~~~~~~                             ^~~~~~
    12 errors generated.

* wtf/DateMath.cpp:
(WTF::ymdhmsToSeconds): Change year argument from long to int.
Change mon, day, hour, minute arguments from int to long.
(WTF::parseInt): Add.  Identical to parseLong but bounds checks
for type int.
(WTF::parseLong): Switch to std::numeric_limits<long> instead of
macros.
(WTF::parseES5DatePortion): Change year argument from long to
int.
(WTF::parseES5DateFromNullTerminatedCharacters): Change year
local variable from long to int.
(WTF::parseDateFromNullTerminatedCharacters): Change year and
offset local variables from long to int.  Switch from using
parseLong() to parseInt() as needed.  Ditto for labs() to abs().
Add overflow check when switching from "MM/DD/YYYY" to
"YYYY/MM/DD" parsing.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@140437 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSDateMath.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/DateMath.cpp