From: Ash Searle Date: Tue, 8 Aug 2017 07:55:02 +0000 (+0100) Subject: Fix: Math.sign isn't supported by IE X-Git-Tag: 2.19.0~8^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b7e44c40899093f0563bebc2ed39e3c33d1521a;p=thirdparty%2Fmoment.git Fix: Math.sign isn't supported by IE --- diff --git a/src/lib/duration/iso-string.js b/src/lib/duration/iso-string.js index 721cec4a8..6f706c9b0 100644 --- a/src/lib/duration/iso-string.js +++ b/src/lib/duration/iso-string.js @@ -1,6 +1,10 @@ import absFloor from '../utils/abs-floor'; var abs = Math.abs; +function sign(x) { + return ((x > 0) - (x < 0)) || +x; +} + export function toISOString() { // for ISO strings we do not use the normal bubbling rules: // * milliseconds bubble up until they become hours @@ -39,9 +43,9 @@ export function toISOString() { var total = this.asSeconds(); var totalSign = total < 0 ? '-' : ''; - var ymSign = Math.sign(total) === Math.sign(this._months) ? '' : '-'; - var daysSign = Math.sign(total) === Math.sign(this._days) ? '' : '-'; - var hmsSign = Math.sign(total) === Math.sign(this._milliseconds) ? '' : '-'; + var ymSign = sign(total) === sign(this._months) ? '' : '-'; + var daysSign = sign(total) === sign(this._days) ? '' : '-'; + var hmsSign = sign(total) === sign(this._milliseconds) ? '' : '-'; if (!total) { // this is the same as C#'s (Noda) and python (isodate)...