@sapui5/sap.gantt 1.125.0 → 1.127.0
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.
- package/package.json +1 -1
- package/src/sap/gantt/.library +6 -1
- package/src/sap/gantt/AdhocLine.js +1 -1
- package/src/sap/gantt/GanttChart.js +1 -1
- package/src/sap/gantt/GanttChartBase.js +1 -1
- package/src/sap/gantt/GanttChartContainer.js +1 -1
- package/src/sap/gantt/GanttChartWithTable.js +1 -1
- package/src/sap/gantt/axistime/AxisTimeStrategyBase.js +58 -8
- package/src/sap/gantt/axistime/FullScreenStrategy.js +1 -1
- package/src/sap/gantt/axistime/FullScreenTimeLineOptions.js +7 -1
- package/src/sap/gantt/axistime/ProportionTimeLineOptions.js +7 -1
- package/src/sap/gantt/axistime/ProportionZoomStrategy.js +1 -1
- package/src/sap/gantt/axistime/StepwiseTimeLineOptions.js +7 -1
- package/src/sap/gantt/axistime/StepwiseZoomStrategy.js +10 -4
- package/src/sap/gantt/changeHandlers/simple/AdhocLine.js +1 -1
- package/src/sap/gantt/changeHandlers/simple/DeltaLine.js +1 -1
- package/src/sap/gantt/changeHandlers/simple/GanttChartContainer.js +1 -1
- package/src/sap/gantt/changeHandlers/simple/GanttChartWithTable.js +1 -1
- package/src/sap/gantt/config/BirdEyeGroup.js +1 -1
- package/src/sap/gantt/config/ChartScheme.js +1 -1
- package/src/sap/gantt/config/ColumnAttribute.js +1 -1
- package/src/sap/gantt/config/ContainerLayout.js +1 -1
- package/src/sap/gantt/config/ExpandChart.js +1 -1
- package/src/sap/gantt/config/ExpandChartGroup.js +1 -1
- package/src/sap/gantt/config/GanttChartLayout.js +1 -1
- package/src/sap/gantt/config/Hierarchy.js +1 -1
- package/src/sap/gantt/config/HierarchyColumn.js +1 -1
- package/src/sap/gantt/config/LayoutGroup.js +1 -1
- package/src/sap/gantt/config/Locale.js +1 -1
- package/src/sap/gantt/config/Mode.js +1 -1
- package/src/sap/gantt/config/ModeGroup.js +1 -1
- package/src/sap/gantt/config/ObjectType.js +1 -1
- package/src/sap/gantt/config/SettingGroup.js +1 -1
- package/src/sap/gantt/config/SettingItem.js +1 -1
- package/src/sap/gantt/config/Shape.js +1 -1
- package/src/sap/gantt/config/TimeAxis.js +1 -1
- package/src/sap/gantt/config/TimeHorizon.js +1 -1
- package/src/sap/gantt/config/TimeZoomGroup.js +1 -1
- package/src/sap/gantt/config/ToolbarGroup.js +1 -1
- package/src/sap/gantt/config/ToolbarScheme.js +1 -1
- package/src/sap/gantt/control/Cell.js +1 -1
- package/src/sap/gantt/def/DefBase.js +1 -1
- package/src/sap/gantt/def/SvgDefs.js +1 -1
- package/src/sap/gantt/def/cal/Calendar.js +1 -1
- package/src/sap/gantt/def/cal/CalendarDefs.js +1 -1
- package/src/sap/gantt/def/cal/TimeInterval.js +1 -1
- package/src/sap/gantt/def/filter/MorphologyFilter.js +1 -1
- package/src/sap/gantt/def/gradient/LinearGradient.js +1 -1
- package/src/sap/gantt/def/gradient/RadialGradient.js +1 -1
- package/src/sap/gantt/def/gradient/Stop.js +1 -1
- package/src/sap/gantt/def/pattern/BackSlashPattern.js +1 -1
- package/src/sap/gantt/def/pattern/PatternBase.js +1 -1
- package/src/sap/gantt/def/pattern/SlashPattern.js +1 -1
- package/src/sap/gantt/drawer/AdhocLine.js +1 -1
- package/src/sap/gantt/drawer/Drawer.js +1 -1
- package/src/sap/gantt/drawer/Legend.js +6 -0
- package/src/sap/gantt/drawer/VerticalLine.js +1 -1
- package/src/sap/gantt/eventHandler/AutoScrollHandler.js +1 -1
- package/src/sap/gantt/eventHandler/BirdEyeHandler.js +7 -1
- package/src/sap/gantt/eventHandler/MouseWheelHandler.js +1 -1
- package/src/sap/gantt/eventHandler/ShapeHoverHandler.js +1 -1
- package/src/sap/gantt/eventHandler/ShapeResizeHandler.js +1 -1
- package/src/sap/gantt/eventHandler/TimePeriodZoomHandler.js +1 -1
- package/src/sap/gantt/eventHandler/TimePopoverHandler.js +1 -1
- package/src/sap/gantt/flexibility/simple/AdhocLine.flexibility.js +7 -1
- package/src/sap/gantt/flexibility/simple/DeltaLine.flexibility.js +7 -1
- package/src/sap/gantt/flexibility/simple/GanttChartWithTable.flexibility.js +7 -1
- package/src/sap/gantt/flexibility/simple/GanttTableColumn.flexibility.js +6 -7
- package/src/sap/gantt/layouts/SidePanel.js +1 -1
- package/src/sap/gantt/legend/DimensionLegend.js +1 -1
- package/src/sap/gantt/legend/LegendBase.js +1 -1
- package/src/sap/gantt/legend/LegendContainer.js +1 -1
- package/src/sap/gantt/legend/ListLegend.js +1 -1
- package/src/sap/gantt/library.js +13 -3
- package/src/sap/gantt/messagebundle.properties +8 -2
- package/src/sap/gantt/messagebundle_sh.properties +30 -30
- package/src/sap/gantt/misc/AxisOrdinal.js +1 -1
- package/src/sap/gantt/misc/AxisTime.js +80 -22
- package/src/sap/gantt/misc/Format.js +2 -2
- package/src/sap/gantt/misc/Memoizer.js +1 -1
- package/src/sap/gantt/misc/RelativeTimeFormatter.js +1 -1
- package/src/sap/gantt/misc/ShapeManager.js +1 -1
- package/src/sap/gantt/misc/Utility.js +11 -0
- package/src/sap/gantt/overlays/GanttRowOverlay.js +80 -16
- package/src/sap/gantt/overlays/Overlay.js +1 -1
- package/src/sap/gantt/polyfills/lib.js +7 -1
- package/src/sap/gantt/polyfills/time.js +13 -7
- package/src/sap/gantt/polyfills/timeUtils/day.js +13 -0
- package/src/sap/gantt/polyfills/{time-utils → timeUtils}/dayCount.js +7 -1
- package/src/sap/gantt/polyfills/timeUtils/days.js +13 -0
- package/src/sap/gantt/polyfills/{time-utils → timeUtils}/interval.js +6 -0
- package/src/sap/gantt/polyfills/{time-utils → timeUtils}/millisecond.js +6 -0
- package/src/sap/gantt/polyfills/timeUtils/monday.js +13 -0
- package/src/sap/gantt/polyfills/timeUtils/saturday.js +13 -0
- package/src/sap/gantt/polyfills/timeUtils/weeks.js +13 -0
- package/src/sap/gantt/shape/Circle.js +1 -1
- package/src/sap/gantt/shape/ClipPath.js +1 -1
- package/src/sap/gantt/shape/Definitions.js +1 -1
- package/src/sap/gantt/shape/Group.js +1 -1
- package/src/sap/gantt/shape/Image.js +1 -1
- package/src/sap/gantt/shape/Line.js +1 -1
- package/src/sap/gantt/shape/Path.js +1 -1
- package/src/sap/gantt/shape/Polygon.js +1 -1
- package/src/sap/gantt/shape/Polyline.js +1 -1
- package/src/sap/gantt/shape/Rectangle.js +1 -1
- package/src/sap/gantt/shape/ResizeShadowShape.js +1 -1
- package/src/sap/gantt/shape/SelectedShape.js +1 -1
- package/src/sap/gantt/shape/Shape.js +1 -1
- package/src/sap/gantt/shape/Text.js +1 -1
- package/src/sap/gantt/shape/cal/Calendar.js +1 -1
- package/src/sap/gantt/shape/ext/Chevron.js +1 -1
- package/src/sap/gantt/shape/ext/Cursor.js +1 -1
- package/src/sap/gantt/shape/ext/Diamond.js +1 -1
- package/src/sap/gantt/shape/ext/Iconfont.js +1 -1
- package/src/sap/gantt/shape/ext/Pentangle.js +1 -1
- package/src/sap/gantt/shape/ext/TextRepeat.js +1 -1
- package/src/sap/gantt/shape/ext/Triangle.js +1 -1
- package/src/sap/gantt/shape/ext/rls/Relationship.js +1 -1
- package/src/sap/gantt/shape/ext/rls/SelectedRelationship.js +2 -2
- package/src/sap/gantt/shape/ext/ubc/UbcBorderPath.js +1 -1
- package/src/sap/gantt/shape/ext/ubc/UbcOverCapacityZonePolygon.js +1 -1
- package/src/sap/gantt/shape/ext/ubc/UbcPolygon.js +1 -1
- package/src/sap/gantt/shape/ext/ubc/UbcShortageCapacityPolygon.js +1 -1
- package/src/sap/gantt/shape/ext/ubc/UbcTooltipRectangle.js +1 -1
- package/src/sap/gantt/shape/ext/ubc/UbcUnderCapacityZonePolygon.js +1 -1
- package/src/sap/gantt/shape/ext/ubc/UbcUsedPolygon.js +1 -1
- package/src/sap/gantt/shape/ext/ubc/UtilizationBarChart.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcBorderPath.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcClipPath.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcClipingPath.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcDimension.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcMiddleLine.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcOverCapacityZoneRectangle.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcOverClipRectangle.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcRectangle.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcTooltipRectangle.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UlcUnderClipRectangle.js +1 -1
- package/src/sap/gantt/shape/ext/ulc/UtilizationLineChart.js +1 -1
- package/src/sap/gantt/simple/AdhocDiamond.js +1 -1
- package/src/sap/gantt/simple/AdhocLine.js +1 -1
- package/src/sap/gantt/simple/AggregationUtils.js +11 -58
- package/src/sap/gantt/simple/BaseCalendar.js +1 -1
- package/src/sap/gantt/simple/BaseChevron.js +1 -1
- package/src/sap/gantt/simple/BaseConditionalShape.js +1 -1
- package/src/sap/gantt/simple/BaseCursor.js +7 -7
- package/src/sap/gantt/simple/BaseDeltaRectangle.js +7 -4
- package/src/sap/gantt/simple/BaseDiamond.js +1 -1
- package/src/sap/gantt/simple/BaseGroup.js +1 -1
- package/src/sap/gantt/simple/BaseImage.js +1 -1
- package/src/sap/gantt/simple/BaseLine.js +1 -1
- package/src/sap/gantt/simple/BasePath.js +1 -1
- package/src/sap/gantt/simple/BasePseudoShape.js +1 -1
- package/src/sap/gantt/simple/BaseRectangle.js +5 -2
- package/src/sap/gantt/simple/BaseShape.js +7 -5
- package/src/sap/gantt/simple/BaseText.js +1 -1
- package/src/sap/gantt/simple/BaseTriangle.js +7 -1
- package/src/sap/gantt/simple/ContainerToolbar.js +19 -4
- package/src/sap/gantt/simple/ContainerToolbarPlaceholder.js +1 -1
- package/src/sap/gantt/simple/CoordinateUtils.js +1 -1
- package/src/sap/gantt/simple/CustomVariantHandler.js +8 -2
- package/src/sap/gantt/simple/DeltaLine.js +1 -1
- package/src/sap/gantt/simple/ExpandModel.js +2 -4
- package/src/sap/gantt/simple/FindAndSelectUtils.js +6 -0
- package/src/sap/gantt/simple/FullScreenUtil.js +7 -1
- package/src/sap/gantt/simple/GanttAdaptationData.js +8 -2
- package/src/sap/gantt/simple/GanttChartContainer.js +8 -2
- package/src/sap/gantt/simple/GanttChartWithTable.js +63 -5
- package/src/sap/gantt/simple/GanttDragDropExtension.js +17 -5
- package/src/sap/gantt/simple/GanttExtension.js +1 -1
- package/src/sap/gantt/simple/GanttHeader.js +1 -1
- package/src/sap/gantt/simple/GanttPointerExtension.js +1 -1
- package/src/sap/gantt/simple/GanttPopoverExtension.js +2 -2
- package/src/sap/gantt/simple/GanttPrinting.js +313 -198
- package/src/sap/gantt/simple/GanttRowAction.js +1 -1
- package/src/sap/gantt/simple/GanttRowSettings.js +30 -1
- package/src/sap/gantt/simple/GanttScrollExtension.js +20 -5
- package/src/sap/gantt/simple/GanttSearchSidePanel.js +7 -1
- package/src/sap/gantt/simple/GanttUtils.js +86 -1
- package/src/sap/gantt/simple/GanttZoomExtension.js +4 -4
- package/src/sap/gantt/simple/InnerGanttChart.js +1 -1
- package/src/sap/gantt/simple/LegendContainer.js +1 -1
- package/src/sap/gantt/simple/LegendShapeGroup.js +1 -1
- package/src/sap/gantt/simple/MultiActivityGroup.js +1 -1
- package/src/sap/gantt/simple/MultiActivityRowSettings.js +1 -1
- package/src/sap/gantt/simple/PrintConfig.js +314 -0
- package/src/sap/gantt/simple/PrintDialogTemplate.js +38 -0
- package/src/sap/gantt/simple/PrintUtils.js +151 -0
- package/src/sap/gantt/simple/Relationship.js +1 -1
- package/src/sap/gantt/simple/ShapeScheme.js +1 -1
- package/src/sap/gantt/simple/StockChart.js +1 -1
- package/src/sap/gantt/simple/StockChartDimension.js +1 -1
- package/src/sap/gantt/simple/StockChartPeriod.js +1 -1
- package/src/sap/gantt/simple/UtilizationBarChart.js +1 -1
- package/src/sap/gantt/simple/UtilizationChart.js +4 -1
- package/src/sap/gantt/simple/UtilizationDimension.js +1 -1
- package/src/sap/gantt/simple/UtilizationLineChart.js +1 -1
- package/src/sap/gantt/simple/UtilizationPeriod.js +1 -1
- package/src/sap/gantt/simple/shapes/Shape.js +6 -6
- package/src/sap/gantt/simple/shapes/Task.js +1 -1
- package/src/sap/gantt/skipTime/DayInterval.js +63 -0
- package/src/sap/gantt/skipTime/DiscontinuousProvider.js +54 -0
- package/src/sap/gantt/skipTime/SkipInterval.js +76 -0
- package/src/sap/gantt/skipTime/SkipPattern.js +64 -0
- package/src/sap/gantt/skipTime/WeekPattern.js +118 -0
- package/src/sap/gantt/skipTime/WeeklyDiscontinuousProvider.js +84 -0
- package/src/sap/gantt/themes/sap_hcb/base_Gantt.less +899 -0
- package/src/sap/gantt/themes/sap_hcb/base_GanttPrinting.less +101 -0
- package/src/sap/gantt/themes/sap_hcb/base_GanttSyncedControl.less +96 -0
- package/src/sap/gantt/themes/sap_hcb/library.source.less +15 -1
- package/src/sap/gantt/thirdparty/d3fc-discontinuous-scale.js +1129 -0
- package/src/sap/gantt/thirdparty/d3fc-rebind.js +103 -0
- package/src/sap/gantt/thirdparty/licenses/d3fc-MIT-LICENSE.txt +21 -0
- package/src/sap/gantt/utils/GanttChartConfigurationUtils.js +6 -0
- package/src/sap/gantt/utils/GanttCustomisationUtils.js +7 -1
- package/src/sap/gantt/utils/GanttFlexibilityUtils.js +7 -1
- package/src/sap/gantt/polyfills/time-utils/day.js +0 -7
- package/src/sap/gantt/polyfills/time-utils/days.js +0 -7
- package/src/sap/gantt/polyfills/time-utils/monday.js +0 -7
- package/src/sap/gantt/polyfills/time-utils/saturday.js +0 -7
- package/src/sap/gantt/polyfills/time-utils/weeks.js +0 -7
|
@@ -0,0 +1,1129 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* d3fc-discontinuous-scale 4.1.0 <https://www.npmjs.com/package/@d3fc/d3fc-discontinuous-scale>
|
|
3
|
+
* Copyright (c) 2015-2019 Scott Logic Ltd.
|
|
4
|
+
* Released under MIT License
|
|
5
|
+
*/
|
|
6
|
+
(function (global, factory) {
|
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-scale'), require('@d3fc/d3fc-rebind'), require('d3-time')) :
|
|
8
|
+
typeof define === 'function' && define.amd ? define(['exports', 'd3-scale', '@d3fc/d3fc-rebind', 'd3-time'], factory) :
|
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.fc = global.fc || {}, global.d3, global.fc,
|
|
10
|
+
/* ##### BEGIN: MODIFIED BY SAP */
|
|
11
|
+
/* Original lines */
|
|
12
|
+
/* global.d3 */
|
|
13
|
+
/* Modified line */
|
|
14
|
+
sap.ui.require("sap/gantt/polyfills/lib").time)
|
|
15
|
+
/* ##### END: MODIFIED BY SAP */
|
|
16
|
+
);
|
|
17
|
+
}(this, (function (exports, d3Scale, d3fcRebind, d3Time) { 'use strict';
|
|
18
|
+
|
|
19
|
+
function identity () {
|
|
20
|
+
var identity = {};
|
|
21
|
+
|
|
22
|
+
identity.distance = function (start, end) {
|
|
23
|
+
return end - start;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
identity.offset = function (start, offset) {
|
|
27
|
+
return start instanceof Date ? new Date(start.getTime() + offset) : start + offset;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
identity.clampUp = function (d) {
|
|
31
|
+
return d;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
identity.clampDown = function (d) {
|
|
35
|
+
return d;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
identity.copy = function () {
|
|
39
|
+
return identity;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return identity;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function tickFilter(ticks, discontinuityProvider) {
|
|
46
|
+
// ##### BEGIN: MODIFIED BY SAP
|
|
47
|
+
// Original lines
|
|
48
|
+
//
|
|
49
|
+
// Modified line
|
|
50
|
+
if ("tickFilter" in discontinuityProvider) {
|
|
51
|
+
return discontinuityProvider.tickFilter(ticks);
|
|
52
|
+
} // use tick filter provided by the discontinuity provider
|
|
53
|
+
// ##### END: MODIFIED BY SAP
|
|
54
|
+
|
|
55
|
+
var discontinuousTicks = ticks.map(discontinuityProvider.clampUp);
|
|
56
|
+
|
|
57
|
+
if (discontinuousTicks.length !== new Set(discontinuousTicks.map(function (d) {
|
|
58
|
+
return d === null || d === void 0 ? void 0 : d.valueOf();
|
|
59
|
+
})).size) {
|
|
60
|
+
console.warn('There are multiple ticks that fall within a discontinuity, which has led to them being rendered on top of each other. Consider using scale.ticks to explicitly specify the ticks for the scale.');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return discontinuousTicks;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function discontinuous(adaptedScale) {
|
|
67
|
+
var _this = this;
|
|
68
|
+
|
|
69
|
+
if (!arguments.length) {
|
|
70
|
+
adaptedScale = d3Scale.scaleIdentity();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var discontinuityProvider = identity();
|
|
74
|
+
|
|
75
|
+
var scale = function scale(value) {
|
|
76
|
+
var domain = adaptedScale.domain();
|
|
77
|
+
var range = adaptedScale.range(); // The discontinuityProvider is responsible for determine the distance between two points
|
|
78
|
+
// along a scale that has discontinuities (i.e. sections that have been removed).
|
|
79
|
+
// the scale for the given point 'x' is calculated as the ratio of the discontinuous distance
|
|
80
|
+
// over the domain of this axis, versus the discontinuous distance to 'x'
|
|
81
|
+
|
|
82
|
+
var totalDomainDistance = discontinuityProvider.distance(domain[0], domain[1]);
|
|
83
|
+
var distanceToX = discontinuityProvider.distance(domain[0], value);
|
|
84
|
+
var ratioToX = distanceToX / totalDomainDistance;
|
|
85
|
+
var scaledByRange = ratioToX * (range[1] - range[0]) + range[0];
|
|
86
|
+
return scaledByRange;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
scale.invert = function (x) {
|
|
90
|
+
var domain = adaptedScale.domain();
|
|
91
|
+
var range = adaptedScale.range();
|
|
92
|
+
var ratioToX = (x - range[0]) / (range[1] - range[0]);
|
|
93
|
+
var totalDomainDistance = discontinuityProvider.distance(domain[0], domain[1]);
|
|
94
|
+
var distanceToX = ratioToX * totalDomainDistance;
|
|
95
|
+
return discontinuityProvider.offset(domain[0], distanceToX);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
scale.domain = function () {
|
|
99
|
+
if (!arguments.length) {
|
|
100
|
+
return adaptedScale.domain();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var newDomain = arguments.length <= 0 ? undefined : arguments[0];
|
|
104
|
+
|
|
105
|
+
// clamp the upper and lower domain values to ensure they
|
|
106
|
+
// do not fall within a discontinuity
|
|
107
|
+
var domainLower = discontinuityProvider.clampUp(newDomain[0]);
|
|
108
|
+
var domainUpper = discontinuityProvider.clampDown(newDomain[1]);
|
|
109
|
+
adaptedScale.domain([domainLower, domainUpper]);
|
|
110
|
+
return scale;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
scale.nice = function () {
|
|
114
|
+
adaptedScale.nice();
|
|
115
|
+
var domain = adaptedScale.domain();
|
|
116
|
+
var domainLower = discontinuityProvider.clampUp(domain[0]);
|
|
117
|
+
var domainUpper = discontinuityProvider.clampDown(domain[1]);
|
|
118
|
+
adaptedScale.domain([domainLower, domainUpper]);
|
|
119
|
+
return scale;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
scale.ticks = function () {
|
|
123
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
124
|
+
args[_key] = arguments[_key];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
var ticks = adaptedScale.ticks.apply(_this, args);
|
|
128
|
+
return tickFilter(ticks, discontinuityProvider);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
scale.copy = function () {
|
|
132
|
+
return discontinuous(adaptedScale.copy()).discontinuityProvider(discontinuityProvider.copy());
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
scale.discontinuityProvider = function () {
|
|
136
|
+
if (!arguments.length) {
|
|
137
|
+
return discontinuityProvider;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
discontinuityProvider = arguments.length <= 0 ? undefined : arguments[0];
|
|
141
|
+
return scale;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
d3fcRebind.rebindAll(scale, adaptedScale, d3fcRebind.include('range', 'rangeRound', 'interpolate', 'clamp', 'tickFormat'));
|
|
145
|
+
return scale;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
var base = function base(dayAccessor, intervalDay, intervalSaturday, intervalMonday) {
|
|
149
|
+
// the indices returned by dayAccessor(date)
|
|
150
|
+
var day = {
|
|
151
|
+
sunday: 0,
|
|
152
|
+
monday: 1,
|
|
153
|
+
saturday: 6
|
|
154
|
+
};
|
|
155
|
+
var millisPerDay = 24 * 3600 * 1000;
|
|
156
|
+
var millisPerWorkWeek = millisPerDay * 5;
|
|
157
|
+
var millisPerWeek = millisPerDay * 7;
|
|
158
|
+
var skipWeekends = {};
|
|
159
|
+
|
|
160
|
+
var isWeekend = function isWeekend(date) {
|
|
161
|
+
return dayAccessor(date) === 0 || dayAccessor(date) === 6;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
skipWeekends.clampDown = function (date) {
|
|
165
|
+
if (date && isWeekend(date)) {
|
|
166
|
+
// round the date up to midnight
|
|
167
|
+
var newDate = intervalDay.ceil(date); // then subtract the required number of days
|
|
168
|
+
|
|
169
|
+
if (dayAccessor(newDate) === day.sunday) {
|
|
170
|
+
return intervalDay.offset(newDate, -1);
|
|
171
|
+
} else if (dayAccessor(newDate) === day.monday) {
|
|
172
|
+
return intervalDay.offset(newDate, -2);
|
|
173
|
+
} else {
|
|
174
|
+
return newDate;
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
return date;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
skipWeekends.clampUp = function (date) {
|
|
182
|
+
if (date && isWeekend(date)) {
|
|
183
|
+
// round the date down to midnight
|
|
184
|
+
var newDate = intervalDay.floor(date); // then add the required number of days
|
|
185
|
+
|
|
186
|
+
if (dayAccessor(newDate) === day.saturday) {
|
|
187
|
+
return intervalDay.offset(newDate, 2);
|
|
188
|
+
} else if (dayAccessor(newDate) === day.sunday) {
|
|
189
|
+
return intervalDay.offset(newDate, 1);
|
|
190
|
+
} else {
|
|
191
|
+
return newDate;
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
return date;
|
|
195
|
+
}
|
|
196
|
+
}; // returns the number of included milliseconds (i.e. those which do not fall)
|
|
197
|
+
// within discontinuities, along this scale
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
skipWeekends.distance = function (startDate, endDate) {
|
|
201
|
+
startDate = skipWeekends.clampUp(startDate);
|
|
202
|
+
endDate = skipWeekends.clampDown(endDate); // move the start date to the end of week boundary
|
|
203
|
+
|
|
204
|
+
var offsetStart = intervalSaturday.ceil(startDate);
|
|
205
|
+
|
|
206
|
+
if (endDate < offsetStart) {
|
|
207
|
+
return endDate.getTime() - startDate.getTime();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
var msAdded = offsetStart.getTime() - startDate.getTime(); // move the end date to the end of week boundary
|
|
211
|
+
|
|
212
|
+
var offsetEnd = intervalSaturday.ceil(endDate);
|
|
213
|
+
var msRemoved = offsetEnd.getTime() - endDate.getTime(); // determine how many weeks there are between these two dates
|
|
214
|
+
// round to account for DST transitions
|
|
215
|
+
|
|
216
|
+
var weeks = Math.round((offsetEnd.getTime() - offsetStart.getTime()) / millisPerWeek);
|
|
217
|
+
return weeks * millisPerWorkWeek + msAdded - msRemoved;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
skipWeekends.offset = function (startDate, ms) {
|
|
221
|
+
var date = isWeekend(startDate) ? skipWeekends.clampUp(startDate) : startDate;
|
|
222
|
+
|
|
223
|
+
if (ms === 0) {
|
|
224
|
+
return date;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
var isNegativeOffset = ms < 0;
|
|
228
|
+
var isPositiveOffset = ms > 0;
|
|
229
|
+
var remainingms = ms; // move to the end of week boundary for a postive offset or to the start of a week for a negative offset
|
|
230
|
+
|
|
231
|
+
var weekBoundary = isNegativeOffset ? intervalMonday.floor(date) : intervalSaturday.ceil(date);
|
|
232
|
+
remainingms -= weekBoundary.getTime() - date.getTime(); // if the distance to the boundary is greater than the number of ms
|
|
233
|
+
// simply add the ms to the current date
|
|
234
|
+
|
|
235
|
+
if (isNegativeOffset && remainingms > 0 || isPositiveOffset && remainingms < 0) {
|
|
236
|
+
return new Date(date.getTime() + ms);
|
|
237
|
+
} // skip the weekend for a positive offset
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
date = isNegativeOffset ? weekBoundary : intervalDay.offset(weekBoundary, 2); // add all of the complete weeks to the date
|
|
241
|
+
|
|
242
|
+
var completeWeeks = Math.floor(remainingms / millisPerWorkWeek);
|
|
243
|
+
date = intervalDay.offset(date, completeWeeks * 7);
|
|
244
|
+
remainingms -= completeWeeks * millisPerWorkWeek; // add the remaining time
|
|
245
|
+
|
|
246
|
+
date = new Date(date.getTime() + remainingms);
|
|
247
|
+
return date;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
skipWeekends.copy = function () {
|
|
251
|
+
return skipWeekends;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return skipWeekends;
|
|
255
|
+
};
|
|
256
|
+
var skipWeekends = (function () {
|
|
257
|
+
return base(function (date) {
|
|
258
|
+
return date.getDay();
|
|
259
|
+
}, d3Time.timeDay, d3Time.timeSaturday, d3Time.timeMonday);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
var skipUtcWeekends = (function () {
|
|
263
|
+
return base(function (date) {
|
|
264
|
+
return date.getUTCDay();
|
|
265
|
+
}, d3Time.utcDay, d3Time.utcSaturday, d3Time.utcMonday);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
function _typeof(obj) {
|
|
269
|
+
"@babel/helpers - typeof";
|
|
270
|
+
|
|
271
|
+
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
272
|
+
_typeof = function (obj) {
|
|
273
|
+
return typeof obj;
|
|
274
|
+
};
|
|
275
|
+
} else {
|
|
276
|
+
_typeof = function (obj) {
|
|
277
|
+
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return _typeof(obj);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function _slicedToArray(arr, i) {
|
|
285
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function _arrayWithHoles(arr) {
|
|
289
|
+
if (Array.isArray(arr)) return arr;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function _iterableToArrayLimit(arr, i) {
|
|
293
|
+
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
|
|
294
|
+
var _arr = [];
|
|
295
|
+
var _n = true;
|
|
296
|
+
var _d = false;
|
|
297
|
+
var _e = undefined;
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
301
|
+
_arr.push(_s.value);
|
|
302
|
+
|
|
303
|
+
if (i && _arr.length === i) break;
|
|
304
|
+
}
|
|
305
|
+
} catch (err) {
|
|
306
|
+
_d = true;
|
|
307
|
+
_e = err;
|
|
308
|
+
} finally {
|
|
309
|
+
try {
|
|
310
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
311
|
+
} finally {
|
|
312
|
+
if (_d) throw _e;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return _arr;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
320
|
+
if (!o) return;
|
|
321
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
322
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
323
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
324
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
325
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function _arrayLikeToArray(arr, len) {
|
|
329
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
330
|
+
|
|
331
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
332
|
+
|
|
333
|
+
return arr2;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function _nonIterableRest() {
|
|
337
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
341
|
+
var it;
|
|
342
|
+
|
|
343
|
+
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
|
344
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
345
|
+
if (it) o = it;
|
|
346
|
+
var i = 0;
|
|
347
|
+
|
|
348
|
+
var F = function () {};
|
|
349
|
+
|
|
350
|
+
return {
|
|
351
|
+
s: F,
|
|
352
|
+
n: function () {
|
|
353
|
+
if (i >= o.length) return {
|
|
354
|
+
done: true
|
|
355
|
+
};
|
|
356
|
+
return {
|
|
357
|
+
done: false,
|
|
358
|
+
value: o[i++]
|
|
359
|
+
};
|
|
360
|
+
},
|
|
361
|
+
e: function (e) {
|
|
362
|
+
throw e;
|
|
363
|
+
},
|
|
364
|
+
f: F
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
var normalCompletion = true,
|
|
372
|
+
didErr = false,
|
|
373
|
+
err;
|
|
374
|
+
return {
|
|
375
|
+
s: function () {
|
|
376
|
+
it = o[Symbol.iterator]();
|
|
377
|
+
},
|
|
378
|
+
n: function () {
|
|
379
|
+
var step = it.next();
|
|
380
|
+
normalCompletion = step.done;
|
|
381
|
+
return step;
|
|
382
|
+
},
|
|
383
|
+
e: function (e) {
|
|
384
|
+
didErr = true;
|
|
385
|
+
err = e;
|
|
386
|
+
},
|
|
387
|
+
f: function () {
|
|
388
|
+
try {
|
|
389
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
390
|
+
} finally {
|
|
391
|
+
if (didErr) throw err;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
var provider = function provider() {
|
|
398
|
+
for (var _len = arguments.length, ranges = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
399
|
+
ranges[_key] = arguments[_key];
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
var inRange = function inRange(number, range) {
|
|
403
|
+
return number > range[0] && number < range[1];
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
var surroundsRange = function surroundsRange(inner, outer) {
|
|
407
|
+
return inner[0] >= outer[0] && inner[1] <= outer[1];
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
var identity = {};
|
|
411
|
+
|
|
412
|
+
identity.distance = function (start, end) {
|
|
413
|
+
start = identity.clampUp(start);
|
|
414
|
+
end = identity.clampDown(end);
|
|
415
|
+
var surroundedRanges = ranges.filter(function (r) {
|
|
416
|
+
return surroundsRange(r, [start, end]);
|
|
417
|
+
});
|
|
418
|
+
var rangeSizes = surroundedRanges.map(function (r) {
|
|
419
|
+
return r[1] - r[0];
|
|
420
|
+
});
|
|
421
|
+
return end - start - rangeSizes.reduce(function (total, current) {
|
|
422
|
+
return total + current;
|
|
423
|
+
}, 0);
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
var add = function add(value, offset) {
|
|
427
|
+
return value instanceof Date ? new Date(value.getTime() + offset) : value + offset;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
identity.offset = function (location, offset) {
|
|
431
|
+
if (offset > 0) {
|
|
432
|
+
var _ret = function () {
|
|
433
|
+
var currentLocation = identity.clampUp(location);
|
|
434
|
+
var offsetRemaining = offset;
|
|
435
|
+
|
|
436
|
+
while (offsetRemaining > 0) {
|
|
437
|
+
var futureRanges = ranges.filter(function (r) {
|
|
438
|
+
return r[0] > currentLocation;
|
|
439
|
+
}).sort(function (a, b) {
|
|
440
|
+
return a[0] - b[0];
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
if (futureRanges.length) {
|
|
444
|
+
var nextRange = futureRanges[0];
|
|
445
|
+
var delta = nextRange[0] - currentLocation;
|
|
446
|
+
|
|
447
|
+
if (delta > offsetRemaining) {
|
|
448
|
+
currentLocation = add(currentLocation, offsetRemaining);
|
|
449
|
+
offsetRemaining = 0;
|
|
450
|
+
} else {
|
|
451
|
+
currentLocation = nextRange[1];
|
|
452
|
+
offsetRemaining -= delta;
|
|
453
|
+
}
|
|
454
|
+
} else {
|
|
455
|
+
currentLocation = add(currentLocation, offsetRemaining);
|
|
456
|
+
offsetRemaining = 0;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
v: currentLocation
|
|
462
|
+
};
|
|
463
|
+
}();
|
|
464
|
+
|
|
465
|
+
if (_typeof(_ret) === "object") return _ret.v;
|
|
466
|
+
} else {
|
|
467
|
+
var _ret2 = function () {
|
|
468
|
+
var currentLocation = identity.clampDown(location);
|
|
469
|
+
var offsetRemaining = offset;
|
|
470
|
+
|
|
471
|
+
while (offsetRemaining < 0) {
|
|
472
|
+
var futureRanges = ranges.filter(function (r) {
|
|
473
|
+
return r[1] < currentLocation;
|
|
474
|
+
}).sort(function (a, b) {
|
|
475
|
+
return b[0] - a[0];
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
if (futureRanges.length) {
|
|
479
|
+
var nextRange = futureRanges[0];
|
|
480
|
+
var delta = nextRange[1] - currentLocation;
|
|
481
|
+
|
|
482
|
+
if (delta < offsetRemaining) {
|
|
483
|
+
currentLocation = add(currentLocation, offsetRemaining);
|
|
484
|
+
offsetRemaining = 0;
|
|
485
|
+
} else {
|
|
486
|
+
currentLocation = nextRange[0];
|
|
487
|
+
offsetRemaining -= delta;
|
|
488
|
+
}
|
|
489
|
+
} else {
|
|
490
|
+
currentLocation = add(currentLocation, offsetRemaining);
|
|
491
|
+
offsetRemaining = 0;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return {
|
|
496
|
+
v: currentLocation
|
|
497
|
+
};
|
|
498
|
+
}();
|
|
499
|
+
|
|
500
|
+
if (_typeof(_ret2) === "object") return _ret2.v;
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
identity.clampUp = function (d) {
|
|
505
|
+
return ranges.reduce(function (value, range) {
|
|
506
|
+
return inRange(value, range) ? range[1] : value;
|
|
507
|
+
}, d);
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
identity.clampDown = function (d) {
|
|
511
|
+
return ranges.reduce(function (value, range) {
|
|
512
|
+
return inRange(value, range) ? range[0] : value;
|
|
513
|
+
}, d);
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
identity.copy = function () {
|
|
517
|
+
return identity;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
return identity;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
var millisPerDay = 24 * 3600 * 1000;
|
|
524
|
+
var dayBoundary = "00:00:00.000";
|
|
525
|
+
var SOD = 'SOD';
|
|
526
|
+
var EOD = 'EOD';
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Attempts to parse and format a time string into a fixed lenght string 'hh:mm:ss.fff'
|
|
530
|
+
* @param {string} timeString - string representation of time 'hh:mm:ss.fff' e.g. '09:30' or '00:00:00.000'
|
|
531
|
+
* @returns {int[]} array of parsed time components [hh, mm, ss, ms] or throws.
|
|
532
|
+
*/
|
|
533
|
+
|
|
534
|
+
function standardiseTimeString(timeString) {
|
|
535
|
+
if (arguments.length !== 1 || typeof timeString !== 'string') {
|
|
536
|
+
throw 'Expected single argument of type string';
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
var isPositiveIntegerUpTo = function isPositiveIntegerUpTo(toCheck, upperBound) {
|
|
540
|
+
if (!Number.isInteger(toCheck)) return false;
|
|
541
|
+
return toCheck >= 0 && toCheck <= upperBound;
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
var result = [0, 0, 0, 0];
|
|
545
|
+
var time_components = timeString.split(":");
|
|
546
|
+
|
|
547
|
+
if (time_components.length < 2 || time_components.length > 3) {
|
|
548
|
+
throw 'Expected an argument wiht 2 or 3 colon delimited parts.';
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
result[0] = isPositiveIntegerUpTo(parseInt(time_components[0], 10), 23) ? parseInt(time_components[0], 10) : function () {
|
|
552
|
+
throw "'Hours' component must be an int between 0 and 23, but was '".concat(time_components[0], "'");
|
|
553
|
+
}();
|
|
554
|
+
result[1] = isPositiveIntegerUpTo(parseInt(time_components[1], 10), 59) ? parseInt(time_components[1], 10) : function () {
|
|
555
|
+
throw "'Minutes' component must be an int between 0 and 59, but was '".concat(time_components[1], "'");
|
|
556
|
+
}();
|
|
557
|
+
|
|
558
|
+
if (time_components.length === 3) {
|
|
559
|
+
var ms_components = time_components[2].split(".").map(function (x) {
|
|
560
|
+
return parseInt(x, 10);
|
|
561
|
+
});
|
|
562
|
+
result[2] = isPositiveIntegerUpTo(ms_components[0], 59) ? ms_components[0] : function () {
|
|
563
|
+
throw "'Seconds' component must be an int between 0 and 59, but was '".concat(ms_components[0], "'");
|
|
564
|
+
}();
|
|
565
|
+
|
|
566
|
+
if (ms_components.length === 2) {
|
|
567
|
+
result[3] = isPositiveIntegerUpTo(ms_components[1], 999) ? ms_components[1] : function () {
|
|
568
|
+
throw "'Miliseconds' component must be an int between 0 and 999, but was '".concat(ms_components[1], "'");
|
|
569
|
+
}();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
return "".concat(result[0].toString(10).padStart(2, '0'), ":").concat(result[1].toString(10).padStart(2, '0'), ":").concat(result[2].toString(10).padStart(2, '0'), ".").concat(result[3].toString(10).padStart(3, '0'));
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* @typedef { Object } nonTradingTimeRange
|
|
577
|
+
* @property { string } startTime - Start time string with fixed format 'hh:mm:ss.fff'
|
|
578
|
+
* @property { string } endTime - End time string with fixed format 'hh:mm:ss.fff'
|
|
579
|
+
* @property { int } lenghtInMs - Absolute length in MS i.e. only valid on non-Daylight saving boundaries
|
|
580
|
+
*/
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Represents a single continous Non-Trading time interval within a single day. You must denote day boundries as:
|
|
584
|
+
* SOD - start of day
|
|
585
|
+
* EOD - end of day
|
|
586
|
+
* @constructor
|
|
587
|
+
* @param { string[] } timeRangeTuple - Time range as a tuple of time strings e.g. ["07:45", "08:30"), ["SOD", "08:30:20") or ["19:00:45.500", "EOD").
|
|
588
|
+
* @param { import('./dateTimeUtility').DateTimeUtility } dateTimeUtility
|
|
589
|
+
* @returns { nonTradingTimeRange }
|
|
590
|
+
*/
|
|
591
|
+
|
|
592
|
+
function nonTradingTimeRange(timeRangeTuple, dateTimeUtility) {
|
|
593
|
+
if (arguments.length != 2 || !Array.isArray(timeRangeTuple) || timeRangeTuple.length !== 2 || typeof timeRangeTuple[0] !== 'string' || typeof timeRangeTuple[1] !== 'string') {
|
|
594
|
+
throw "Expected argument is a single string[] of length 2.";
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (timeRangeTuple[0] === SOD) {
|
|
598
|
+
timeRangeTuple[0] = dayBoundary;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if (timeRangeTuple[1] === EOD) {
|
|
602
|
+
timeRangeTuple[1] = dayBoundary;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
var startTime = standardiseTimeString(timeRangeTuple[0]);
|
|
606
|
+
var endTime = standardiseTimeString(timeRangeTuple[1]);
|
|
607
|
+
|
|
608
|
+
if (endTime !== dayBoundary && startTime > endTime) {
|
|
609
|
+
throw "Time range start time '".concat(startTime, "' must be before end time '").concat(endTime, "' or both must equal ").concat(dayBoundary);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
var lenghtInMs = dateTimeUtility.setTime(new Date(endTime === dayBoundary ? millisPerDay : 0), endTime) - dateTimeUtility.setTime(new Date(0), startTime);
|
|
613
|
+
var instance = {
|
|
614
|
+
startTime: startTime,
|
|
615
|
+
endTime: endTime,
|
|
616
|
+
lenghtInMs: lenghtInMs
|
|
617
|
+
};
|
|
618
|
+
/**
|
|
619
|
+
* Returns if given date's time portion is within this discontinuity time range instance
|
|
620
|
+
* @param { Date } date - date
|
|
621
|
+
* @returns { boolean }
|
|
622
|
+
*/
|
|
623
|
+
|
|
624
|
+
instance.isInRange = function (date) {
|
|
625
|
+
var time = dateTimeUtility.getTimeString(date);
|
|
626
|
+
|
|
627
|
+
if (instance.startTime <= time && (instance.endTime === dayBoundary || instance.endTime > time)) {
|
|
628
|
+
return true;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
return false;
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
return instance;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Represents a Trading day
|
|
639
|
+
* @param { string[][] } rawDiscontinuityTimeRanges - Array of time range tuples e.g. [["07:45", "08:30"), ["19:00:45.500", "EOD")]
|
|
640
|
+
* @param { import('./dateTimeUtility').DateTimeUtility } dateTimeUtility
|
|
641
|
+
*/
|
|
642
|
+
|
|
643
|
+
var tradingDay = function tradingDay(rawDiscontinuityTimeRanges, dateTimeUtility) {
|
|
644
|
+
var nonTradingTimeRanges = rawDiscontinuityTimeRanges.map(function (rawRange) {
|
|
645
|
+
return nonTradingTimeRange(rawRange, dateTimeUtility);
|
|
646
|
+
}).sort(function (a, b) {
|
|
647
|
+
return a.startTime < b.startTime ? -1 : a.startTime > b.startTime ? 1 : 0;
|
|
648
|
+
});
|
|
649
|
+
var totalTradingTimeInMiliseconds = millisPerDay - nonTradingTimeRanges.reduce(function (total, range) {
|
|
650
|
+
return total + range.lenghtInMs;
|
|
651
|
+
}, 0);
|
|
652
|
+
|
|
653
|
+
var totalTradingMillisecondsBetween = function totalTradingMillisecondsBetween(intervalStart, intervalEnd) {
|
|
654
|
+
if (intervalStart.getTime() === intervalEnd.getTime()) {
|
|
655
|
+
return 0;
|
|
656
|
+
} // ensure arguments are on the same day or intervalEnd is the next day boundary
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
if (dateTimeUtility.dayInterval(intervalStart).getTime() !== dateTimeUtility.dayInterval(intervalEnd).getTime() && dateTimeUtility.getStartOfNextDay(intervalStart).getTime() !== intervalEnd.getTime()) {
|
|
660
|
+
throw "tradingDay.totalTradingMillisecondsBetween arguments must be on the same day or intervalEnd must be the start of the next day instead: intervalStart: '".concat(intervalStart, "'; intervalEnd: '").concat(intervalEnd, "'");
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
var total = 0;
|
|
664
|
+
var relevantDiscontinuityRanges = nonTradingTimeRanges.filter(function (range) {
|
|
665
|
+
return range.endTime === dayBoundary || dateTimeUtility.setTime(intervalStart, range.endTime) >= intervalStart;
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
var _iterator = _createForOfIteratorHelper(relevantDiscontinuityRanges),
|
|
669
|
+
_step;
|
|
670
|
+
|
|
671
|
+
try {
|
|
672
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
673
|
+
var nonTradingRange = _step.value;
|
|
674
|
+
var nonTradingStart = dateTimeUtility.setTime(intervalStart, nonTradingRange.startTime);
|
|
675
|
+
var nonTradingEnd = nonTradingRange.endTime === dayBoundary ? dateTimeUtility.getStartOfNextDay(intervalStart) : dateTimeUtility.setTime(intervalStart, nonTradingRange.endTime); // both intervalStart and intervalEnd are before the start of this non-trading range
|
|
676
|
+
|
|
677
|
+
if (intervalStart < nonTradingStart && intervalEnd < nonTradingStart) {
|
|
678
|
+
return total + dateTimeUtility.msInterval.count(intervalStart, intervalEnd);
|
|
679
|
+
} // intervalStart is before the start of this non-trading time range
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
if (intervalStart < nonTradingStart) {
|
|
683
|
+
total += dateTimeUtility.msInterval.count(intervalStart, nonTradingStart);
|
|
684
|
+
} // interval ends within non-trading range
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
if (intervalEnd < nonTradingEnd) {
|
|
688
|
+
return total;
|
|
689
|
+
} // set interval start to the end of non-trading range
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
intervalStart = nonTradingEnd;
|
|
693
|
+
} // add any interval time still left after iterating through all non-trading ranges
|
|
694
|
+
|
|
695
|
+
} catch (err) {
|
|
696
|
+
_iterator.e(err);
|
|
697
|
+
} finally {
|
|
698
|
+
_iterator.f();
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
return total + dateTimeUtility.msInterval.count(intervalStart, intervalEnd);
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
var offset = function offset(date, ms) {
|
|
705
|
+
if (ms === 0) {
|
|
706
|
+
return [date, ms];
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
var offsetDate = dateTimeUtility.msInterval.offset(date, ms);
|
|
710
|
+
var nonTradingRanges = ms > 0 ? nonTradingTimeRanges.filter(function (range) {
|
|
711
|
+
return dateTimeUtility.setTime(date, range.startTime) >= date;
|
|
712
|
+
}) : nonTradingTimeRanges.filter(function (range) {
|
|
713
|
+
return dateTimeUtility.setTime(date, range.startTime) < date;
|
|
714
|
+
}).reverse();
|
|
715
|
+
|
|
716
|
+
if (nonTradingRanges.length === 0) {
|
|
717
|
+
return [dateTimeUtility.msInterval.offset(date, ms), 0];
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
if (ms > 0) {
|
|
721
|
+
var _iterator2 = _createForOfIteratorHelper(nonTradingRanges),
|
|
722
|
+
_step2;
|
|
723
|
+
|
|
724
|
+
try {
|
|
725
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
726
|
+
var nonTradingRange = _step2.value;
|
|
727
|
+
var rangeStart = dateTimeUtility.setTime(date, nonTradingRange.startTime);
|
|
728
|
+
|
|
729
|
+
if (rangeStart <= offsetDate) {
|
|
730
|
+
// offsetDate is within non-trading range
|
|
731
|
+
ms -= dateTimeUtility.msInterval.count(date, rangeStart);
|
|
732
|
+
date = nonTradingRange.endTime === dayBoundary ? dateTimeUtility.getStartOfNextDay(date) : dateTimeUtility.setTime(date, nonTradingRange.endTime);
|
|
733
|
+
offsetDate = dateTimeUtility.msInterval.offset(date, ms);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
} catch (err) {
|
|
737
|
+
_iterator2.e(err);
|
|
738
|
+
} finally {
|
|
739
|
+
_iterator2.f();
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
ms -= dateTimeUtility.msInterval.count(date, offsetDate);
|
|
743
|
+
} else {
|
|
744
|
+
var _iterator3 = _createForOfIteratorHelper(nonTradingRanges),
|
|
745
|
+
_step3;
|
|
746
|
+
|
|
747
|
+
try {
|
|
748
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
749
|
+
var _nonTradingRange = _step3.value;
|
|
750
|
+
var endTime = _nonTradingRange.endTime === dayBoundary ? dateTimeUtility.getStartOfNextDay(date) : dateTimeUtility.setTime(date, _nonTradingRange.endTime);
|
|
751
|
+
|
|
752
|
+
if (offsetDate < endTime) {
|
|
753
|
+
// offsetDate is within non-trading range
|
|
754
|
+
ms += dateTimeUtility.msInterval.count(endTime, date) + 1;
|
|
755
|
+
date = dateTimeUtility.msInterval.offset(dateTimeUtility.setTime(date, _nonTradingRange.startTime), -1);
|
|
756
|
+
offsetDate = dateTimeUtility.msInterval.offset(date, ms);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
} catch (err) {
|
|
760
|
+
_iterator3.e(err);
|
|
761
|
+
} finally {
|
|
762
|
+
_iterator3.f();
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
ms += dateTimeUtility.msInterval.count(offsetDate, date);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
if (ms !== 0) {
|
|
769
|
+
throw 'tradingDay.offset was called with an offset that spans more than a day';
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
return [offsetDate, ms];
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
return {
|
|
776
|
+
totalTradingTimeInMiliseconds: totalTradingTimeInMiliseconds,
|
|
777
|
+
nonTradingTimeRanges: nonTradingTimeRanges,
|
|
778
|
+
totalTradingMillisecondsBetween: totalTradingMillisecondsBetween,
|
|
779
|
+
offset: offset
|
|
780
|
+
};
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Object that helps with working with time strings and dates
|
|
785
|
+
* @typedef { Object } DateTimeUtility
|
|
786
|
+
* @property { function(Date): string } getTimeString - get's the time string for date as 'hh:mm:ss.fff'
|
|
787
|
+
* @property { function(Date , string, number): Date } setTime - set the time for date as
|
|
788
|
+
* @property { function(Date): Date } getStartOfNextDay - returns the start of the next day i.e. 00:00:00.000
|
|
789
|
+
* @property { function(Date): Date } getEndOfPreviousDay - returns the 'End' of the previous day i.e. one ms before midnight
|
|
790
|
+
*/
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
*
|
|
794
|
+
* @param {function(Date, number, number, number, number): Date } setTimeForDate - sets a time on a Date object given hh, mm, ss & ms time compononets
|
|
795
|
+
* @param {function(Date): number } getDay
|
|
796
|
+
* @param {function(Date): number[] } getTimeComponentArray
|
|
797
|
+
* @param {function} dayInterval - d3-time timeDay or utcDay
|
|
798
|
+
* @param {function} msInterval - d3-time timeMillisecond or utcMillisecond
|
|
799
|
+
* @returns {DateTimeUtility}
|
|
800
|
+
*/
|
|
801
|
+
var dateTimeUtility = function dateTimeUtility(setTimeForDate, getDay, getTimeComponentArray, dayInterval, msInterval) {
|
|
802
|
+
var utility = {};
|
|
803
|
+
|
|
804
|
+
utility.getTimeComponentArrayFromString = function (timeString) {
|
|
805
|
+
return [timeString.slice(0, 2), timeString.slice(3, 5), timeString.slice(6, 8), timeString.slice(9, 12)];
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* Returns the local time part of a given Date instance as 'hh:mm:ss.fff'
|
|
809
|
+
* @param {Date} date - Data instance
|
|
810
|
+
* @returns {string} time string.
|
|
811
|
+
*/
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
utility.getTimeString = function (date) {
|
|
815
|
+
var _getTimeComponentArra = getTimeComponentArray(date).map(function (x) {
|
|
816
|
+
return x.toString(10).padStart(2, '0');
|
|
817
|
+
}),
|
|
818
|
+
_getTimeComponentArra2 = _slicedToArray(_getTimeComponentArra, 4),
|
|
819
|
+
hh = _getTimeComponentArra2[0],
|
|
820
|
+
mm = _getTimeComponentArra2[1],
|
|
821
|
+
ss = _getTimeComponentArra2[2],
|
|
822
|
+
ms = _getTimeComponentArra2[3];
|
|
823
|
+
|
|
824
|
+
return "".concat(hh, ":").concat(mm, ":").concat(ss, ".").concat(ms.padStart(3, '0'));
|
|
825
|
+
};
|
|
826
|
+
/**
|
|
827
|
+
* Returns the combined local date and time string
|
|
828
|
+
* @param {Date} date - Data instance
|
|
829
|
+
* @param {string} timeString - string as 'hh:mm:ss.fff'
|
|
830
|
+
* @param {number} offsetInmilliSeconds - additional offset in millisends. Default = 0; e.g. -1 is one millisecond before time specified by timeString;
|
|
831
|
+
* @returns {Date} - combined date and time.
|
|
832
|
+
*/
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
utility.setTime = function (date, timeString) {
|
|
836
|
+
var offsetInmilliSeconds = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
837
|
+
|
|
838
|
+
var _utility$getTimeCompo = utility.getTimeComponentArrayFromString(timeString),
|
|
839
|
+
_utility$getTimeCompo2 = _slicedToArray(_utility$getTimeCompo, 4),
|
|
840
|
+
hh = _utility$getTimeCompo2[0],
|
|
841
|
+
mm = _utility$getTimeCompo2[1],
|
|
842
|
+
ss = _utility$getTimeCompo2[2],
|
|
843
|
+
ms = _utility$getTimeCompo2[3];
|
|
844
|
+
|
|
845
|
+
return msInterval.offset(setTimeForDate(date, hh, mm, ss, ms), offsetInmilliSeconds);
|
|
846
|
+
};
|
|
847
|
+
/**
|
|
848
|
+
* Returns the start of the next day i.e. 00:00:00.000
|
|
849
|
+
* @param {Date} date - Data instance
|
|
850
|
+
* @returns {Date}.
|
|
851
|
+
*/
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
utility.getStartOfNextDay = function (date) {
|
|
855
|
+
return dayInterval.offset(dayInterval.floor(date), 1);
|
|
856
|
+
};
|
|
857
|
+
/**
|
|
858
|
+
* Returns the end of the previous day (1ms before midnight) i.e. 23:59:59.999
|
|
859
|
+
* @param {Date} date - Data instance
|
|
860
|
+
* @returns {Date}.
|
|
861
|
+
*/
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
utility.getEndOfPreviousDay = function (date) {
|
|
865
|
+
return msInterval.offset(dayInterval.floor(date), -1);
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
utility.dayInterval = dayInterval;
|
|
869
|
+
utility.msInterval = msInterval;
|
|
870
|
+
utility.getDay = getDay;
|
|
871
|
+
return utility;
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
var localDateTimeUtility = dateTimeUtility(function (date, hh, mm, ss, ms) {
|
|
875
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), hh, mm, ss, ms);
|
|
876
|
+
}, function (date) {
|
|
877
|
+
return date.getDay();
|
|
878
|
+
}, function (date) {
|
|
879
|
+
return [date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()];
|
|
880
|
+
}, d3Time.timeDay, d3Time.timeMillisecond);
|
|
881
|
+
/**
|
|
882
|
+
* Discontinuity provider implemenation that works with 'non-trading' periods during a trading day
|
|
883
|
+
* @typedef { Object } WeeklyPatternDiscontinuityProvider
|
|
884
|
+
* @property { function(Date): Date } clampUp - When given a value, if it falls within a discontinuity (i.e. an excluded domain range) it should be shifted forwards to the discontinuity boundary. Otherwise, it should be returned unchanged.
|
|
885
|
+
* @property { function(Date): Date } clampDown - When given a value, if it falls within a discontinuity it should be shifted backwards to the discontinuity boundary. Otherwise, it should be returned unchanged.
|
|
886
|
+
* @property { function(Date, Date): number } distance - When given a pair of values, this function returns the distance between the, in domain units, minus any discontinuities. discontinuities.
|
|
887
|
+
* @property { function(Date, number): Date } offset - When given a value and an offset, the value should be advanced by the offset value, skipping any discontinuities, to return the final value.
|
|
888
|
+
* @property { function(): WeeklyPatternDiscontinuityProvider } copy - Creates a copy of the discontinuity provider.
|
|
889
|
+
*/
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Creates WeeklyPatternDiscontinuityProvider
|
|
893
|
+
* @param {Object} nonTradingPattern - contains raw 'non-trading' time ranges for each day of the week
|
|
894
|
+
* @param {DateTimeUtility} dateTimeUtility - uses local or utc dates
|
|
895
|
+
* @returns { WeeklyPatternDiscontinuityProvider } WeeklyPatternDiscontinuityProvider
|
|
896
|
+
*/
|
|
897
|
+
|
|
898
|
+
var base$1 = function base(nonTradingPattern, dateTimeUtility) {
|
|
899
|
+
var getDayPatternOrDefault = function getDayPatternOrDefault(day) {
|
|
900
|
+
return nonTradingPattern[day] === undefined ? [] : nonTradingPattern[day];
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
var tradingDays = [tradingDay(getDayPatternOrDefault('Sunday'), dateTimeUtility), tradingDay(getDayPatternOrDefault('Monday'), dateTimeUtility), tradingDay(getDayPatternOrDefault('Tuesday'), dateTimeUtility), tradingDay(getDayPatternOrDefault('Wednesday'), dateTimeUtility), tradingDay(getDayPatternOrDefault('Thursday'), dateTimeUtility), tradingDay(getDayPatternOrDefault('Friday'), dateTimeUtility), tradingDay(getDayPatternOrDefault('Saturday'), dateTimeUtility)];
|
|
904
|
+
var totalTradingWeekMilliseconds = tradingDays.reduce(function (total, tradingDay) {
|
|
905
|
+
return total + tradingDay.totalTradingTimeInMiliseconds;
|
|
906
|
+
}, 0);
|
|
907
|
+
|
|
908
|
+
if (totalTradingWeekMilliseconds === 0) {
|
|
909
|
+
throw 'Trading pattern must yield at least 1 ms of trading time';
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
var instance = {
|
|
913
|
+
tradingDays: tradingDays,
|
|
914
|
+
totalTradingWeekMilliseconds: totalTradingWeekMilliseconds
|
|
915
|
+
};
|
|
916
|
+
/**
|
|
917
|
+
* When given a value falls within a discontinuity (i.e. an excluded domain range) it should be shifted forwards to the discontinuity boundary.
|
|
918
|
+
* Otherwise, it should be returns unchanged.
|
|
919
|
+
* @param {Date} date - date to clamp up
|
|
920
|
+
* @returns {Date}
|
|
921
|
+
*/
|
|
922
|
+
|
|
923
|
+
instance.clampUp = function (date) {
|
|
924
|
+
var tradingDay = tradingDays[dateTimeUtility.getDay(date)];
|
|
925
|
+
|
|
926
|
+
var _iterator = _createForOfIteratorHelper(tradingDay.nonTradingTimeRanges),
|
|
927
|
+
_step;
|
|
928
|
+
|
|
929
|
+
try {
|
|
930
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
931
|
+
var range = _step.value;
|
|
932
|
+
|
|
933
|
+
if (range.isInRange(date)) {
|
|
934
|
+
return range.endTime === dayBoundary ? instance.clampUp(dateTimeUtility.getStartOfNextDay(date)) : dateTimeUtility.setTime(date, range.endTime);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
} catch (err) {
|
|
938
|
+
_iterator.e(err);
|
|
939
|
+
} finally {
|
|
940
|
+
_iterator.f();
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
return date;
|
|
944
|
+
};
|
|
945
|
+
/**
|
|
946
|
+
* When given a value, if it falls within a discontinuity it should be shifted backwards to the discontinuity boundary. Otherwise, it should be returned unchanged.
|
|
947
|
+
* @param {Date} date - date to clamp down
|
|
948
|
+
* @returns {Date}
|
|
949
|
+
*/
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
instance.clampDown = function (date) {
|
|
953
|
+
var tradingDay = tradingDays[dateTimeUtility.getDay(date)];
|
|
954
|
+
|
|
955
|
+
var _iterator2 = _createForOfIteratorHelper(tradingDay.nonTradingTimeRanges),
|
|
956
|
+
_step2;
|
|
957
|
+
|
|
958
|
+
try {
|
|
959
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
960
|
+
var range = _step2.value;
|
|
961
|
+
|
|
962
|
+
if (range.isInRange(date)) {
|
|
963
|
+
return range.startTime === dayBoundary ? instance.clampDown(dateTimeUtility.getEndOfPreviousDay(date)) : dateTimeUtility.setTime(date, range.startTime, -1);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
} catch (err) {
|
|
967
|
+
_iterator2.e(err);
|
|
968
|
+
} finally {
|
|
969
|
+
_iterator2.f();
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
return date;
|
|
973
|
+
};
|
|
974
|
+
/**
|
|
975
|
+
* When given a pair of values, this function returns the distance between the, in domain units, minus any discontinuities. discontinuities.
|
|
976
|
+
* @param {Date} startDate
|
|
977
|
+
* @param {Date} endDate
|
|
978
|
+
* @returns {number} - the number of milliseconds between the dates
|
|
979
|
+
*/
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
instance.distance = function (startDate, endDate) {
|
|
983
|
+
if (startDate.getTime() === endDate.getTime()) {
|
|
984
|
+
return 0;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
var _ref = startDate <= endDate ? [startDate, endDate, 1] : [endDate, startDate, -1],
|
|
988
|
+
_ref2 = _slicedToArray(_ref, 3),
|
|
989
|
+
start = _ref2[0],
|
|
990
|
+
end = _ref2[1],
|
|
991
|
+
factor = _ref2[2]; // same day distance
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
if (dateTimeUtility.dayInterval(start).getTime() === dateTimeUtility.dayInterval(end).getTime()) {
|
|
995
|
+
// ##### BEGIN: MODIFIED BY SAP
|
|
996
|
+
// Original lines
|
|
997
|
+
// return instance.tradingDays[dateTimeUtility.getDay(start)].totalTradingMillisecondsBetween(start, end);
|
|
998
|
+
// Modified Line
|
|
999
|
+
return factor * instance.tradingDays[dateTimeUtility.getDay(start)].totalTradingMillisecondsBetween(start, end);
|
|
1000
|
+
// ##### END: MODIFIED BY SAP
|
|
1001
|
+
} // combine any trading time left in the day after startDate
|
|
1002
|
+
// and any trading time from midnight up until the endDate
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
var total = instance.tradingDays[dateTimeUtility.getDay(start)].totalTradingMillisecondsBetween(start, dateTimeUtility.dayInterval.offset(dateTimeUtility.dayInterval(start), 1)) + instance.tradingDays[dateTimeUtility.getDay(end)].totalTradingMillisecondsBetween(dateTimeUtility.dayInterval(end), end); // startDate and endDate are consecutive days
|
|
1006
|
+
|
|
1007
|
+
// ##### BEGIN: MODIFIED BY SAP
|
|
1008
|
+
// Original lines
|
|
1009
|
+
// if (dateTimeUtility.dayInterval.count(start, end) === 1) {
|
|
1010
|
+
// return total;
|
|
1011
|
+
// Modified Line
|
|
1012
|
+
if (d3Time.dayCount(start, end) === 1) {
|
|
1013
|
+
return factor * total;
|
|
1014
|
+
// ##### END: MODIFIED BY SAP
|
|
1015
|
+
} // move the start date to following day
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
start = dateTimeUtility.dayInterval.offset(dateTimeUtility.dayInterval(start), 1); // floor endDate to remove 'time component'
|
|
1019
|
+
|
|
1020
|
+
end = dateTimeUtility.dayInterval(end);
|
|
1021
|
+
return factor * dateTimeUtility.dayInterval.range(start, end).reduce(function (runningTotal, currentDay, currentIndex, arr) {
|
|
1022
|
+
var nextDay = currentIndex < arr.length - 1 ? arr[currentIndex + 1] : dateTimeUtility.dayInterval.offset(currentDay, 1);
|
|
1023
|
+
var isDstBoundary = nextDay - currentDay !== millisPerDay;
|
|
1024
|
+
var tradingDay = instance.tradingDays[dateTimeUtility.getDay(currentDay)];
|
|
1025
|
+
return runningTotal += isDstBoundary ? tradingDay.totalTradingMillisecondsBetween(currentDay, nextDay) : tradingDay.totalTradingTimeInMiliseconds;
|
|
1026
|
+
}, total);
|
|
1027
|
+
};
|
|
1028
|
+
/**
|
|
1029
|
+
* When given a value and an offset in milliseconds, the value should be advanced by the offset value, skipping any discontinuities, to return the final value.
|
|
1030
|
+
* @param {Date} date
|
|
1031
|
+
* @param {number} ms
|
|
1032
|
+
*/
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
instance.offset = function (date, ms) {
|
|
1036
|
+
// ##### BEGIN: MODIFIED BY SAP
|
|
1037
|
+
// Original lines
|
|
1038
|
+
//
|
|
1039
|
+
// Modified line
|
|
1040
|
+
ms = Math.floor(ms);
|
|
1041
|
+
// ##### END: MODIFIED BY SAP
|
|
1042
|
+
date = ms >= 0 ? instance.clampUp(date) : instance.clampDown(date);
|
|
1043
|
+
|
|
1044
|
+
var isDstBoundary = function isDstBoundary(d) {
|
|
1045
|
+
return dateTimeUtility.dayInterval.offset(d) - dateTimeUtility.dayInterval(d) !== millisPerDay;
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
var moveToDayBoundary = function moveToDayBoundary(tradingDay, date, ms) {
|
|
1049
|
+
if (ms < 0) {
|
|
1050
|
+
var dateFloor = dateTimeUtility.dayInterval(date);
|
|
1051
|
+
var distanceToStartOfDay = tradingDay.totalTradingMillisecondsBetween(dateFloor, date);
|
|
1052
|
+
return Math.abs(ms) <= distanceToStartOfDay ? tradingDay.offset(date, ms) : [instance.clampDown(dateTimeUtility.msInterval.offset(dateFloor, -1)), ms + distanceToStartOfDay + 1];
|
|
1053
|
+
} else {
|
|
1054
|
+
var nextDate = dateTimeUtility.getStartOfNextDay(date);
|
|
1055
|
+
var distanceToDayBoundary = tradingDay.totalTradingMillisecondsBetween(date, nextDate);
|
|
1056
|
+
return ms < distanceToDayBoundary ? tradingDay.offset(date, ms) : [instance.clampUp(nextDate), ms - distanceToDayBoundary];
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
if (ms === 0) return date;
|
|
1061
|
+
var moveDateDelegate = ms < 0 ? function (date, remainingMs, tradingDayMs) {
|
|
1062
|
+
return [instance.clampDown(dateTimeUtility.dayInterval.offset(date, -1)), remainingMs + tradingDayMs];
|
|
1063
|
+
} : function (date, remainingMs, tradingDayMs) {
|
|
1064
|
+
return [instance.clampUp(dateTimeUtility.dayInterval.offset(date)), remainingMs - tradingDayMs];
|
|
1065
|
+
};
|
|
1066
|
+
var tradingDay = instance.tradingDays[dateTimeUtility.getDay(date)];
|
|
1067
|
+
|
|
1068
|
+
var _moveToDayBoundary = moveToDayBoundary(tradingDay, date, ms);
|
|
1069
|
+
|
|
1070
|
+
var _moveToDayBoundary2 = _slicedToArray(_moveToDayBoundary, 2);
|
|
1071
|
+
|
|
1072
|
+
date = _moveToDayBoundary2[0];
|
|
1073
|
+
ms = _moveToDayBoundary2[1];
|
|
1074
|
+
|
|
1075
|
+
while (ms !== 0) {
|
|
1076
|
+
tradingDay = instance.tradingDays[dateTimeUtility.getDay(date)];
|
|
1077
|
+
|
|
1078
|
+
if (isDstBoundary(date)) {
|
|
1079
|
+
var _moveToDayBoundary3 = moveToDayBoundary(tradingDay, date, ms);
|
|
1080
|
+
|
|
1081
|
+
var _moveToDayBoundary4 = _slicedToArray(_moveToDayBoundary3, 2);
|
|
1082
|
+
|
|
1083
|
+
date = _moveToDayBoundary4[0];
|
|
1084
|
+
ms = _moveToDayBoundary4[1];
|
|
1085
|
+
} else {
|
|
1086
|
+
var _ref3 = Math.abs(ms) >= tradingDay.totalTradingTimeInMiliseconds ? moveDateDelegate(date, ms, tradingDay.totalTradingTimeInMiliseconds) : moveToDayBoundary(tradingDay, date, ms);
|
|
1087
|
+
|
|
1088
|
+
var _ref4 = _slicedToArray(_ref3, 2);
|
|
1089
|
+
|
|
1090
|
+
date = _ref4[0];
|
|
1091
|
+
ms = _ref4[1];
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
return date;
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
instance.copy = function () {
|
|
1099
|
+
return instance;
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
return instance;
|
|
1103
|
+
};
|
|
1104
|
+
var skipWeeklyPattern = (function (nonTradingHoursPattern) {
|
|
1105
|
+
return base$1(nonTradingHoursPattern, localDateTimeUtility);
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
var utcDateTimeUtility = dateTimeUtility(function (date, hh, mm, ss, ms) {
|
|
1109
|
+
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), hh, mm, ss, ms));
|
|
1110
|
+
}, function (date) {
|
|
1111
|
+
return date.getUTCDay();
|
|
1112
|
+
}, function (date) {
|
|
1113
|
+
return [date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds()];
|
|
1114
|
+
}, d3Time.utcDay, d3Time.utcMillisecond);
|
|
1115
|
+
var skipUtcWeeklyPattern = (function (nonTradingUtcHoursPattern) {
|
|
1116
|
+
return base$1(nonTradingUtcHoursPattern, utcDateTimeUtility);
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
exports.discontinuityIdentity = identity;
|
|
1120
|
+
exports.discontinuityRange = provider;
|
|
1121
|
+
exports.discontinuitySkipUtcWeekends = skipUtcWeekends;
|
|
1122
|
+
exports.discontinuitySkipUtcWeeklyPattern = skipUtcWeeklyPattern;
|
|
1123
|
+
exports.discontinuitySkipWeekends = skipWeekends;
|
|
1124
|
+
exports.discontinuitySkipWeeklyPattern = skipWeeklyPattern;
|
|
1125
|
+
exports.scaleDiscontinuous = discontinuous;
|
|
1126
|
+
|
|
1127
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1128
|
+
|
|
1129
|
+
})));
|