]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix: Math.sign isn't supported by IE
authorAsh Searle <ash@hexmen.com>
Tue, 8 Aug 2017 07:55:02 +0000 (08:55 +0100)
committerIskren Chernev <iskren.chernev@gmail.com>
Mon, 9 Oct 2017 22:46:58 +0000 (01:46 +0300)
src/lib/duration/iso-string.js

index 721cec4a85ced7fdd7ea171f8f657782bec1a3b2..6f706c9b06edb11a8b7b866198c1ca7405be704c 100644 (file)
@@ -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)...