summaryrefslogtreecommitdiffstats
path: root/bower_components/moment/src/lib/duration/iso-string.js
diff options
context:
space:
mode:
Diffstat (limited to 'bower_components/moment/src/lib/duration/iso-string.js')
-rw-r--r--bower_components/moment/src/lib/duration/iso-string.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/bower_components/moment/src/lib/duration/iso-string.js b/bower_components/moment/src/lib/duration/iso-string.js
new file mode 100644
index 0000000..2670a9d
--- /dev/null
+++ b/bower_components/moment/src/lib/duration/iso-string.js
@@ -0,0 +1,28 @@
+var abs = Math.abs;
+
+export function toISOString() {
+ // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
+ var Y = abs(this.years());
+ var M = abs(this.months());
+ var D = abs(this.days());
+ var h = abs(this.hours());
+ var m = abs(this.minutes());
+ var s = abs(this.seconds() + this.milliseconds() / 1000);
+ var total = this.asSeconds();
+
+ if (!total) {
+ // this is the same as C#'s (Noda) and python (isodate)...
+ // but not other JS (goog.date)
+ return 'P0D';
+ }
+
+ return (total < 0 ? '-' : '') +
+ 'P' +
+ (Y ? Y + 'Y' : '') +
+ (M ? M + 'M' : '') +
+ (D ? D + 'D' : '') +
+ ((h || m || s) ? 'T' : '') +
+ (h ? h + 'H' : '') +
+ (m ? m + 'M' : '') +
+ (s ? s + 'S' : '');
+}