aboutsummaryrefslogtreecommitdiff
path: root/node_modules/moment/src/lib/duration
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-10-14 18:40:54 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-10-14 18:40:54 +0200
commit9df98e65f842cf3acae09cbdd969966f42d64469 (patch)
treef071d3e09a342c208fb8e1cd3f5241d64fbfbaf3 /node_modules/moment/src/lib/duration
parent008926b18470e7f394cd640302957b29728a9803 (diff)
update dependencies
Diffstat (limited to 'node_modules/moment/src/lib/duration')
-rw-r--r--node_modules/moment/src/lib/duration/clone.js6
-rw-r--r--node_modules/moment/src/lib/duration/constructor.js2
-rw-r--r--node_modules/moment/src/lib/duration/create.js6
-rw-r--r--node_modules/moment/src/lib/duration/iso-string.js26
-rw-r--r--node_modules/moment/src/lib/duration/prototype.js2
-rw-r--r--node_modules/moment/src/lib/duration/valid.js3
6 files changed, 31 insertions, 14 deletions
diff --git a/node_modules/moment/src/lib/duration/clone.js b/node_modules/moment/src/lib/duration/clone.js
new file mode 100644
index 000000000..56008d12e
--- /dev/null
+++ b/node_modules/moment/src/lib/duration/clone.js
@@ -0,0 +1,6 @@
+import { createDuration } from './create';
+
+export function clone () {
+ return createDuration(this);
+}
+
diff --git a/node_modules/moment/src/lib/duration/constructor.js b/node_modules/moment/src/lib/duration/constructor.js
index 5c97ef108..2d86d5e2c 100644
--- a/node_modules/moment/src/lib/duration/constructor.js
+++ b/node_modules/moment/src/lib/duration/constructor.js
@@ -25,7 +25,7 @@ export function Duration (duration) {
// day when working around DST, we need to store them separately
this._days = +days +
weeks * 7;
- // It is impossible translate months into days without knowing
+ // It is impossible to translate months into days without knowing
// which months you are are talking about, so we have to store
// it separately.
this._months = +months +
diff --git a/node_modules/moment/src/lib/duration/create.js b/node_modules/moment/src/lib/duration/create.js
index 9b6d5a964..346814816 100644
--- a/node_modules/moment/src/lib/duration/create.js
+++ b/node_modules/moment/src/lib/duration/create.js
@@ -9,12 +9,12 @@ import { createLocal } from '../create/local';
import { createInvalid as invalid } from './valid';
// ASP.NET json date format regex
-var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
+var aspNetRegex = /^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
// from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
// somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
// and further modified to allow for strings containing both week and day
-var isoRegex = /^(-)?P(?:(-?[0-9,.]*)Y)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)W)?(?:(-?[0-9,.]*)D)?(?:T(?:(-?[0-9,.]*)H)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)S)?)?$/;
+var isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
export function createDuration (input, key) {
var duration = input,
@@ -48,7 +48,7 @@ export function createDuration (input, key) {
ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match
};
} else if (!!(match = isoRegex.exec(input))) {
- sign = (match[1] === '-') ? -1 : 1;
+ sign = (match[1] === '-') ? -1 : (match[1] === '+') ? 1 : 1;
duration = {
y : parseIso(match[2], sign),
M : parseIso(match[3], sign),
diff --git a/node_modules/moment/src/lib/duration/iso-string.js b/node_modules/moment/src/lib/duration/iso-string.js
index 7bb022813..419f3638e 100644
--- a/node_modules/moment/src/lib/duration/iso-string.js
+++ b/node_modules/moment/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
@@ -35,7 +39,7 @@ export function toISOString() {
var D = days;
var h = hours;
var m = minutes;
- var s = seconds;
+ var s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
var total = this.asSeconds();
if (!total) {
@@ -44,13 +48,17 @@ export function toISOString() {
return 'P0D';
}
- return (total < 0 ? '-' : '') +
- 'P' +
- (Y ? Y + 'Y' : '') +
- (M ? M + 'M' : '') +
- (D ? D + 'D' : '') +
+ var totalSign = total < 0 ? '-' : '';
+ var ymSign = sign(this._months) !== sign(total) ? '-' : '';
+ var daysSign = sign(this._days) !== sign(total) ? '-' : '';
+ var hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
+
+ return totalSign + 'P' +
+ (Y ? ymSign + Y + 'Y' : '') +
+ (M ? ymSign + M + 'M' : '') +
+ (D ? daysSign + D + 'D' : '') +
((h || m || s) ? 'T' : '') +
- (h ? h + 'H' : '') +
- (m ? m + 'M' : '') +
- (s ? s + 'S' : '');
+ (h ? hmsSign + h + 'H' : '') +
+ (m ? hmsSign + m + 'M' : '') +
+ (s ? hmsSign + s + 'S' : '');
}
diff --git a/node_modules/moment/src/lib/duration/prototype.js b/node_modules/moment/src/lib/duration/prototype.js
index d923375cb..dd5470d38 100644
--- a/node_modules/moment/src/lib/duration/prototype.js
+++ b/node_modules/moment/src/lib/duration/prototype.js
@@ -6,6 +6,7 @@ import { abs } from './abs';
import { add, subtract } from './add-subtract';
import { as, asMilliseconds, asSeconds, asMinutes, asHours, asDays, asWeeks, asMonths, asYears, valueOf } from './as';
import { bubble } from './bubble';
+import { clone } from './clone';
import { get, milliseconds, seconds, minutes, hours, days, months, years, weeks } from './get';
import { humanize } from './humanize';
import { toISOString } from './iso-string';
@@ -27,6 +28,7 @@ proto.asMonths = asMonths;
proto.asYears = asYears;
proto.valueOf = valueOf;
proto._bubble = bubble;
+proto.clone = clone;
proto.get = get;
proto.milliseconds = milliseconds;
proto.seconds = seconds;
diff --git a/node_modules/moment/src/lib/duration/valid.js b/node_modules/moment/src/lib/duration/valid.js
index 842585f32..033fd5b0f 100644
--- a/node_modules/moment/src/lib/duration/valid.js
+++ b/node_modules/moment/src/lib/duration/valid.js
@@ -1,4 +1,5 @@
import toInt from '../utils/to-int';
+import indexOf from '../utils/index-of';
import {Duration} from './constructor';
import {createDuration} from './create';
@@ -6,7 +7,7 @@ var ordering = ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'se
export default function isDurationValid(m) {
for (var key in m) {
- if (!(ordering.indexOf(key) !== -1 && (m[key] == null || !isNaN(m[key])))) {
+ if (!(indexOf.call(ordering, key) !== -1 && (m[key] == null || !isNaN(m[key])))) {
return false;
}
}