@barchart/portfolio-api-common 1.2.146 → 1.2.147

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.
@@ -691,9 +691,9 @@ module.exports = (() => {
691
691
  updates.marketPrevious = updates.marketPrevious.add(translate(item, item.data.marketPrevious));
692
692
  updates.marketPrevious2 = updates.marketPrevious2.add(translate(item, item.data.marketPrevious2));
693
693
 
694
+ updates.periodIncome = updates.periodIncome.add(translate(item, item.data.periodIncome));
694
695
  updates.periodRealized = updates.periodRealized.add(translate(item, item.data.periodRealized));
695
696
  updates.periodUnrealized = updates.periodUnrealized.add(translate(item, item.data.periodUnrealized));
696
- updates.periodIncome = updates.periodIncome.add(translate(item, item.data.periodIncome));
697
697
 
698
698
  if (item.position.instrument.type === InstrumentType.CASH) {
699
699
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
@@ -715,9 +715,9 @@ module.exports = (() => {
715
715
  summaryTotalPrevious2: Decimal.ZERO,
716
716
  marketPrevious: Decimal.ZERO,
717
717
  marketPrevious2: Decimal.ZERO,
718
+ periodIncome: Decimal.ZERO,
718
719
  periodRealized: Decimal.ZERO,
719
720
  periodUnrealized: Decimal.ZERO,
720
- periodIncome: Decimal.ZERO,
721
721
  cashTotal: Decimal.ZERO,
722
722
  totalDivisor: Decimal.ZERO,
723
723
  periodDivisorCurrent: Decimal.ZERO,
@@ -734,9 +734,9 @@ module.exports = (() => {
734
734
  actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
735
735
  actual.marketPrevious = updates.marketPrevious;
736
736
  actual.marketPrevious2 = updates.marketPrevious2;
737
+ actual.periodIncome = updates.periodIncome;
737
738
  actual.periodRealized = updates.periodRealized;
738
739
  actual.periodUnrealized = updates.periodUnrealized;
739
- actual.periodIncome = updates.periodIncome;
740
740
  actual.cashTotal = updates.cashTotal;
741
741
  actual.totalDivisor = updates.totalDivisor;
742
742
  actual.periodDivisorCurrent = updates.periodDivisorCurrent;
@@ -755,9 +755,9 @@ module.exports = (() => {
755
755
  format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
756
756
  format.marketPrevious = formatCurrency(updates.marketPrevious, currency);
757
757
  format.marketPrevious2 = formatCurrency(updates.marketPrevious2, currency);
758
+ format.periodIncome = formatCurrency(updates.periodIncome, currency);
758
759
  format.periodRealized = formatCurrency(updates.periodRealized, currency);
759
760
  format.periodUnrealized = formatCurrency(updates.periodUnrealized, currency);
760
- format.periodIncome = formatCurrency(updates.periodIncome, currency);
761
761
  format.cashTotal = formatCurrency(updates.cashTotal, currency);
762
762
 
763
763
  calculateRealizedPercent(group);
@@ -846,6 +846,7 @@ module.exports = (() => {
846
846
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
847
847
  updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
848
848
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.periodGain));
849
+ updates.periodUnrealized = updates.periodUnrealized.add(translate(item, item.data.periodUnrealized));
849
850
 
850
851
  return updates;
851
852
  }, {
@@ -854,7 +855,8 @@ module.exports = (() => {
854
855
  marketDirection: unchanged,
855
856
  unrealized: Decimal.ZERO,
856
857
  unrealizedToday: Decimal.ZERO,
857
- summaryTotalCurrent: Decimal.ZERO
858
+ summaryTotalCurrent: Decimal.ZERO,
859
+ periodUnrealized: Decimal.ZERO
858
860
  });
859
861
  } else {
860
862
  updates = {
@@ -863,7 +865,8 @@ module.exports = (() => {
863
865
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
864
866
  unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
865
867
  unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
866
- summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange))
868
+ summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange)),
869
+ periodUnrealized: actual.periodUnrealized.add(translate(item, item.data.periodUnrealizedChange))
867
870
  };
868
871
  }
869
872
 
@@ -872,6 +875,7 @@ module.exports = (() => {
872
875
  actual.unrealized = updates.unrealized;
873
876
  actual.unrealizedToday = updates.unrealizedToday;
874
877
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
878
+ actual.periodUnrealized = updates.periodUnrealized;
875
879
 
876
880
  actual.total = updates.unrealized.add(actual.realized).add(actual.income);
877
881
  actual.totalPercent = calculateGainPercent(actual.total, actual.totalDivisor);
@@ -910,6 +914,8 @@ module.exports = (() => {
910
914
  format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
911
915
  format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
912
916
 
917
+ format.periodUnrealized = formatCurrency(actual.periodUnrealized, currency);
918
+
913
919
  format.total = formatCurrency(actual.total, currency);
914
920
  format.totalNegative = actual.total.getIsNegative();
915
921
  format.totalPercent = formatPercent(actual.totalPercent, 2);
@@ -922,10 +928,6 @@ module.exports = (() => {
922
928
 
923
929
  actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
924
930
  format.periodPercent = formatPercent(actual.periodPercent, 2);
925
-
926
- if (group.single && item) {
927
- actual.periodUnrealized = item.data.periodUnrealized;
928
- }
929
931
  }
930
932
 
931
933
  function calculateMarketPercent(group, rates, parentGroup, portfolioGroup) {
@@ -75,7 +75,9 @@ module.exports = (() => {
75
75
 
76
76
  this._data.periodIncome = null;
77
77
  this._data.periodRealized = null;
78
+
78
79
  this._data.periodUnrealized = null;
80
+ this._data.periodUnrealizedChange = null;
79
81
 
80
82
  this._data.periodPrice = null;
81
83
  this._data.periodPricePrevious = null;
@@ -420,14 +422,14 @@ module.exports = (() => {
420
422
  data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
421
423
  data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
422
424
 
423
- data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
424
- data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
425
- data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
426
-
427
425
  data.periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary1);
428
426
  data.periodGainPrevious = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
429
427
  data.periodGainPrevious2 = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
430
428
 
429
+ data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
430
+ data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
431
+ data.periodUnrealized = calculatePeriodUnrealized(position.instrument.type, data.periodGain, data.periodRealized, data.periodIncome);
432
+
431
433
  data.periodDivisor = calculatePeriodDivisor(position.instrument.type, data.initiate, currentSummary, previousSummary1);
432
434
  data.periodDivisorPrevious = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
433
435
  data.periodDivisorPrevious2 = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
@@ -555,6 +557,18 @@ module.exports = (() => {
555
557
 
556
558
  data.periodGain = periodGain;
557
559
  data.periodGainChange = periodGainChange;
560
+
561
+ let periodUnrealized = calculatePeriodUnrealized(position.instrument.type, data.periodGain, data.periodRealized, data.periodIncome);
562
+ let periodUnrealizedChange;
563
+
564
+ if (data.periodUnrealized !== null) {
565
+ periodUnrealizedChange = periodUnrealized.subtract(data.periodUnrealized);
566
+ } else {
567
+ periodUnrealizedChange = Decimal.ZERO;
568
+ }
569
+
570
+ data.periodUnrealized = periodUnrealized;
571
+ data.periodUnrealizedChange = periodUnrealizedChange;
558
572
  } else {
559
573
  data.unrealized = Decimal.ZERO;
560
574
  data.unrealizedChange = Decimal.ZERO;
@@ -645,6 +659,18 @@ module.exports = (() => {
645
659
  return returnRef;
646
660
  }
647
661
 
662
+ function calculatePeriodUnrealized(type, periodGain, periodRealized, periodIncome) {
663
+ let returnRef;
664
+
665
+ if (type !== InstrumentType.CASH) {
666
+ returnRef = periodRealized.add(periodIncome).subtract(periodGain).opposite();
667
+ } else {
668
+ returnRef = Decimal.ZERO;
669
+ }
670
+
671
+ return returnRef;
672
+ }
673
+
648
674
  function calculateTotalDivisor(type, direction, finalSummary, position) {
649
675
  let returnRef;
650
676
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.146",
3
+ "version": "1.2.147",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -3213,9 +3213,9 @@ module.exports = (() => {
3213
3213
  updates.marketPrevious = updates.marketPrevious.add(translate(item, item.data.marketPrevious));
3214
3214
  updates.marketPrevious2 = updates.marketPrevious2.add(translate(item, item.data.marketPrevious2));
3215
3215
 
3216
+ updates.periodIncome = updates.periodIncome.add(translate(item, item.data.periodIncome));
3216
3217
  updates.periodRealized = updates.periodRealized.add(translate(item, item.data.periodRealized));
3217
3218
  updates.periodUnrealized = updates.periodUnrealized.add(translate(item, item.data.periodUnrealized));
3218
- updates.periodIncome = updates.periodIncome.add(translate(item, item.data.periodIncome));
3219
3219
 
3220
3220
  if (item.position.instrument.type === InstrumentType.CASH) {
3221
3221
  updates.cashTotal = updates.cashTotal.add(translate(item, item.data.market));
@@ -3237,9 +3237,9 @@ module.exports = (() => {
3237
3237
  summaryTotalPrevious2: Decimal.ZERO,
3238
3238
  marketPrevious: Decimal.ZERO,
3239
3239
  marketPrevious2: Decimal.ZERO,
3240
+ periodIncome: Decimal.ZERO,
3240
3241
  periodRealized: Decimal.ZERO,
3241
3242
  periodUnrealized: Decimal.ZERO,
3242
- periodIncome: Decimal.ZERO,
3243
3243
  cashTotal: Decimal.ZERO,
3244
3244
  totalDivisor: Decimal.ZERO,
3245
3245
  periodDivisorCurrent: Decimal.ZERO,
@@ -3256,9 +3256,9 @@ module.exports = (() => {
3256
3256
  actual.summaryTotalPrevious2 = updates.summaryTotalPrevious2;
3257
3257
  actual.marketPrevious = updates.marketPrevious;
3258
3258
  actual.marketPrevious2 = updates.marketPrevious2;
3259
+ actual.periodIncome = updates.periodIncome;
3259
3260
  actual.periodRealized = updates.periodRealized;
3260
3261
  actual.periodUnrealized = updates.periodUnrealized;
3261
- actual.periodIncome = updates.periodIncome;
3262
3262
  actual.cashTotal = updates.cashTotal;
3263
3263
  actual.totalDivisor = updates.totalDivisor;
3264
3264
  actual.periodDivisorCurrent = updates.periodDivisorCurrent;
@@ -3277,9 +3277,9 @@ module.exports = (() => {
3277
3277
  format.summaryTotalPrevious2Negative = updates.summaryTotalPrevious2.getIsNegative();
3278
3278
  format.marketPrevious = formatCurrency(updates.marketPrevious, currency);
3279
3279
  format.marketPrevious2 = formatCurrency(updates.marketPrevious2, currency);
3280
+ format.periodIncome = formatCurrency(updates.periodIncome, currency);
3280
3281
  format.periodRealized = formatCurrency(updates.periodRealized, currency);
3281
3282
  format.periodUnrealized = formatCurrency(updates.periodUnrealized, currency);
3282
- format.periodIncome = formatCurrency(updates.periodIncome, currency);
3283
3283
  format.cashTotal = formatCurrency(updates.cashTotal, currency);
3284
3284
 
3285
3285
  calculateRealizedPercent(group);
@@ -3368,6 +3368,7 @@ module.exports = (() => {
3368
3368
  updates.unrealized = updates.unrealized.add(translate(item, item.data.unrealized));
3369
3369
  updates.unrealizedToday = updates.unrealizedToday.add(translate(item, item.data.unrealizedToday));
3370
3370
  updates.summaryTotalCurrent = updates.summaryTotalCurrent.add(translate(item, item.data.periodGain));
3371
+ updates.periodUnrealized = updates.periodUnrealized.add(translate(item, item.data.periodUnrealized));
3371
3372
 
3372
3373
  return updates;
3373
3374
  }, {
@@ -3376,7 +3377,8 @@ module.exports = (() => {
3376
3377
  marketDirection: unchanged,
3377
3378
  unrealized: Decimal.ZERO,
3378
3379
  unrealizedToday: Decimal.ZERO,
3379
- summaryTotalCurrent: Decimal.ZERO
3380
+ summaryTotalCurrent: Decimal.ZERO,
3381
+ periodUnrealized: Decimal.ZERO
3380
3382
  });
3381
3383
  } else {
3382
3384
  updates = {
@@ -3385,7 +3387,8 @@ module.exports = (() => {
3385
3387
  marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
3386
3388
  unrealized: actual.unrealized.add(translate(item, item.data.unrealizedChange)),
3387
3389
  unrealizedToday: actual.unrealizedToday.add(translate(item, item.data.unrealizedTodayChange)),
3388
- summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange))
3390
+ summaryTotalCurrent: actual.summaryTotalCurrent.add(translate(item, item.data.periodGainChange)),
3391
+ periodUnrealized: actual.periodUnrealized.add(translate(item, item.data.periodUnrealizedChange))
3389
3392
  };
3390
3393
  }
3391
3394
 
@@ -3394,6 +3397,7 @@ module.exports = (() => {
3394
3397
  actual.unrealized = updates.unrealized;
3395
3398
  actual.unrealizedToday = updates.unrealizedToday;
3396
3399
  actual.summaryTotalCurrent = updates.summaryTotalCurrent;
3400
+ actual.periodUnrealized = updates.periodUnrealized;
3397
3401
 
3398
3402
  actual.total = updates.unrealized.add(actual.realized).add(actual.income);
3399
3403
  actual.totalPercent = calculateGainPercent(actual.total, actual.totalDivisor);
@@ -3432,6 +3436,8 @@ module.exports = (() => {
3432
3436
  format.summaryTotalCurrent = formatCurrency(actual.summaryTotalCurrent, currency);
3433
3437
  format.summaryTotalCurrentNegative = actual.summaryTotalCurrent.getIsNegative();
3434
3438
 
3439
+ format.periodUnrealized = formatCurrency(actual.periodUnrealized, currency);
3440
+
3435
3441
  format.total = formatCurrency(actual.total, currency);
3436
3442
  format.totalNegative = actual.total.getIsNegative();
3437
3443
  format.totalPercent = formatPercent(actual.totalPercent, 2);
@@ -3444,10 +3450,6 @@ module.exports = (() => {
3444
3450
 
3445
3451
  actual.periodPercent = calculateGainPercent(actual.summaryTotalCurrent, actual.periodDivisorCurrent);
3446
3452
  format.periodPercent = formatPercent(actual.periodPercent, 2);
3447
-
3448
- if (group.single && item) {
3449
- actual.periodUnrealized = item.data.periodUnrealized;
3450
- }
3451
3453
  }
3452
3454
 
3453
3455
  function calculateMarketPercent(group, rates, parentGroup, portfolioGroup) {
@@ -3615,7 +3617,9 @@ module.exports = (() => {
3615
3617
 
3616
3618
  this._data.periodIncome = null;
3617
3619
  this._data.periodRealized = null;
3620
+
3618
3621
  this._data.periodUnrealized = null;
3622
+ this._data.periodUnrealizedChange = null;
3619
3623
 
3620
3624
  this._data.periodPrice = null;
3621
3625
  this._data.periodPricePrevious = null;
@@ -3960,14 +3964,14 @@ module.exports = (() => {
3960
3964
  data.marketPrevious2 = previousSummary2 === null ? Decimal.ZERO : previousSummary2.end.value;
3961
3965
  data.quantityPrevious = previousSummary1 === null ? Decimal.ZERO : previousSummary1.end.open;
3962
3966
 
3963
- data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
3964
- data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
3965
- data.periodUnrealized = currentSummary !== null ? currentSummary.period.unrealized : Decimal.ZERO;
3966
-
3967
3967
  data.periodGain = calculatePeriodGain(position.instrument.type, data.initiate, currentSummary, previousSummary1);
3968
3968
  data.periodGainPrevious = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
3969
3969
  data.periodGainPrevious2 = calculatePeriodGain(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
3970
3970
 
3971
+ data.periodIncome = currentSummary !== null ? currentSummary.period.income : Decimal.ZERO;
3972
+ data.periodRealized = currentSummary !== null ? currentSummary.period.realized : Decimal.ZERO;
3973
+ data.periodUnrealized = calculatePeriodUnrealized(position.instrument.type, data.periodGain, data.periodRealized, data.periodIncome);
3974
+
3971
3975
  data.periodDivisor = calculatePeriodDivisor(position.instrument.type, data.initiate, currentSummary, previousSummary1);
3972
3976
  data.periodDivisorPrevious = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary1, previousSummary2);
3973
3977
  data.periodDivisorPrevious2 = calculatePeriodDivisor(position.instrument.type, data.initiate, previousSummary2, previousSummary3);
@@ -4095,6 +4099,18 @@ module.exports = (() => {
4095
4099
 
4096
4100
  data.periodGain = periodGain;
4097
4101
  data.periodGainChange = periodGainChange;
4102
+
4103
+ let periodUnrealized = calculatePeriodUnrealized(position.instrument.type, data.periodGain, data.periodRealized, data.periodIncome);
4104
+ let periodUnrealizedChange;
4105
+
4106
+ if (data.periodUnrealized !== null) {
4107
+ periodUnrealizedChange = periodUnrealized.subtract(data.periodUnrealized);
4108
+ } else {
4109
+ periodUnrealizedChange = Decimal.ZERO;
4110
+ }
4111
+
4112
+ data.periodUnrealized = periodUnrealized;
4113
+ data.periodUnrealizedChange = periodUnrealizedChange;
4098
4114
  } else {
4099
4115
  data.unrealized = Decimal.ZERO;
4100
4116
  data.unrealizedChange = Decimal.ZERO;
@@ -4185,6 +4201,18 @@ module.exports = (() => {
4185
4201
  return returnRef;
4186
4202
  }
4187
4203
 
4204
+ function calculatePeriodUnrealized(type, periodGain, periodRealized, periodIncome) {
4205
+ let returnRef;
4206
+
4207
+ if (type !== InstrumentType.CASH) {
4208
+ returnRef = periodRealized.add(periodIncome).subtract(periodGain).opposite();
4209
+ } else {
4210
+ returnRef = Decimal.ZERO;
4211
+ }
4212
+
4213
+ return returnRef;
4214
+ }
4215
+
4188
4216
  function calculateTotalDivisor(type, direction, finalSummary, position) {
4189
4217
  let returnRef;
4190
4218
 
@@ -14055,22 +14083,36 @@ moment.tz.load(require('./data/packed/latest.json'));
14055
14083
  function createDate (y, m, d, h, M, s, ms) {
14056
14084
  // can't just apply() to create a date:
14057
14085
  // https://stackoverflow.com/q/181348
14058
- var date = new Date(y, m, d, h, M, s, ms);
14059
-
14086
+ var date;
14060
14087
  // the date constructor remaps years 0-99 to 1900-1999
14061
- if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
14062
- date.setFullYear(y);
14088
+ if (y < 100 && y >= 0) {
14089
+ // preserve leap years using a full 400 year cycle, then reset
14090
+ date = new Date(y + 400, m, d, h, M, s, ms);
14091
+ if (isFinite(date.getFullYear())) {
14092
+ date.setFullYear(y);
14093
+ }
14094
+ } else {
14095
+ date = new Date(y, m, d, h, M, s, ms);
14063
14096
  }
14097
+
14064
14098
  return date;
14065
14099
  }
14066
14100
 
14067
14101
  function createUTCDate (y) {
14068
- var date = new Date(Date.UTC.apply(null, arguments));
14069
-
14102
+ var date;
14070
14103
  // the Date.UTC function remaps years 0-99 to 1900-1999
14071
- if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
14072
- date.setUTCFullYear(y);
14104
+ if (y < 100 && y >= 0) {
14105
+ var args = Array.prototype.slice.call(arguments);
14106
+ // preserve leap years using a full 400 year cycle, then reset
14107
+ args[0] = y + 400;
14108
+ date = new Date(Date.UTC.apply(null, args));
14109
+ if (isFinite(date.getUTCFullYear())) {
14110
+ date.setUTCFullYear(y);
14111
+ }
14112
+ } else {
14113
+ date = new Date(Date.UTC.apply(null, arguments));
14073
14114
  }
14115
+
14074
14116
  return date;
14075
14117
  }
14076
14118
 
@@ -14172,7 +14214,7 @@ moment.tz.load(require('./data/packed/latest.json'));
14172
14214
 
14173
14215
  var defaultLocaleWeek = {
14174
14216
  dow : 0, // Sunday is the first day of the week.
14175
- doy : 6 // The week that contains Jan 1st is the first week of the year.
14217
+ doy : 6 // The week that contains Jan 6th is the first week of the year.
14176
14218
  };
14177
14219
 
14178
14220
  function localeFirstDayOfWeek () {
@@ -14281,25 +14323,28 @@ moment.tz.load(require('./data/packed/latest.json'));
14281
14323
  }
14282
14324
 
14283
14325
  // LOCALES
14326
+ function shiftWeekdays (ws, n) {
14327
+ return ws.slice(n, 7).concat(ws.slice(0, n));
14328
+ }
14284
14329
 
14285
14330
  var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
14286
14331
  function localeWeekdays (m, format) {
14287
- if (!m) {
14288
- return isArray(this._weekdays) ? this._weekdays :
14289
- this._weekdays['standalone'];
14290
- }
14291
- return isArray(this._weekdays) ? this._weekdays[m.day()] :
14292
- this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
14332
+ var weekdays = isArray(this._weekdays) ? this._weekdays :
14333
+ this._weekdays[(m && m !== true && this._weekdays.isFormat.test(format)) ? 'format' : 'standalone'];
14334
+ return (m === true) ? shiftWeekdays(weekdays, this._week.dow)
14335
+ : (m) ? weekdays[m.day()] : weekdays;
14293
14336
  }
14294
14337
 
14295
14338
  var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
14296
14339
  function localeWeekdaysShort (m) {
14297
- return (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
14340
+ return (m === true) ? shiftWeekdays(this._weekdaysShort, this._week.dow)
14341
+ : (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
14298
14342
  }
14299
14343
 
14300
14344
  var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
14301
14345
  function localeWeekdaysMin (m) {
14302
- return (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
14346
+ return (m === true) ? shiftWeekdays(this._weekdaysMin, this._week.dow)
14347
+ : (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
14303
14348
  }
14304
14349
 
14305
14350
  function handleStrictParse$1(weekdayName, format, strict) {
@@ -15048,13 +15093,13 @@ moment.tz.load(require('./data/packed/latest.json'));
15048
15093
  weekdayOverflow = true;
15049
15094
  }
15050
15095
  } else if (w.e != null) {
15051
- // local weekday -- counting starts from begining of week
15096
+ // local weekday -- counting starts from beginning of week
15052
15097
  weekday = w.e + dow;
15053
15098
  if (w.e < 0 || w.e > 6) {
15054
15099
  weekdayOverflow = true;
15055
15100
  }
15056
15101
  } else {
15057
- // default to begining of week
15102
+ // default to beginning of week
15058
15103
  weekday = dow;
15059
15104
  }
15060
15105
  }
@@ -15648,7 +15693,7 @@ moment.tz.load(require('./data/packed/latest.json'));
15648
15693
  years = normalizedInput.year || 0,
15649
15694
  quarters = normalizedInput.quarter || 0,
15650
15695
  months = normalizedInput.month || 0,
15651
- weeks = normalizedInput.week || 0,
15696
+ weeks = normalizedInput.week || normalizedInput.isoWeek || 0,
15652
15697
  days = normalizedInput.day || 0,
15653
15698
  hours = normalizedInput.hour || 0,
15654
15699
  minutes = normalizedInput.minute || 0,
@@ -15952,7 +15997,7 @@ moment.tz.load(require('./data/packed/latest.json'));
15952
15997
  ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match
15953
15998
  };
15954
15999
  } else if (!!(match = isoRegex.exec(input))) {
15955
- sign = (match[1] === '-') ? -1 : (match[1] === '+') ? 1 : 1;
16000
+ sign = (match[1] === '-') ? -1 : 1;
15956
16001
  duration = {
15957
16002
  y : parseIso(match[2], sign),
15958
16003
  M : parseIso(match[3], sign),
@@ -15994,7 +16039,7 @@ moment.tz.load(require('./data/packed/latest.json'));
15994
16039
  }
15995
16040
 
15996
16041
  function positiveMomentsDifference(base, other) {
15997
- var res = {milliseconds: 0, months: 0};
16042
+ var res = {};
15998
16043
 
15999
16044
  res.months = other.month() - base.month() +
16000
16045
  (other.year() - base.year()) * 12;
@@ -16103,7 +16148,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16103
16148
  if (!(this.isValid() && localInput.isValid())) {
16104
16149
  return false;
16105
16150
  }
16106
- units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
16151
+ units = normalizeUnits(units) || 'millisecond';
16107
16152
  if (units === 'millisecond') {
16108
16153
  return this.valueOf() > localInput.valueOf();
16109
16154
  } else {
@@ -16116,7 +16161,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16116
16161
  if (!(this.isValid() && localInput.isValid())) {
16117
16162
  return false;
16118
16163
  }
16119
- units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
16164
+ units = normalizeUnits(units) || 'millisecond';
16120
16165
  if (units === 'millisecond') {
16121
16166
  return this.valueOf() < localInput.valueOf();
16122
16167
  } else {
@@ -16125,9 +16170,14 @@ moment.tz.load(require('./data/packed/latest.json'));
16125
16170
  }
16126
16171
 
16127
16172
  function isBetween (from, to, units, inclusivity) {
16173
+ var localFrom = isMoment(from) ? from : createLocal(from),
16174
+ localTo = isMoment(to) ? to : createLocal(to);
16175
+ if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) {
16176
+ return false;
16177
+ }
16128
16178
  inclusivity = inclusivity || '()';
16129
- return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
16130
- (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
16179
+ return (inclusivity[0] === '(' ? this.isAfter(localFrom, units) : !this.isBefore(localFrom, units)) &&
16180
+ (inclusivity[1] === ')' ? this.isBefore(localTo, units) : !this.isAfter(localTo, units));
16131
16181
  }
16132
16182
 
16133
16183
  function isSame (input, units) {
@@ -16136,7 +16186,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16136
16186
  if (!(this.isValid() && localInput.isValid())) {
16137
16187
  return false;
16138
16188
  }
16139
- units = normalizeUnits(units || 'millisecond');
16189
+ units = normalizeUnits(units) || 'millisecond';
16140
16190
  if (units === 'millisecond') {
16141
16191
  return this.valueOf() === localInput.valueOf();
16142
16192
  } else {
@@ -16146,11 +16196,11 @@ moment.tz.load(require('./data/packed/latest.json'));
16146
16196
  }
16147
16197
 
16148
16198
  function isSameOrAfter (input, units) {
16149
- return this.isSame(input, units) || this.isAfter(input,units);
16199
+ return this.isSame(input, units) || this.isAfter(input, units);
16150
16200
  }
16151
16201
 
16152
16202
  function isSameOrBefore (input, units) {
16153
- return this.isSame(input, units) || this.isBefore(input,units);
16203
+ return this.isSame(input, units) || this.isBefore(input, units);
16154
16204
  }
16155
16205
 
16156
16206
  function diff (input, units, asFloat) {
@@ -16327,62 +16377,130 @@ moment.tz.load(require('./data/packed/latest.json'));
16327
16377
  return this._locale;
16328
16378
  }
16329
16379
 
16380
+ var MS_PER_SECOND = 1000;
16381
+ var MS_PER_MINUTE = 60 * MS_PER_SECOND;
16382
+ var MS_PER_HOUR = 60 * MS_PER_MINUTE;
16383
+ var MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
16384
+
16385
+ // actual modulo - handles negative numbers (for dates before 1970):
16386
+ function mod$1(dividend, divisor) {
16387
+ return (dividend % divisor + divisor) % divisor;
16388
+ }
16389
+
16390
+ function localStartOfDate(y, m, d) {
16391
+ // the date constructor remaps years 0-99 to 1900-1999
16392
+ if (y < 100 && y >= 0) {
16393
+ // preserve leap years using a full 400 year cycle, then reset
16394
+ return new Date(y + 400, m, d) - MS_PER_400_YEARS;
16395
+ } else {
16396
+ return new Date(y, m, d).valueOf();
16397
+ }
16398
+ }
16399
+
16400
+ function utcStartOfDate(y, m, d) {
16401
+ // Date.UTC remaps years 0-99 to 1900-1999
16402
+ if (y < 100 && y >= 0) {
16403
+ // preserve leap years using a full 400 year cycle, then reset
16404
+ return Date.UTC(y + 400, m, d) - MS_PER_400_YEARS;
16405
+ } else {
16406
+ return Date.UTC(y, m, d);
16407
+ }
16408
+ }
16409
+
16330
16410
  function startOf (units) {
16411
+ var time;
16331
16412
  units = normalizeUnits(units);
16332
- // the following switch intentionally omits break keywords
16333
- // to utilize falling through the cases.
16413
+ if (units === undefined || units === 'millisecond' || !this.isValid()) {
16414
+ return this;
16415
+ }
16416
+
16417
+ var startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
16418
+
16334
16419
  switch (units) {
16335
16420
  case 'year':
16336
- this.month(0);
16337
- /* falls through */
16421
+ time = startOfDate(this.year(), 0, 1);
16422
+ break;
16338
16423
  case 'quarter':
16424
+ time = startOfDate(this.year(), this.month() - this.month() % 3, 1);
16425
+ break;
16339
16426
  case 'month':
16340
- this.date(1);
16341
- /* falls through */
16427
+ time = startOfDate(this.year(), this.month(), 1);
16428
+ break;
16342
16429
  case 'week':
16430
+ time = startOfDate(this.year(), this.month(), this.date() - this.weekday());
16431
+ break;
16343
16432
  case 'isoWeek':
16433
+ time = startOfDate(this.year(), this.month(), this.date() - (this.isoWeekday() - 1));
16434
+ break;
16344
16435
  case 'day':
16345
16436
  case 'date':
16346
- this.hours(0);
16347
- /* falls through */
16437
+ time = startOfDate(this.year(), this.month(), this.date());
16438
+ break;
16348
16439
  case 'hour':
16349
- this.minutes(0);
16350
- /* falls through */
16440
+ time = this._d.valueOf();
16441
+ time -= mod$1(time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE), MS_PER_HOUR);
16442
+ break;
16351
16443
  case 'minute':
16352
- this.seconds(0);
16353
- /* falls through */
16444
+ time = this._d.valueOf();
16445
+ time -= mod$1(time, MS_PER_MINUTE);
16446
+ break;
16354
16447
  case 'second':
16355
- this.milliseconds(0);
16356
- }
16357
-
16358
- // weeks are a special case
16359
- if (units === 'week') {
16360
- this.weekday(0);
16361
- }
16362
- if (units === 'isoWeek') {
16363
- this.isoWeekday(1);
16364
- }
16365
-
16366
- // quarters are also special
16367
- if (units === 'quarter') {
16368
- this.month(Math.floor(this.month() / 3) * 3);
16448
+ time = this._d.valueOf();
16449
+ time -= mod$1(time, MS_PER_SECOND);
16450
+ break;
16369
16451
  }
16370
16452
 
16453
+ this._d.setTime(time);
16454
+ hooks.updateOffset(this, true);
16371
16455
  return this;
16372
16456
  }
16373
16457
 
16374
16458
  function endOf (units) {
16459
+ var time;
16375
16460
  units = normalizeUnits(units);
16376
- if (units === undefined || units === 'millisecond') {
16461
+ if (units === undefined || units === 'millisecond' || !this.isValid()) {
16377
16462
  return this;
16378
16463
  }
16379
16464
 
16380
- // 'date' is an alias for 'day', so it should be considered as such.
16381
- if (units === 'date') {
16382
- units = 'day';
16465
+ var startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
16466
+
16467
+ switch (units) {
16468
+ case 'year':
16469
+ time = startOfDate(this.year() + 1, 0, 1) - 1;
16470
+ break;
16471
+ case 'quarter':
16472
+ time = startOfDate(this.year(), this.month() - this.month() % 3 + 3, 1) - 1;
16473
+ break;
16474
+ case 'month':
16475
+ time = startOfDate(this.year(), this.month() + 1, 1) - 1;
16476
+ break;
16477
+ case 'week':
16478
+ time = startOfDate(this.year(), this.month(), this.date() - this.weekday() + 7) - 1;
16479
+ break;
16480
+ case 'isoWeek':
16481
+ time = startOfDate(this.year(), this.month(), this.date() - (this.isoWeekday() - 1) + 7) - 1;
16482
+ break;
16483
+ case 'day':
16484
+ case 'date':
16485
+ time = startOfDate(this.year(), this.month(), this.date() + 1) - 1;
16486
+ break;
16487
+ case 'hour':
16488
+ time = this._d.valueOf();
16489
+ time += MS_PER_HOUR - mod$1(time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE), MS_PER_HOUR) - 1;
16490
+ break;
16491
+ case 'minute':
16492
+ time = this._d.valueOf();
16493
+ time += MS_PER_MINUTE - mod$1(time, MS_PER_MINUTE) - 1;
16494
+ break;
16495
+ case 'second':
16496
+ time = this._d.valueOf();
16497
+ time += MS_PER_SECOND - mod$1(time, MS_PER_SECOND) - 1;
16498
+ break;
16383
16499
  }
16384
16500
 
16385
- return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
16501
+ this._d.setTime(time);
16502
+ hooks.updateOffset(this, true);
16503
+ return this;
16386
16504
  }
16387
16505
 
16388
16506
  function valueOf () {
@@ -17088,10 +17206,14 @@ moment.tz.load(require('./data/packed/latest.json'));
17088
17206
 
17089
17207
  units = normalizeUnits(units);
17090
17208
 
17091
- if (units === 'month' || units === 'year') {
17092
- days = this._days + milliseconds / 864e5;
17209
+ if (units === 'month' || units === 'quarter' || units === 'year') {
17210
+ days = this._days + milliseconds / 864e5;
17093
17211
  months = this._months + daysToMonths(days);
17094
- return units === 'month' ? months : months / 12;
17212
+ switch (units) {
17213
+ case 'month': return months;
17214
+ case 'quarter': return months / 3;
17215
+ case 'year': return months / 12;
17216
+ }
17095
17217
  } else {
17096
17218
  // handle milliseconds separately because of floating point math errors (issue #1867)
17097
17219
  days = this._days + Math.round(monthsToDays(this._months));
@@ -17134,6 +17256,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17134
17256
  var asDays = makeAs('d');
17135
17257
  var asWeeks = makeAs('w');
17136
17258
  var asMonths = makeAs('M');
17259
+ var asQuarters = makeAs('Q');
17137
17260
  var asYears = makeAs('y');
17138
17261
 
17139
17262
  function clone$1 () {
@@ -17325,6 +17448,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17325
17448
  proto$2.asDays = asDays;
17326
17449
  proto$2.asWeeks = asWeeks;
17327
17450
  proto$2.asMonths = asMonths;
17451
+ proto$2.asQuarters = asQuarters;
17328
17452
  proto$2.asYears = asYears;
17329
17453
  proto$2.valueOf = valueOf$1;
17330
17454
  proto$2._bubble = bubble;
@@ -17369,7 +17493,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17369
17493
  // Side effect imports
17370
17494
 
17371
17495
 
17372
- hooks.version = '2.22.2';
17496
+ hooks.version = '2.24.0';
17373
17497
 
17374
17498
  setHookCallback(createLocal);
17375
17499
 
@@ -17410,7 +17534,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17410
17534
  TIME: 'HH:mm', // <input type="time" />
17411
17535
  TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" />
17412
17536
  TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
17413
- WEEK: 'YYYY-[W]WW', // <input type="week" />
17537
+ WEEK: 'GGGG-[W]WW', // <input type="week" />
17414
17538
  MONTH: 'YYYY-MM' // <input type="month" />
17415
17539
  };
17416
17540