@barchart/portfolio-api-common 1.2.124 → 1.2.125

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/test/SpecRunner.js +161 -65
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.124",
3
+ "version": "1.2.125",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -23,9 +23,10 @@
23
23
  "gulp-bump": "~1.0.0",
24
24
  "gulp-git": "~1.6.0",
25
25
  "gulp-jasmine": "^2.2.1",
26
- "gulp-jshint": "~1.11.2",
26
+ "gulp-jshint": "~2.1.0",
27
27
  "gulp-util": "^3.0.7",
28
28
  "jsdoc": "^3.5.5",
29
+ "jshint": "2.9.5",
29
30
  "run-sequence": "~1.1.4",
30
31
  "vinyl-buffer": "^1.0.0",
31
32
  "vinyl-source-stream": "^1.1.0"
@@ -14020,22 +14020,36 @@ moment.tz.load(require('./data/packed/latest.json'));
14020
14020
  function createDate (y, m, d, h, M, s, ms) {
14021
14021
  // can't just apply() to create a date:
14022
14022
  // https://stackoverflow.com/q/181348
14023
- var date = new Date(y, m, d, h, M, s, ms);
14024
-
14023
+ var date;
14025
14024
  // the date constructor remaps years 0-99 to 1900-1999
14026
- if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
14027
- date.setFullYear(y);
14025
+ if (y < 100 && y >= 0) {
14026
+ // preserve leap years using a full 400 year cycle, then reset
14027
+ date = new Date(y + 400, m, d, h, M, s, ms);
14028
+ if (isFinite(date.getFullYear())) {
14029
+ date.setFullYear(y);
14030
+ }
14031
+ } else {
14032
+ date = new Date(y, m, d, h, M, s, ms);
14028
14033
  }
14034
+
14029
14035
  return date;
14030
14036
  }
14031
14037
 
14032
14038
  function createUTCDate (y) {
14033
- var date = new Date(Date.UTC.apply(null, arguments));
14034
-
14039
+ var date;
14035
14040
  // the Date.UTC function remaps years 0-99 to 1900-1999
14036
- if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
14037
- date.setUTCFullYear(y);
14041
+ if (y < 100 && y >= 0) {
14042
+ var args = Array.prototype.slice.call(arguments);
14043
+ // preserve leap years using a full 400 year cycle, then reset
14044
+ args[0] = y + 400;
14045
+ date = new Date(Date.UTC.apply(null, args));
14046
+ if (isFinite(date.getUTCFullYear())) {
14047
+ date.setUTCFullYear(y);
14048
+ }
14049
+ } else {
14050
+ date = new Date(Date.UTC.apply(null, arguments));
14038
14051
  }
14052
+
14039
14053
  return date;
14040
14054
  }
14041
14055
 
@@ -14137,7 +14151,7 @@ moment.tz.load(require('./data/packed/latest.json'));
14137
14151
 
14138
14152
  var defaultLocaleWeek = {
14139
14153
  dow : 0, // Sunday is the first day of the week.
14140
- doy : 6 // The week that contains Jan 1st is the first week of the year.
14154
+ doy : 6 // The week that contains Jan 6th is the first week of the year.
14141
14155
  };
14142
14156
 
14143
14157
  function localeFirstDayOfWeek () {
@@ -14246,25 +14260,28 @@ moment.tz.load(require('./data/packed/latest.json'));
14246
14260
  }
14247
14261
 
14248
14262
  // LOCALES
14263
+ function shiftWeekdays (ws, n) {
14264
+ return ws.slice(n, 7).concat(ws.slice(0, n));
14265
+ }
14249
14266
 
14250
14267
  var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
14251
14268
  function localeWeekdays (m, format) {
14252
- if (!m) {
14253
- return isArray(this._weekdays) ? this._weekdays :
14254
- this._weekdays['standalone'];
14255
- }
14256
- return isArray(this._weekdays) ? this._weekdays[m.day()] :
14257
- this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
14269
+ var weekdays = isArray(this._weekdays) ? this._weekdays :
14270
+ this._weekdays[(m && m !== true && this._weekdays.isFormat.test(format)) ? 'format' : 'standalone'];
14271
+ return (m === true) ? shiftWeekdays(weekdays, this._week.dow)
14272
+ : (m) ? weekdays[m.day()] : weekdays;
14258
14273
  }
14259
14274
 
14260
14275
  var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
14261
14276
  function localeWeekdaysShort (m) {
14262
- return (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
14277
+ return (m === true) ? shiftWeekdays(this._weekdaysShort, this._week.dow)
14278
+ : (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
14263
14279
  }
14264
14280
 
14265
14281
  var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
14266
14282
  function localeWeekdaysMin (m) {
14267
- return (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
14283
+ return (m === true) ? shiftWeekdays(this._weekdaysMin, this._week.dow)
14284
+ : (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
14268
14285
  }
14269
14286
 
14270
14287
  function handleStrictParse$1(weekdayName, format, strict) {
@@ -15013,13 +15030,13 @@ moment.tz.load(require('./data/packed/latest.json'));
15013
15030
  weekdayOverflow = true;
15014
15031
  }
15015
15032
  } else if (w.e != null) {
15016
- // local weekday -- counting starts from begining of week
15033
+ // local weekday -- counting starts from beginning of week
15017
15034
  weekday = w.e + dow;
15018
15035
  if (w.e < 0 || w.e > 6) {
15019
15036
  weekdayOverflow = true;
15020
15037
  }
15021
15038
  } else {
15022
- // default to begining of week
15039
+ // default to beginning of week
15023
15040
  weekday = dow;
15024
15041
  }
15025
15042
  }
@@ -15613,7 +15630,7 @@ moment.tz.load(require('./data/packed/latest.json'));
15613
15630
  years = normalizedInput.year || 0,
15614
15631
  quarters = normalizedInput.quarter || 0,
15615
15632
  months = normalizedInput.month || 0,
15616
- weeks = normalizedInput.week || 0,
15633
+ weeks = normalizedInput.week || normalizedInput.isoWeek || 0,
15617
15634
  days = normalizedInput.day || 0,
15618
15635
  hours = normalizedInput.hour || 0,
15619
15636
  minutes = normalizedInput.minute || 0,
@@ -15917,7 +15934,7 @@ moment.tz.load(require('./data/packed/latest.json'));
15917
15934
  ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match
15918
15935
  };
15919
15936
  } else if (!!(match = isoRegex.exec(input))) {
15920
- sign = (match[1] === '-') ? -1 : (match[1] === '+') ? 1 : 1;
15937
+ sign = (match[1] === '-') ? -1 : 1;
15921
15938
  duration = {
15922
15939
  y : parseIso(match[2], sign),
15923
15940
  M : parseIso(match[3], sign),
@@ -15959,7 +15976,7 @@ moment.tz.load(require('./data/packed/latest.json'));
15959
15976
  }
15960
15977
 
15961
15978
  function positiveMomentsDifference(base, other) {
15962
- var res = {milliseconds: 0, months: 0};
15979
+ var res = {};
15963
15980
 
15964
15981
  res.months = other.month() - base.month() +
15965
15982
  (other.year() - base.year()) * 12;
@@ -16068,7 +16085,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16068
16085
  if (!(this.isValid() && localInput.isValid())) {
16069
16086
  return false;
16070
16087
  }
16071
- units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
16088
+ units = normalizeUnits(units) || 'millisecond';
16072
16089
  if (units === 'millisecond') {
16073
16090
  return this.valueOf() > localInput.valueOf();
16074
16091
  } else {
@@ -16081,7 +16098,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16081
16098
  if (!(this.isValid() && localInput.isValid())) {
16082
16099
  return false;
16083
16100
  }
16084
- units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
16101
+ units = normalizeUnits(units) || 'millisecond';
16085
16102
  if (units === 'millisecond') {
16086
16103
  return this.valueOf() < localInput.valueOf();
16087
16104
  } else {
@@ -16090,9 +16107,14 @@ moment.tz.load(require('./data/packed/latest.json'));
16090
16107
  }
16091
16108
 
16092
16109
  function isBetween (from, to, units, inclusivity) {
16110
+ var localFrom = isMoment(from) ? from : createLocal(from),
16111
+ localTo = isMoment(to) ? to : createLocal(to);
16112
+ if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) {
16113
+ return false;
16114
+ }
16093
16115
  inclusivity = inclusivity || '()';
16094
- return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
16095
- (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
16116
+ return (inclusivity[0] === '(' ? this.isAfter(localFrom, units) : !this.isBefore(localFrom, units)) &&
16117
+ (inclusivity[1] === ')' ? this.isBefore(localTo, units) : !this.isAfter(localTo, units));
16096
16118
  }
16097
16119
 
16098
16120
  function isSame (input, units) {
@@ -16101,7 +16123,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16101
16123
  if (!(this.isValid() && localInput.isValid())) {
16102
16124
  return false;
16103
16125
  }
16104
- units = normalizeUnits(units || 'millisecond');
16126
+ units = normalizeUnits(units) || 'millisecond';
16105
16127
  if (units === 'millisecond') {
16106
16128
  return this.valueOf() === localInput.valueOf();
16107
16129
  } else {
@@ -16111,11 +16133,11 @@ moment.tz.load(require('./data/packed/latest.json'));
16111
16133
  }
16112
16134
 
16113
16135
  function isSameOrAfter (input, units) {
16114
- return this.isSame(input, units) || this.isAfter(input,units);
16136
+ return this.isSame(input, units) || this.isAfter(input, units);
16115
16137
  }
16116
16138
 
16117
16139
  function isSameOrBefore (input, units) {
16118
- return this.isSame(input, units) || this.isBefore(input,units);
16140
+ return this.isSame(input, units) || this.isBefore(input, units);
16119
16141
  }
16120
16142
 
16121
16143
  function diff (input, units, asFloat) {
@@ -16292,62 +16314,130 @@ moment.tz.load(require('./data/packed/latest.json'));
16292
16314
  return this._locale;
16293
16315
  }
16294
16316
 
16317
+ var MS_PER_SECOND = 1000;
16318
+ var MS_PER_MINUTE = 60 * MS_PER_SECOND;
16319
+ var MS_PER_HOUR = 60 * MS_PER_MINUTE;
16320
+ var MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
16321
+
16322
+ // actual modulo - handles negative numbers (for dates before 1970):
16323
+ function mod$1(dividend, divisor) {
16324
+ return (dividend % divisor + divisor) % divisor;
16325
+ }
16326
+
16327
+ function localStartOfDate(y, m, d) {
16328
+ // the date constructor remaps years 0-99 to 1900-1999
16329
+ if (y < 100 && y >= 0) {
16330
+ // preserve leap years using a full 400 year cycle, then reset
16331
+ return new Date(y + 400, m, d) - MS_PER_400_YEARS;
16332
+ } else {
16333
+ return new Date(y, m, d).valueOf();
16334
+ }
16335
+ }
16336
+
16337
+ function utcStartOfDate(y, m, d) {
16338
+ // Date.UTC remaps years 0-99 to 1900-1999
16339
+ if (y < 100 && y >= 0) {
16340
+ // preserve leap years using a full 400 year cycle, then reset
16341
+ return Date.UTC(y + 400, m, d) - MS_PER_400_YEARS;
16342
+ } else {
16343
+ return Date.UTC(y, m, d);
16344
+ }
16345
+ }
16346
+
16295
16347
  function startOf (units) {
16348
+ var time;
16296
16349
  units = normalizeUnits(units);
16297
- // the following switch intentionally omits break keywords
16298
- // to utilize falling through the cases.
16350
+ if (units === undefined || units === 'millisecond' || !this.isValid()) {
16351
+ return this;
16352
+ }
16353
+
16354
+ var startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
16355
+
16299
16356
  switch (units) {
16300
16357
  case 'year':
16301
- this.month(0);
16302
- /* falls through */
16358
+ time = startOfDate(this.year(), 0, 1);
16359
+ break;
16303
16360
  case 'quarter':
16361
+ time = startOfDate(this.year(), this.month() - this.month() % 3, 1);
16362
+ break;
16304
16363
  case 'month':
16305
- this.date(1);
16306
- /* falls through */
16364
+ time = startOfDate(this.year(), this.month(), 1);
16365
+ break;
16307
16366
  case 'week':
16367
+ time = startOfDate(this.year(), this.month(), this.date() - this.weekday());
16368
+ break;
16308
16369
  case 'isoWeek':
16370
+ time = startOfDate(this.year(), this.month(), this.date() - (this.isoWeekday() - 1));
16371
+ break;
16309
16372
  case 'day':
16310
16373
  case 'date':
16311
- this.hours(0);
16312
- /* falls through */
16374
+ time = startOfDate(this.year(), this.month(), this.date());
16375
+ break;
16313
16376
  case 'hour':
16314
- this.minutes(0);
16315
- /* falls through */
16377
+ time = this._d.valueOf();
16378
+ time -= mod$1(time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE), MS_PER_HOUR);
16379
+ break;
16316
16380
  case 'minute':
16317
- this.seconds(0);
16318
- /* falls through */
16381
+ time = this._d.valueOf();
16382
+ time -= mod$1(time, MS_PER_MINUTE);
16383
+ break;
16319
16384
  case 'second':
16320
- this.milliseconds(0);
16321
- }
16322
-
16323
- // weeks are a special case
16324
- if (units === 'week') {
16325
- this.weekday(0);
16326
- }
16327
- if (units === 'isoWeek') {
16328
- this.isoWeekday(1);
16329
- }
16330
-
16331
- // quarters are also special
16332
- if (units === 'quarter') {
16333
- this.month(Math.floor(this.month() / 3) * 3);
16385
+ time = this._d.valueOf();
16386
+ time -= mod$1(time, MS_PER_SECOND);
16387
+ break;
16334
16388
  }
16335
16389
 
16390
+ this._d.setTime(time);
16391
+ hooks.updateOffset(this, true);
16336
16392
  return this;
16337
16393
  }
16338
16394
 
16339
16395
  function endOf (units) {
16396
+ var time;
16340
16397
  units = normalizeUnits(units);
16341
- if (units === undefined || units === 'millisecond') {
16398
+ if (units === undefined || units === 'millisecond' || !this.isValid()) {
16342
16399
  return this;
16343
16400
  }
16344
16401
 
16345
- // 'date' is an alias for 'day', so it should be considered as such.
16346
- if (units === 'date') {
16347
- units = 'day';
16402
+ var startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
16403
+
16404
+ switch (units) {
16405
+ case 'year':
16406
+ time = startOfDate(this.year() + 1, 0, 1) - 1;
16407
+ break;
16408
+ case 'quarter':
16409
+ time = startOfDate(this.year(), this.month() - this.month() % 3 + 3, 1) - 1;
16410
+ break;
16411
+ case 'month':
16412
+ time = startOfDate(this.year(), this.month() + 1, 1) - 1;
16413
+ break;
16414
+ case 'week':
16415
+ time = startOfDate(this.year(), this.month(), this.date() - this.weekday() + 7) - 1;
16416
+ break;
16417
+ case 'isoWeek':
16418
+ time = startOfDate(this.year(), this.month(), this.date() - (this.isoWeekday() - 1) + 7) - 1;
16419
+ break;
16420
+ case 'day':
16421
+ case 'date':
16422
+ time = startOfDate(this.year(), this.month(), this.date() + 1) - 1;
16423
+ break;
16424
+ case 'hour':
16425
+ time = this._d.valueOf();
16426
+ time += MS_PER_HOUR - mod$1(time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE), MS_PER_HOUR) - 1;
16427
+ break;
16428
+ case 'minute':
16429
+ time = this._d.valueOf();
16430
+ time += MS_PER_MINUTE - mod$1(time, MS_PER_MINUTE) - 1;
16431
+ break;
16432
+ case 'second':
16433
+ time = this._d.valueOf();
16434
+ time += MS_PER_SECOND - mod$1(time, MS_PER_SECOND) - 1;
16435
+ break;
16348
16436
  }
16349
16437
 
16350
- return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
16438
+ this._d.setTime(time);
16439
+ hooks.updateOffset(this, true);
16440
+ return this;
16351
16441
  }
16352
16442
 
16353
16443
  function valueOf () {
@@ -17053,10 +17143,14 @@ moment.tz.load(require('./data/packed/latest.json'));
17053
17143
 
17054
17144
  units = normalizeUnits(units);
17055
17145
 
17056
- if (units === 'month' || units === 'year') {
17057
- days = this._days + milliseconds / 864e5;
17146
+ if (units === 'month' || units === 'quarter' || units === 'year') {
17147
+ days = this._days + milliseconds / 864e5;
17058
17148
  months = this._months + daysToMonths(days);
17059
- return units === 'month' ? months : months / 12;
17149
+ switch (units) {
17150
+ case 'month': return months;
17151
+ case 'quarter': return months / 3;
17152
+ case 'year': return months / 12;
17153
+ }
17060
17154
  } else {
17061
17155
  // handle milliseconds separately because of floating point math errors (issue #1867)
17062
17156
  days = this._days + Math.round(monthsToDays(this._months));
@@ -17099,6 +17193,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17099
17193
  var asDays = makeAs('d');
17100
17194
  var asWeeks = makeAs('w');
17101
17195
  var asMonths = makeAs('M');
17196
+ var asQuarters = makeAs('Q');
17102
17197
  var asYears = makeAs('y');
17103
17198
 
17104
17199
  function clone$1 () {
@@ -17290,6 +17385,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17290
17385
  proto$2.asDays = asDays;
17291
17386
  proto$2.asWeeks = asWeeks;
17292
17387
  proto$2.asMonths = asMonths;
17388
+ proto$2.asQuarters = asQuarters;
17293
17389
  proto$2.asYears = asYears;
17294
17390
  proto$2.valueOf = valueOf$1;
17295
17391
  proto$2._bubble = bubble;
@@ -17334,7 +17430,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17334
17430
  // Side effect imports
17335
17431
 
17336
17432
 
17337
- hooks.version = '2.22.2';
17433
+ hooks.version = '2.24.0';
17338
17434
 
17339
17435
  setHookCallback(createLocal);
17340
17436
 
@@ -17375,7 +17471,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17375
17471
  TIME: 'HH:mm', // <input type="time" />
17376
17472
  TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" />
17377
17473
  TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
17378
- WEEK: 'YYYY-[W]WW', // <input type="week" />
17474
+ WEEK: 'GGGG-[W]WW', // <input type="week" />
17379
17475
  MONTH: 'YYYY-MM' // <input type="month" />
17380
17476
  };
17381
17477