...
|
...
|
@@ -174,19 +174,18 @@ export const QuickTimeIntervalTranslationMap = new Map<QuickTimeInterval, string |
174
|
174
|
]);
|
175
|
175
|
|
176
|
176
|
export function historyInterval(timewindowMs: number): Timewindow {
|
177
|
|
- const timewindow: Timewindow = {
|
|
177
|
+ return {
|
178
|
178
|
selectedTab: TimewindowType.HISTORY,
|
179
|
179
|
history: {
|
180
|
180
|
historyType: HistoryWindowType.LAST_INTERVAL,
|
181
|
181
|
timewindowMs
|
182
|
182
|
}
|
183
|
183
|
};
|
184
|
|
- return timewindow;
|
185
|
184
|
}
|
186
|
185
|
|
187
|
186
|
export function defaultTimewindow(timeService: TimeService): Timewindow {
|
188
|
187
|
const currentTime = moment().valueOf();
|
189
|
|
- const timewindow: Timewindow = {
|
|
188
|
+ return {
|
190
|
189
|
displayValue: '',
|
191
|
190
|
hideInterval: false,
|
192
|
191
|
hideAggregation: false,
|
...
|
...
|
@@ -214,7 +213,6 @@ export function defaultTimewindow(timeService: TimeService): Timewindow { |
214
|
213
|
limit: Math.floor(timeService.getMaxDatapointsLimit() / 2)
|
215
|
214
|
}
|
216
|
215
|
};
|
217
|
|
- return timewindow;
|
218
|
216
|
}
|
219
|
217
|
|
220
|
218
|
function getTimewindowType(timewindow: Timewindow): TimewindowType {
|
...
|
...
|
@@ -304,7 +302,7 @@ export function toHistoryTimewindow(timewindow: Timewindow, startTimeMs: number, |
304
|
302
|
aggType = AggregationType.AVG;
|
305
|
303
|
limit = timeService.getMaxDatapointsLimit();
|
306
|
304
|
}
|
307
|
|
- const historyTimewindow: Timewindow = {
|
|
305
|
+ return {
|
308
|
306
|
hideInterval: timewindow.hideInterval || false,
|
309
|
307
|
hideAggregation: timewindow.hideAggregation || false,
|
310
|
308
|
hideAggInterval: timewindow.hideAggInterval || false,
|
...
|
...
|
@@ -324,7 +322,6 @@ export function toHistoryTimewindow(timewindow: Timewindow, startTimeMs: number, |
324
|
322
|
},
|
325
|
323
|
timezone: timewindow.timezone
|
326
|
324
|
};
|
327
|
|
- return historyTimewindow;
|
328
|
325
|
}
|
329
|
326
|
|
330
|
327
|
export function timewindowTypeChanged(newTimewindow: Timewindow, oldTimewindow: Timewindow): boolean {
|
...
|
...
|
@@ -363,7 +360,7 @@ export function createSubscriptionTimewindow(timewindow: Timewindow, stDiff: num |
363
|
360
|
timezone: timewindow.timezone,
|
364
|
361
|
tsOffset: calculateTsOffset(timewindow.timezone)
|
365
|
362
|
};
|
366
|
|
- let aggTimewindow = 0;
|
|
363
|
+ let aggTimewindow;
|
367
|
364
|
if (stateData) {
|
368
|
365
|
subscriptionTimewindow.aggregation.type = AggregationType.NONE;
|
369
|
366
|
subscriptionTimewindow.aggregation.stateData = true;
|
...
|
...
|
@@ -385,14 +382,15 @@ export function createSubscriptionTimewindow(timewindow: Timewindow, stDiff: num |
385
|
382
|
}
|
386
|
383
|
}
|
387
|
384
|
if (realtimeType === RealtimeWindowType.INTERVAL) {
|
388
|
|
- const currentDate = getCurrentTime(timewindow.timezone);
|
389
|
385
|
subscriptionTimewindow.realtimeWindowMs =
|
390
|
|
- getSubscriptionRealtimeWindowFromTimeInterval(timewindow.realtime.quickInterval, currentDate);
|
|
386
|
+ getSubscriptionRealtimeWindowFromTimeInterval(timewindow.realtime.quickInterval, timewindow.timezone);
|
391
|
387
|
subscriptionTimewindow.quickInterval = timewindow.realtime.quickInterval;
|
392
|
|
- subscriptionTimewindow.startTs = calculateIntervalStartTime(timewindow.realtime.quickInterval, currentDate);
|
|
388
|
+ const currentDate = getCurrentTime(timewindow.timezone);
|
|
389
|
+ subscriptionTimewindow.startTs = calculateIntervalStartTime(timewindow.realtime.quickInterval, currentDate).valueOf();
|
393
|
390
|
} else {
|
394
|
391
|
subscriptionTimewindow.realtimeWindowMs = timewindow.realtime.timewindowMs;
|
395
|
|
- subscriptionTimewindow.startTs = Date.now() + stDiff - subscriptionTimewindow.realtimeWindowMs;
|
|
392
|
+ const currentDate = getCurrentTime(timewindow.timezone);
|
|
393
|
+ subscriptionTimewindow.startTs = currentDate.valueOf() + stDiff - subscriptionTimewindow.realtimeWindowMs;
|
396
|
394
|
}
|
397
|
395
|
subscriptionTimewindow.aggregation.interval =
|
398
|
396
|
timeService.boundIntervalToTimewindow(subscriptionTimewindow.realtimeWindowMs, timewindow.realtime.interval,
|
...
|
...
|
@@ -425,10 +423,10 @@ export function createSubscriptionTimewindow(timewindow: Timewindow, stDiff: num |
425
|
423
|
};
|
426
|
424
|
aggTimewindow = timewindow.history.timewindowMs;
|
427
|
425
|
} else if (historyType === HistoryWindowType.INTERVAL) {
|
428
|
|
- const currentDate = getCurrentTime(timewindow.timezone);
|
|
426
|
+ const startEndTime = calculateIntervalStartEndTime(timewindow.history.quickInterval, timewindow.timezone);
|
429
|
427
|
subscriptionTimewindow.fixedWindow = {
|
430
|
|
- startTimeMs: calculateIntervalStartTime(timewindow.history.quickInterval, currentDate),
|
431
|
|
- endTimeMs: calculateIntervalEndTime(timewindow.history.quickInterval, currentDate)
|
|
428
|
+ startTimeMs: startEndTime[0],
|
|
429
|
+ endTimeMs: startEndTime[1]
|
432
|
430
|
};
|
433
|
431
|
aggTimewindow = subscriptionTimewindow.fixedWindow.endTimeMs - subscriptionTimewindow.fixedWindow.startTimeMs;
|
434
|
432
|
subscriptionTimewindow.quickInterval = timewindow.history.quickInterval;
|
...
|
...
|
@@ -451,7 +449,8 @@ export function createSubscriptionTimewindow(timewindow: Timewindow, stDiff: num |
451
|
449
|
return subscriptionTimewindow;
|
452
|
450
|
}
|
453
|
451
|
|
454
|
|
-function getSubscriptionRealtimeWindowFromTimeInterval(interval: QuickTimeInterval, currentDate: moment_.Moment): number {
|
|
452
|
+function getSubscriptionRealtimeWindowFromTimeInterval(interval: QuickTimeInterval, tz?: string): number {
|
|
453
|
+ let currentDate;
|
455
|
454
|
switch (interval) {
|
456
|
455
|
case QuickTimeInterval.CURRENT_HOUR:
|
457
|
456
|
return HOUR;
|
...
|
...
|
@@ -465,99 +464,94 @@ function getSubscriptionRealtimeWindowFromTimeInterval(interval: QuickTimeInterv |
465
|
464
|
return WEEK;
|
466
|
465
|
case QuickTimeInterval.CURRENT_MONTH:
|
467
|
466
|
case QuickTimeInterval.CURRENT_MONTH_SO_FAR:
|
|
467
|
+ currentDate = getCurrentTime(tz);
|
468
|
468
|
return currentDate.endOf('month').diff(currentDate.clone().startOf('month'));
|
469
|
469
|
case QuickTimeInterval.CURRENT_YEAR:
|
470
|
470
|
case QuickTimeInterval.CURRENT_YEAR_SO_FAR:
|
|
471
|
+ currentDate = getCurrentTime(tz);
|
471
|
472
|
return currentDate.endOf('year').diff(currentDate.clone().startOf('year'));
|
472
|
473
|
}
|
473
|
474
|
}
|
474
|
475
|
|
475
|
|
-export function calculateIntervalEndTime(interval: QuickTimeInterval, currentDate: moment_.Moment = null, tz: string = ''): number {
|
476
|
|
- currentDate = currentDate ? currentDate.clone() : getCurrentTime(tz);
|
477
|
|
- switch (interval) {
|
478
|
|
- case QuickTimeInterval.YESTERDAY:
|
479
|
|
- currentDate.subtract(1, 'days');
|
480
|
|
- return currentDate.endOf('day').valueOf();
|
481
|
|
- case QuickTimeInterval.DAY_BEFORE_YESTERDAY:
|
482
|
|
- currentDate.subtract(2, 'days');
|
483
|
|
- return currentDate.endOf('day').valueOf();
|
484
|
|
- case QuickTimeInterval.THIS_DAY_LAST_WEEK:
|
485
|
|
- currentDate.subtract(1, 'weeks');
|
486
|
|
- return currentDate.endOf('day').valueOf();
|
487
|
|
- case QuickTimeInterval.PREVIOUS_WEEK:
|
488
|
|
- currentDate.subtract(1, 'weeks');
|
489
|
|
- return currentDate.endOf('week').valueOf();
|
490
|
|
- case QuickTimeInterval.PREVIOUS_WEEK_ISO:
|
491
|
|
- currentDate.subtract(1, 'weeks');
|
492
|
|
- return currentDate.endOf('isoWeek').valueOf();
|
493
|
|
- case QuickTimeInterval.PREVIOUS_MONTH:
|
494
|
|
- currentDate.subtract(1, 'months');
|
495
|
|
- return currentDate.endOf('month').valueOf();
|
496
|
|
- case QuickTimeInterval.PREVIOUS_YEAR:
|
497
|
|
- currentDate.subtract(1, 'years');
|
498
|
|
- return currentDate.endOf('year').valueOf();
|
499
|
|
- case QuickTimeInterval.CURRENT_HOUR:
|
500
|
|
- return currentDate.endOf('hour').valueOf();
|
501
|
|
- case QuickTimeInterval.CURRENT_DAY:
|
502
|
|
- return currentDate.endOf('day').valueOf();
|
503
|
|
- case QuickTimeInterval.CURRENT_WEEK:
|
504
|
|
- return currentDate.endOf('week').valueOf();
|
505
|
|
- case QuickTimeInterval.CURRENT_WEEK_ISO:
|
506
|
|
- return currentDate.endOf('isoWeek').valueOf();
|
507
|
|
- case QuickTimeInterval.CURRENT_MONTH:
|
508
|
|
- return currentDate.endOf('month').valueOf();
|
509
|
|
- case QuickTimeInterval.CURRENT_YEAR:
|
510
|
|
- return currentDate.endOf('year').valueOf();
|
511
|
|
- case QuickTimeInterval.CURRENT_DAY_SO_FAR:
|
512
|
|
- case QuickTimeInterval.CURRENT_WEEK_SO_FAR:
|
513
|
|
- case QuickTimeInterval.CURRENT_WEEK_ISO_SO_FAR:
|
514
|
|
- case QuickTimeInterval.CURRENT_MONTH_SO_FAR:
|
515
|
|
- case QuickTimeInterval.CURRENT_YEAR_SO_FAR:
|
516
|
|
- return currentDate.valueOf();
|
517
|
|
- }
|
|
476
|
+export function calculateIntervalStartEndTime(interval: QuickTimeInterval, tz?: string): [number, number] {
|
|
477
|
+ const startEndTs: [number, number] = [0, 0];
|
|
478
|
+ const currentDate = getCurrentTime(tz);
|
|
479
|
+ const startDate = calculateIntervalStartTime(interval, currentDate);
|
|
480
|
+ startEndTs[0] = startDate.valueOf();
|
|
481
|
+ const endDate = calculateIntervalEndTime(interval, startDate, tz);
|
|
482
|
+ startEndTs[1] = endDate.valueOf();
|
|
483
|
+ return startEndTs;
|
518
|
484
|
}
|
519
|
485
|
|
520
|
|
-export function calculateIntervalStartTime(interval: QuickTimeInterval, currentDate: moment_.Moment = null, tz: string = ''): number {
|
521
|
|
- currentDate = currentDate ? currentDate.clone() : getCurrentTime(tz);
|
|
486
|
+export function calculateIntervalStartTime(interval: QuickTimeInterval, currentDate: moment_.Moment): moment_.Moment {
|
522
|
487
|
switch (interval) {
|
523
|
488
|
case QuickTimeInterval.YESTERDAY:
|
524
|
489
|
currentDate.subtract(1, 'days');
|
525
|
|
- return currentDate.startOf('day').valueOf();
|
|
490
|
+ return currentDate.startOf('day');
|
526
|
491
|
case QuickTimeInterval.DAY_BEFORE_YESTERDAY:
|
527
|
492
|
currentDate.subtract(2, 'days');
|
528
|
|
- return currentDate.startOf('day').valueOf();
|
|
493
|
+ return currentDate.startOf('day');
|
529
|
494
|
case QuickTimeInterval.THIS_DAY_LAST_WEEK:
|
530
|
495
|
currentDate.subtract(1, 'weeks');
|
531
|
|
- return currentDate.startOf('day').valueOf();
|
|
496
|
+ return currentDate.startOf('day');
|
532
|
497
|
case QuickTimeInterval.PREVIOUS_WEEK:
|
533
|
498
|
currentDate.subtract(1, 'weeks');
|
534
|
|
- return currentDate.startOf('week').valueOf();
|
|
499
|
+ return currentDate.startOf('week');
|
535
|
500
|
case QuickTimeInterval.PREVIOUS_WEEK_ISO:
|
536
|
501
|
currentDate.subtract(1, 'weeks');
|
537
|
|
- return currentDate.startOf('isoWeek').valueOf();
|
|
502
|
+ return currentDate.startOf('isoWeek');
|
538
|
503
|
case QuickTimeInterval.PREVIOUS_MONTH:
|
539
|
504
|
currentDate.subtract(1, 'months');
|
540
|
|
- return currentDate.startOf('month').valueOf();
|
|
505
|
+ return currentDate.startOf('month');
|
541
|
506
|
case QuickTimeInterval.PREVIOUS_YEAR:
|
542
|
507
|
currentDate.subtract(1, 'years');
|
543
|
|
- return currentDate.startOf('year').valueOf();
|
|
508
|
+ return currentDate.startOf('year');
|
544
|
509
|
case QuickTimeInterval.CURRENT_HOUR:
|
545
|
|
- return currentDate.startOf('hour').valueOf();
|
|
510
|
+ return currentDate.startOf('hour');
|
546
|
511
|
case QuickTimeInterval.CURRENT_DAY:
|
547
|
512
|
case QuickTimeInterval.CURRENT_DAY_SO_FAR:
|
548
|
|
- return currentDate.startOf('day').valueOf();
|
|
513
|
+ return currentDate.startOf('day');
|
549
|
514
|
case QuickTimeInterval.CURRENT_WEEK:
|
550
|
515
|
case QuickTimeInterval.CURRENT_WEEK_SO_FAR:
|
551
|
|
- return currentDate.startOf('week').valueOf();
|
|
516
|
+ return currentDate.startOf('week');
|
552
|
517
|
case QuickTimeInterval.CURRENT_WEEK_ISO:
|
553
|
518
|
case QuickTimeInterval.CURRENT_WEEK_ISO_SO_FAR:
|
554
|
|
- return currentDate.startOf('isoWeek').valueOf();
|
|
519
|
+ return currentDate.startOf('isoWeek');
|
555
|
520
|
case QuickTimeInterval.CURRENT_MONTH:
|
556
|
521
|
case QuickTimeInterval.CURRENT_MONTH_SO_FAR:
|
557
|
|
- return currentDate.startOf('month').valueOf();
|
|
522
|
+ return currentDate.startOf('month');
|
558
|
523
|
case QuickTimeInterval.CURRENT_YEAR:
|
559
|
524
|
case QuickTimeInterval.CURRENT_YEAR_SO_FAR:
|
560
|
|
- return currentDate.startOf('year').valueOf();
|
|
525
|
+ return currentDate.startOf('year');
|
|
526
|
+ }
|
|
527
|
+}
|
|
528
|
+
|
|
529
|
+export function calculateIntervalEndTime(interval: QuickTimeInterval, startDate: moment_.Moment, tz?: string): number {
|
|
530
|
+ switch (interval) {
|
|
531
|
+ case QuickTimeInterval.YESTERDAY:
|
|
532
|
+ case QuickTimeInterval.DAY_BEFORE_YESTERDAY:
|
|
533
|
+ case QuickTimeInterval.THIS_DAY_LAST_WEEK:
|
|
534
|
+ case QuickTimeInterval.CURRENT_DAY:
|
|
535
|
+ return startDate.add(1, 'day').valueOf();
|
|
536
|
+ case QuickTimeInterval.PREVIOUS_WEEK:
|
|
537
|
+ case QuickTimeInterval.PREVIOUS_WEEK_ISO:
|
|
538
|
+ case QuickTimeInterval.CURRENT_WEEK:
|
|
539
|
+ case QuickTimeInterval.CURRENT_WEEK_ISO:
|
|
540
|
+ return startDate.add(1, 'week').valueOf();
|
|
541
|
+ case QuickTimeInterval.PREVIOUS_MONTH:
|
|
542
|
+ case QuickTimeInterval.CURRENT_MONTH:
|
|
543
|
+ return startDate.add(1, 'month').valueOf();
|
|
544
|
+ case QuickTimeInterval.PREVIOUS_YEAR:
|
|
545
|
+ case QuickTimeInterval.CURRENT_YEAR:
|
|
546
|
+ return startDate.add(1, 'year').valueOf();
|
|
547
|
+ case QuickTimeInterval.CURRENT_HOUR:
|
|
548
|
+ return startDate.add(1, 'hour').valueOf();
|
|
549
|
+ case QuickTimeInterval.CURRENT_DAY_SO_FAR:
|
|
550
|
+ case QuickTimeInterval.CURRENT_WEEK_SO_FAR:
|
|
551
|
+ case QuickTimeInterval.CURRENT_WEEK_ISO_SO_FAR:
|
|
552
|
+ case QuickTimeInterval.CURRENT_MONTH_SO_FAR:
|
|
553
|
+ case QuickTimeInterval.CURRENT_YEAR_SO_FAR:
|
|
554
|
+ return getCurrentTime(tz).valueOf();
|
561
|
555
|
}
|
562
|
556
|
}
|
563
|
557
|
|
...
|
...
|
@@ -590,82 +584,58 @@ export function quickTimeIntervalPeriod(interval: QuickTimeInterval): number { |
590
|
584
|
}
|
591
|
585
|
|
592
|
586
|
export function calculateIntervalComparisonStartTime(interval: QuickTimeInterval,
|
593
|
|
- currentDate: moment_.Moment): number {
|
|
587
|
+ startDate: moment_.Moment): moment_.Moment {
|
594
|
588
|
switch (interval) {
|
595
|
589
|
case QuickTimeInterval.YESTERDAY:
|
596
|
590
|
case QuickTimeInterval.DAY_BEFORE_YESTERDAY:
|
597
|
591
|
case QuickTimeInterval.CURRENT_DAY:
|
598
|
592
|
case QuickTimeInterval.CURRENT_DAY_SO_FAR:
|
599
|
|
- currentDate.subtract(1, 'days');
|
600
|
|
- return currentDate.startOf('day').valueOf();
|
|
593
|
+ startDate.subtract(1, 'days');
|
|
594
|
+ return startDate.startOf('day');
|
601
|
595
|
case QuickTimeInterval.THIS_DAY_LAST_WEEK:
|
602
|
|
- currentDate.subtract(1, 'weeks');
|
603
|
|
- return currentDate.startOf('day').valueOf();
|
|
596
|
+ startDate.subtract(1, 'weeks');
|
|
597
|
+ return startDate.startOf('day');
|
604
|
598
|
case QuickTimeInterval.PREVIOUS_WEEK:
|
605
|
599
|
case QuickTimeInterval.CURRENT_WEEK:
|
606
|
600
|
case QuickTimeInterval.CURRENT_WEEK_SO_FAR:
|
607
|
|
- currentDate.subtract(1, 'weeks');
|
608
|
|
- return currentDate.startOf('week').valueOf();
|
|
601
|
+ startDate.subtract(1, 'weeks');
|
|
602
|
+ return startDate.startOf('week');
|
609
|
603
|
case QuickTimeInterval.PREVIOUS_WEEK_ISO:
|
610
|
604
|
case QuickTimeInterval.CURRENT_WEEK_ISO:
|
611
|
605
|
case QuickTimeInterval.CURRENT_WEEK_ISO_SO_FAR:
|
612
|
|
- currentDate.subtract(1, 'weeks');
|
613
|
|
- return currentDate.startOf('isoWeek').valueOf();
|
|
606
|
+ startDate.subtract(1, 'weeks');
|
|
607
|
+ return startDate.startOf('isoWeek');
|
614
|
608
|
case QuickTimeInterval.PREVIOUS_MONTH:
|
615
|
609
|
case QuickTimeInterval.CURRENT_MONTH:
|
616
|
610
|
case QuickTimeInterval.CURRENT_MONTH_SO_FAR:
|
617
|
|
- currentDate.subtract(1, 'months');
|
618
|
|
- return currentDate.startOf('month').valueOf();
|
|
611
|
+ startDate.subtract(1, 'months');
|
|
612
|
+ return startDate.startOf('month');
|
619
|
613
|
case QuickTimeInterval.PREVIOUS_YEAR:
|
620
|
614
|
case QuickTimeInterval.CURRENT_YEAR:
|
621
|
615
|
case QuickTimeInterval.CURRENT_YEAR_SO_FAR:
|
622
|
|
- currentDate.subtract(1, 'years');
|
623
|
|
- return currentDate.startOf('year').valueOf();
|
|
616
|
+ startDate.subtract(1, 'years');
|
|
617
|
+ return startDate.startOf('year');
|
624
|
618
|
case QuickTimeInterval.CURRENT_HOUR:
|
625
|
|
- currentDate.subtract(1, 'hour');
|
626
|
|
- return currentDate.startOf('hour').valueOf();
|
|
619
|
+ startDate.subtract(1, 'hour');
|
|
620
|
+ return startDate.startOf('hour');
|
627
|
621
|
}
|
628
|
622
|
}
|
629
|
623
|
|
630
|
624
|
export function calculateIntervalComparisonEndTime(interval: QuickTimeInterval,
|
631
|
|
- currentDate: moment_.Moment): number {
|
|
625
|
+ comparisonStartDate: moment_.Moment,
|
|
626
|
+ endDate: moment_.Moment): number {
|
632
|
627
|
switch (interval) {
|
633
|
|
- case QuickTimeInterval.YESTERDAY:
|
634
|
|
- case QuickTimeInterval.DAY_BEFORE_YESTERDAY:
|
635
|
|
- case QuickTimeInterval.CURRENT_DAY:
|
636
|
|
- currentDate.subtract(1, 'days');
|
637
|
|
- return currentDate.endOf('day').valueOf();
|
638
|
628
|
case QuickTimeInterval.CURRENT_DAY_SO_FAR:
|
639
|
|
- return currentDate.subtract(1, 'days').valueOf();
|
640
|
|
- case QuickTimeInterval.THIS_DAY_LAST_WEEK:
|
641
|
|
- currentDate.subtract(1, 'weeks');
|
642
|
|
- return currentDate.endOf('day').valueOf();
|
643
|
|
- case QuickTimeInterval.PREVIOUS_WEEK:
|
644
|
|
- case QuickTimeInterval.CURRENT_WEEK:
|
645
|
|
- currentDate.subtract(1, 'weeks');
|
646
|
|
- return currentDate.endOf('week').valueOf();
|
647
|
|
- case QuickTimeInterval.PREVIOUS_WEEK_ISO:
|
648
|
|
- case QuickTimeInterval.CURRENT_WEEK_ISO:
|
649
|
|
- currentDate.subtract(1, 'weeks');
|
650
|
|
- return currentDate.endOf('isoWeek').valueOf();
|
|
629
|
+ return endDate.subtract(1, 'days').valueOf();
|
651
|
630
|
case QuickTimeInterval.CURRENT_WEEK_SO_FAR:
|
652
|
631
|
case QuickTimeInterval.CURRENT_WEEK_ISO_SO_FAR:
|
653
|
|
- return currentDate.subtract(1, 'week').valueOf();
|
654
|
|
- case QuickTimeInterval.PREVIOUS_MONTH:
|
655
|
|
- case QuickTimeInterval.CURRENT_MONTH:
|
656
|
|
- currentDate.subtract(1, 'months');
|
657
|
|
- return currentDate.endOf('month').valueOf();
|
|
632
|
+ return endDate.subtract(1, 'week').valueOf();
|
658
|
633
|
case QuickTimeInterval.CURRENT_MONTH_SO_FAR:
|
659
|
|
- return currentDate.subtract(1, 'month').valueOf();
|
660
|
|
- case QuickTimeInterval.PREVIOUS_YEAR:
|
661
|
|
- case QuickTimeInterval.CURRENT_YEAR:
|
662
|
|
- currentDate.subtract(1, 'years');
|
663
|
|
- return currentDate.endOf('year').valueOf();
|
|
634
|
+ return endDate.subtract(1, 'month').valueOf();
|
664
|
635
|
case QuickTimeInterval.CURRENT_YEAR_SO_FAR:
|
665
|
|
- return currentDate.subtract(1, 'year').valueOf();
|
666
|
|
- case QuickTimeInterval.CURRENT_HOUR:
|
667
|
|
- currentDate.subtract(1, 'hour');
|
668
|
|
- return currentDate.endOf('hour').valueOf();
|
|
636
|
+ return endDate.subtract(1, 'year').valueOf();
|
|
637
|
+ default:
|
|
638
|
+ return calculateIntervalEndTime(interval, comparisonStartDate);
|
669
|
639
|
}
|
670
|
640
|
}
|
671
|
641
|
|
...
|
...
|
@@ -689,8 +659,9 @@ export function createTimewindowForComparison(subscriptionTimewindow: Subscripti |
689
|
659
|
startDate.tz(subscriptionTimewindow.timezone);
|
690
|
660
|
endDate.tz(subscriptionTimewindow.timezone);
|
691
|
661
|
}
|
692
|
|
- startTimeMs = calculateIntervalComparisonStartTime(subscriptionTimewindow.quickInterval, startDate);
|
693
|
|
- endTimeMs = calculateIntervalComparisonEndTime(subscriptionTimewindow.quickInterval, endDate);
|
|
662
|
+ const comparisonStartDate = calculateIntervalComparisonStartTime(subscriptionTimewindow.quickInterval, startDate);
|
|
663
|
+ startTimeMs = comparisonStartDate.valueOf();
|
|
664
|
+ endTimeMs = calculateIntervalComparisonEndTime(subscriptionTimewindow.quickInterval, comparisonStartDate, endDate);
|
694
|
665
|
} else {
|
695
|
666
|
const timeInterval = subscriptionTimewindow.fixedWindow.endTimeMs - subscriptionTimewindow.fixedWindow.startTimeMs;
|
696
|
667
|
endTimeMs = subscriptionTimewindow.fixedWindow.startTimeMs;
|
...
|
...
|
@@ -730,22 +701,6 @@ export function cloneSelectedTimewindow(timewindow: Timewindow): Timewindow { |
730
|
701
|
return cloned;
|
731
|
702
|
}
|
732
|
703
|
|
733
|
|
-export function cloneSelectedHistoryTimewindow(historyWindow: HistoryWindow): HistoryWindow {
|
734
|
|
- const cloned: HistoryWindow = {};
|
735
|
|
- if (isDefined(historyWindow.historyType)) {
|
736
|
|
- cloned.historyType = historyWindow.historyType;
|
737
|
|
- cloned.interval = historyWindow.interval;
|
738
|
|
- if (historyWindow.historyType === HistoryWindowType.LAST_INTERVAL) {
|
739
|
|
- cloned.timewindowMs = historyWindow.timewindowMs;
|
740
|
|
- } else if (historyWindow.historyType === HistoryWindowType.INTERVAL) {
|
741
|
|
- cloned.quickInterval = historyWindow.quickInterval;
|
742
|
|
- } else if (historyWindow.historyType === HistoryWindowType.FIXED) {
|
743
|
|
- cloned.fixedTimewindow = deepClone(historyWindow.fixedTimewindow);
|
744
|
|
- }
|
745
|
|
- }
|
746
|
|
- return cloned;
|
747
|
|
-}
|
748
|
|
-
|
749
|
704
|
export interface TimeInterval {
|
750
|
705
|
name: string;
|
751
|
706
|
translateParams: {[key: string]: any};
|
...
|
...
|
@@ -927,6 +882,14 @@ export function getCurrentTime(tz?: string): moment_.Moment { |
927
|
882
|
}
|
928
|
883
|
}
|
929
|
884
|
|
|
885
|
+export function getTime(ts: number, tz?: string): moment_.Moment {
|
|
886
|
+ if (tz) {
|
|
887
|
+ return moment(ts).tz(tz);
|
|
888
|
+ } else {
|
|
889
|
+ return moment(ts);
|
|
890
|
+ }
|
|
891
|
+}
|
|
892
|
+
|
930
|
893
|
export function getTimezone(tz: string): moment_.Moment {
|
931
|
894
|
return moment.tz(tz);
|
932
|
895
|
}
|
...
|
...
|
|