diff options
| author | 2015-08-26 07:57:23 -0300 | |
|---|---|---|
| committer | 2015-08-26 07:57:23 -0300 | |
| commit | 70ceb871117ca811d63cb02671dc0fefc2700883 (patch) | |
| tree | 846133ea39797d2cd1101cff2ac0818167353490 /bower_components/moment/src/lib/duration/iso-string.js | |
| parent | 8559119e2f45b7f6508282962c0430423bfab051 (diff) | |
| parent | 787b97a4cb24330b36f11297c6d3a7a473a907d0 (diff) | |
Merge tag 'upstream/7.6.4'
Upstream version 7.6.4
Diffstat (limited to 'bower_components/moment/src/lib/duration/iso-string.js')
| -rw-r--r-- | bower_components/moment/src/lib/duration/iso-string.js | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/bower_components/moment/src/lib/duration/iso-string.js b/bower_components/moment/src/lib/duration/iso-string.js index 2670a9d..f33a968 100644 --- a/bower_components/moment/src/lib/duration/iso-string.js +++ b/bower_components/moment/src/lib/duration/iso-string.js @@ -1,13 +1,37 @@ +import absFloor from '../utils/abs-floor'; var abs = Math.abs; export function toISOString() { + // for ISO strings we do not use the normal bubbling rules: + // * milliseconds bubble up until they become hours + // * days do not bubble at all + // * months bubble up until they become years + // This is because there is no context-free conversion between hours and days + // (think of clock changes) + // and also not between days and months (28-31 days per month) + var seconds = abs(this._milliseconds) / 1000; + var days = abs(this._days); + var months = abs(this._months); + var minutes, hours, years; + + // 3600 seconds -> 60 minutes -> 1 hour + minutes = absFloor(seconds / 60); + hours = absFloor(minutes / 60); + seconds %= 60; + minutes %= 60; + + // 12 months -> 1 year + years = absFloor(months / 12); + months %= 12; + + // 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 Y = years; + var M = months; + var D = days; + var h = hours; + var m = minutes; + var s = seconds; var total = this.asSeconds(); if (!total) { |
