@utiliread/primitives 1.0.0-55 → 1.0.0-56
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/dist/esm/register-id.d.ts +1 -1
- package/package.json +1 -1
- package/src/index.ts +35 -35
- package/src/register-id.ts +22 -6
- package/src/repository.ts +23 -23
- package/src/step.ts +37 -37
- package/src/time-or-rule.ts +17 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare type RegisterId = "none" | "heatEnergy" | "diffHeatEnergy" | "heatEnergyVolumeInInlet" | "diffHeatEnergyVolumeInInlet" | "heatEnergyVolumeInOutlet" | "diffHeatEnergyVolumeInOutlet" | "coolingEnergy" | "diffCoolingEnergy" | "coolingEnergyVolumeInInlet" | "diffCoolingEnergyVolumeInInlet" | "coolingEnergyVolumeInOutlet" | "diffCoolingEnergyVolumeInOutlet" | "electricalEnergy" | "diffElectricalEnergy" | "reactiveEnergy" | "diffReactiveEnergy" | "volume" | "diffVolume" | "inletVolume" | "diffInletVolume" | "outletVolume" | "diffOutletVolume" | "pulseInputAVolume" | "diffPulseInputAVolume" | "pulseInputBVolume" | "diffPulseInputBVolume" | "mass" | "diffMass" | "inletMass" | "diffInletMass" | "outletMass" | "diffOutletMass" | "power" | "maxPower" | "minPower" | "avgPower" | "inletPower" | "maxInletPower" | "minInletPower" | "avgInletPower" | "outletPower" | "maxOutletPower" | "minOutletPower" | "avgOutletPower" | "volumeFlow" | "maxVolumeFlow" | "minVolumeFlow" | "avgVolumeFlow" | "inletVolumeFlow" | "maxInletVolumeFlow" | "minInletVolumeFlow" | "avgInletVolumeFlow" | "outletVolumeFlow" | "maxOutletVolumeFlow" | "minOutletVolumeFlow" | "avgOutletVolumeFlow" | "massFlow" | "maxMassFlow" | "minMassFlow" | "avgMassFlow" | "inletMassFlow" | "maxInletMassFlow" | "minInletMassFlow" | "avgInletMassFlow" | "outletMassFlow" | "maxOutletMassFlow" | "minOutletMassFlow" | "avgOutletMassFlow" | "flowTemperature" | "maxFlowTemperature" | "minFlowTemperature" | "avgFlowTemperature" | "inletFlowTemperature" | "maxInletFlowTemperature" | "minInletFlowTemperature" | "avgInletFlowTemperature" | "outletFlowTemperature" | "maxOutletFlowTemperature" | "minOutletFlowTemperature" | "avgOutletFlowTemperature" | "inletMinusOutletFlowTemperatureDifference" | "maxInletMinusOutletFlowTemperatureDifference" | "minInletMinusOutletFlowTemperatureDifference" | "avgInletMinusOutletFlowTemperatureDifference" | "outletMinusInletFlowTemperatureDifference" | "maxOutletMinusInletFlowTemperatureDifference" | "minOutletMinusInletFlowTemperatureDifference" | "avgOutletMinusInletFlowTemperatureDifference" | "ambientTemperature" | "maxAmbientTemperature" | "minAmbientTemperature" | "avgAmbientTemperature" | "radiatorTemperature" | "maxRadiatorTemperature" | "minRadiatorTemperature" | "avgRadiatorTemperature" | "relativeHumidity" | "kamstrupE8Inlet" | "diffKamstrupE8Inlet" | "kamstrupE9Outlet" | "diffKamstrupE9Outlet" | "operatingTime" | "diffOperatingTime" | "remainingBatteryTime" | "diffRemainingBatteryTime" | "deviceDate" | "deviceTime" | "deviceDateTime" | "timeSinceLastExactOverhearingArrived" | "timeAtLastExactOverhearingArrived" | "timeSinceLastPossibleCandidateOverhearingArrived" | "timeAtLastPossibleCandidateOverhearingArrived" | "timeSinceLastSampled" | "timeAtLastSampled" | "timeSinceLastInstallationMounted" | "timeAtLastInstallationMounted" | "basetime" | "instantTime" | "periodStartTime" | "periodEndTime" | "instantOrPeriodStartTime" | "instantOrPeriodEndTime" | "device" | "wMBusDeviceAddresses" | "kamdraftDeviceAddresses" | "tchlrDeviceAddresses" | "kamdaDeviceAddresses" | "msisdnDeviceAddresses" | "deviceRegisters" | "consumptionZone" | "mBusFormatStringSignature" | "deviceSoftwareVersion" | "kamstrupMulticalInfocodeType1" | "kamstrupMulticalInfocodeType2" | "kamstrupMulticalInfocodeType3" | "kamstrupMulticalInfocodeType4" | "kamstrupMulticalInfocode" | "kamstrupModuleType" | "diehlInfocodeType1" | "diehlInfocode" | "landisGyrMBusStatusType1" | "landisGyrMBusStatusType2" | "landisGyrMBusStatus" | "landisGyrInfocodeType1" | "landisGyrInfocodeType2" | "landisGyrInfocode" | "infocode";
|
|
1
|
+
export declare type RegisterId = "none" | "heatEnergy" | "diffHeatEnergy" | "heatEnergyVolumeInInlet" | "diffHeatEnergyVolumeInInlet" | "heatEnergyVolumeInOutlet" | "diffHeatEnergyVolumeInOutlet" | "coolingEnergy" | "diffCoolingEnergy" | "coolingEnergyVolumeInInlet" | "diffCoolingEnergyVolumeInInlet" | "coolingEnergyVolumeInOutlet" | "diffCoolingEnergyVolumeInOutlet" | "electricalEnergy" | "diffElectricalEnergy" | "reactiveEnergy" | "diffReactiveEnergy" | "volume" | "diffVolume" | "inletVolume" | "diffInletVolume" | "outletVolume" | "diffOutletVolume" | "pulseInputAVolume" | "diffPulseInputAVolume" | "pulseInputBVolume" | "diffPulseInputBVolume" | "mass" | "diffMass" | "inletMass" | "diffInletMass" | "outletMass" | "diffOutletMass" | "power" | "maxPower" | "minPower" | "avgPower" | "ssqPower" | "inletPower" | "maxInletPower" | "minInletPower" | "avgInletPower" | "ssqInletPower" | "outletPower" | "maxOutletPower" | "minOutletPower" | "avgOutletPower" | "ssqOutletPower" | "volumeFlow" | "maxVolumeFlow" | "minVolumeFlow" | "avgVolumeFlow" | "ssqVolumeFlow" | "inletVolumeFlow" | "maxInletVolumeFlow" | "minInletVolumeFlow" | "avgInletVolumeFlow" | "ssqInletVolumeFlow" | "outletVolumeFlow" | "maxOutletVolumeFlow" | "minOutletVolumeFlow" | "avgOutletVolumeFlow" | "ssqOutletVolumeFlow" | "massFlow" | "maxMassFlow" | "minMassFlow" | "avgMassFlow" | "ssqMassFlow" | "inletMassFlow" | "maxInletMassFlow" | "minInletMassFlow" | "avgInletMassFlow" | "ssqInletMassFlow" | "outletMassFlow" | "maxOutletMassFlow" | "minOutletMassFlow" | "avgOutletMassFlow" | "ssqOutletMassFlow" | "flowTemperature" | "maxFlowTemperature" | "minFlowTemperature" | "avgFlowTemperature" | "ssqFlowTemperature" | "inletFlowTemperature" | "maxInletFlowTemperature" | "minInletFlowTemperature" | "avgInletFlowTemperature" | "ssqInletFlowTemperature" | "outletFlowTemperature" | "maxOutletFlowTemperature" | "minOutletFlowTemperature" | "avgOutletFlowTemperature" | "ssqOutletFlowTemperature" | "inletMinusOutletFlowTemperatureDifference" | "maxInletMinusOutletFlowTemperatureDifference" | "minInletMinusOutletFlowTemperatureDifference" | "avgInletMinusOutletFlowTemperatureDifference" | "ssqInletMinusOutletFlowTemperatureDifference" | "outletMinusInletFlowTemperatureDifference" | "maxOutletMinusInletFlowTemperatureDifference" | "minOutletMinusInletFlowTemperatureDifference" | "avgOutletMinusInletFlowTemperatureDifference" | "ssqOutletMinusInletFlowTemperatureDifference" | "ambientTemperature" | "maxAmbientTemperature" | "minAmbientTemperature" | "avgAmbientTemperature" | "ssqAmbientTemperature" | "radiatorTemperature" | "maxRadiatorTemperature" | "minRadiatorTemperature" | "avgRadiatorTemperature" | "ssqRadiatorTemperature" | "relativeHumidity" | "kamstrupE8Inlet" | "diffKamstrupE8Inlet" | "kamstrupE9Outlet" | "diffKamstrupE9Outlet" | "operatingTime" | "diffOperatingTime" | "remainingBatteryTime" | "diffRemainingBatteryTime" | "deviceDate" | "deviceTime" | "deviceDateTime" | "timeSinceLastExactOverhearingArrived" | "timeAtLastExactOverhearingArrived" | "timeSinceLastPossibleCandidateOverhearingArrived" | "timeAtLastPossibleCandidateOverhearingArrived" | "timeSinceLastSampled" | "timeAtLastSampled" | "timeSinceLastInstallationMounted" | "timeAtLastInstallationMounted" | "basetime" | "instantTime" | "periodStartTime" | "periodEndTime" | "instantOrPeriodStartTime" | "instantOrPeriodEndTime" | "device" | "wMBusDeviceAddresses" | "kamdraftDeviceAddresses" | "tchlrDeviceAddresses" | "kamdaDeviceAddresses" | "msisdnDeviceAddresses" | "deviceRegisters" | "consumptionZone" | "mBusFormatStringSignature" | "deviceSoftwareVersion" | "kamstrupMulticalInfocodeType1" | "kamstrupMulticalInfocodeType2" | "kamstrupMulticalInfocodeType3" | "kamstrupMulticalInfocodeType4" | "kamstrupMulticalInfocode" | "kamstrupModuleType" | "diehlInfocodeType1" | "diehlInfocode" | "landisGyrMBusStatusType1" | "landisGyrMBusStatusType2" | "landisGyrMBusStatus" | "landisGyrInfocodeType1" | "landisGyrInfocodeType2" | "landisGyrInfocode" | "infocode";
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import type { ConsumptionTypeId } from "./consumption-type-id";
|
|
2
|
-
import type { RegisterId } from "./register-id";
|
|
3
|
-
import type { UnitId } from "./unit-id";
|
|
4
|
-
import { RegisterLibrary } from "./register-library";
|
|
5
|
-
import type { RegisterDefinition } from "./register-definition";
|
|
6
|
-
import { NumberFormatter, invariantDecimalSeparator, localeDecimalSeparator } from "./number-formatter";
|
|
7
|
-
import { RegisterConvention } from "./register-convention";
|
|
8
|
-
import type { AggregateId } from "./aggregate-id";
|
|
9
|
-
import type { MeasureId } from "./measure-id";
|
|
10
|
-
import { Step, DayOfWeek } from "./step";
|
|
11
|
-
import { TimeOrRule } from "./time-or-rule";
|
|
12
|
-
import { PrecisionNumber } from "./precision-number";
|
|
13
|
-
import "./repository"; // We need this to get the Repository namespace exported
|
|
14
|
-
import { Repository } from "./repository";
|
|
15
|
-
import type { Optional } from "./optional";
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
AggregateId,
|
|
19
|
-
ConsumptionTypeId,
|
|
20
|
-
DayOfWeek,
|
|
21
|
-
MeasureId,
|
|
22
|
-
NumberFormatter,
|
|
23
|
-
PrecisionNumber,
|
|
24
|
-
RegisterConvention,
|
|
25
|
-
RegisterDefinition,
|
|
26
|
-
RegisterId,
|
|
27
|
-
RegisterLibrary,
|
|
28
|
-
Repository,
|
|
29
|
-
Step,
|
|
30
|
-
TimeOrRule,
|
|
31
|
-
UnitId,
|
|
32
|
-
invariantDecimalSeparator,
|
|
33
|
-
localeDecimalSeparator,
|
|
34
|
-
Optional,
|
|
35
|
-
};
|
|
1
|
+
import type { ConsumptionTypeId } from "./consumption-type-id";
|
|
2
|
+
import type { RegisterId } from "./register-id";
|
|
3
|
+
import type { UnitId } from "./unit-id";
|
|
4
|
+
import { RegisterLibrary } from "./register-library";
|
|
5
|
+
import type { RegisterDefinition } from "./register-definition";
|
|
6
|
+
import { NumberFormatter, invariantDecimalSeparator, localeDecimalSeparator } from "./number-formatter";
|
|
7
|
+
import { RegisterConvention } from "./register-convention";
|
|
8
|
+
import type { AggregateId } from "./aggregate-id";
|
|
9
|
+
import type { MeasureId } from "./measure-id";
|
|
10
|
+
import { Step, DayOfWeek } from "./step";
|
|
11
|
+
import { TimeOrRule } from "./time-or-rule";
|
|
12
|
+
import { PrecisionNumber } from "./precision-number";
|
|
13
|
+
import "./repository"; // We need this to get the Repository namespace exported
|
|
14
|
+
import { Repository } from "./repository";
|
|
15
|
+
import type { Optional } from "./optional";
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
AggregateId,
|
|
19
|
+
ConsumptionTypeId,
|
|
20
|
+
DayOfWeek,
|
|
21
|
+
MeasureId,
|
|
22
|
+
NumberFormatter,
|
|
23
|
+
PrecisionNumber,
|
|
24
|
+
RegisterConvention,
|
|
25
|
+
RegisterDefinition,
|
|
26
|
+
RegisterId,
|
|
27
|
+
RegisterLibrary,
|
|
28
|
+
Repository,
|
|
29
|
+
Step,
|
|
30
|
+
TimeOrRule,
|
|
31
|
+
UnitId,
|
|
32
|
+
invariantDecimalSeparator,
|
|
33
|
+
localeDecimalSeparator,
|
|
34
|
+
Optional,
|
|
35
|
+
};
|
package/src/register-id.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type RegisterId =
|
|
2
2
|
"none" |
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
"heatEnergy" |
|
|
5
5
|
"diffHeatEnergy" |
|
|
6
6
|
|
|
@@ -53,81 +53,97 @@ export type RegisterId =
|
|
|
53
53
|
"maxPower" |
|
|
54
54
|
"minPower" |
|
|
55
55
|
"avgPower" |
|
|
56
|
+
"ssqPower" |
|
|
56
57
|
|
|
57
58
|
"inletPower" |
|
|
58
59
|
"maxInletPower" |
|
|
59
60
|
"minInletPower" |
|
|
60
61
|
"avgInletPower" |
|
|
62
|
+
"ssqInletPower" |
|
|
61
63
|
|
|
62
64
|
"outletPower" |
|
|
63
65
|
"maxOutletPower" |
|
|
64
66
|
"minOutletPower" |
|
|
65
67
|
"avgOutletPower" |
|
|
68
|
+
"ssqOutletPower" |
|
|
66
69
|
|
|
67
70
|
"volumeFlow" |
|
|
68
71
|
"maxVolumeFlow" |
|
|
69
72
|
"minVolumeFlow" |
|
|
70
73
|
"avgVolumeFlow" |
|
|
74
|
+
"ssqVolumeFlow" |
|
|
71
75
|
|
|
72
76
|
"inletVolumeFlow" |
|
|
73
77
|
"maxInletVolumeFlow" |
|
|
74
78
|
"minInletVolumeFlow" |
|
|
75
79
|
"avgInletVolumeFlow" |
|
|
80
|
+
"ssqInletVolumeFlow" |
|
|
76
81
|
|
|
77
82
|
"outletVolumeFlow" |
|
|
78
83
|
"maxOutletVolumeFlow" |
|
|
79
84
|
"minOutletVolumeFlow" |
|
|
80
85
|
"avgOutletVolumeFlow" |
|
|
86
|
+
"ssqOutletVolumeFlow" |
|
|
81
87
|
|
|
82
88
|
"massFlow" |
|
|
83
89
|
"maxMassFlow" |
|
|
84
90
|
"minMassFlow" |
|
|
85
91
|
"avgMassFlow" |
|
|
92
|
+
"ssqMassFlow" |
|
|
86
93
|
|
|
87
94
|
"inletMassFlow" |
|
|
88
95
|
"maxInletMassFlow" |
|
|
89
96
|
"minInletMassFlow" |
|
|
90
97
|
"avgInletMassFlow" |
|
|
98
|
+
"ssqInletMassFlow" |
|
|
91
99
|
|
|
92
100
|
"outletMassFlow" |
|
|
93
101
|
"maxOutletMassFlow" |
|
|
94
102
|
"minOutletMassFlow" |
|
|
95
103
|
"avgOutletMassFlow" |
|
|
104
|
+
"ssqOutletMassFlow" |
|
|
96
105
|
|
|
97
106
|
"flowTemperature" |
|
|
98
107
|
"maxFlowTemperature" |
|
|
99
108
|
"minFlowTemperature" |
|
|
100
109
|
"avgFlowTemperature" |
|
|
110
|
+
"ssqFlowTemperature" |
|
|
101
111
|
|
|
102
112
|
"inletFlowTemperature" |
|
|
103
113
|
"maxInletFlowTemperature" |
|
|
104
114
|
"minInletFlowTemperature" |
|
|
105
115
|
"avgInletFlowTemperature" |
|
|
116
|
+
"ssqInletFlowTemperature" |
|
|
106
117
|
|
|
107
118
|
"outletFlowTemperature" |
|
|
108
119
|
"maxOutletFlowTemperature" |
|
|
109
120
|
"minOutletFlowTemperature" |
|
|
110
121
|
"avgOutletFlowTemperature" |
|
|
122
|
+
"ssqOutletFlowTemperature" |
|
|
111
123
|
|
|
112
124
|
"inletMinusOutletFlowTemperatureDifference" |
|
|
113
125
|
"maxInletMinusOutletFlowTemperatureDifference" |
|
|
114
126
|
"minInletMinusOutletFlowTemperatureDifference" |
|
|
115
127
|
"avgInletMinusOutletFlowTemperatureDifference" |
|
|
128
|
+
"ssqInletMinusOutletFlowTemperatureDifference" |
|
|
116
129
|
|
|
117
130
|
"outletMinusInletFlowTemperatureDifference" |
|
|
118
131
|
"maxOutletMinusInletFlowTemperatureDifference" |
|
|
119
132
|
"minOutletMinusInletFlowTemperatureDifference" |
|
|
120
133
|
"avgOutletMinusInletFlowTemperatureDifference" |
|
|
134
|
+
"ssqOutletMinusInletFlowTemperatureDifference" |
|
|
121
135
|
|
|
122
136
|
"ambientTemperature" |
|
|
123
137
|
"maxAmbientTemperature" |
|
|
124
138
|
"minAmbientTemperature" |
|
|
125
139
|
"avgAmbientTemperature" |
|
|
140
|
+
"ssqAmbientTemperature" |
|
|
126
141
|
|
|
127
142
|
"radiatorTemperature" |
|
|
128
143
|
"maxRadiatorTemperature" |
|
|
129
144
|
"minRadiatorTemperature" |
|
|
130
145
|
"avgRadiatorTemperature" |
|
|
146
|
+
"ssqRadiatorTemperature" |
|
|
131
147
|
|
|
132
148
|
"relativeHumidity" |
|
|
133
149
|
|
|
@@ -151,10 +167,10 @@ export type RegisterId =
|
|
|
151
167
|
|
|
152
168
|
"timeSinceLastPossibleCandidateOverhearingArrived" |
|
|
153
169
|
"timeAtLastPossibleCandidateOverhearingArrived" |
|
|
154
|
-
|
|
170
|
+
|
|
155
171
|
"timeSinceLastSampled" |
|
|
156
172
|
"timeAtLastSampled" |
|
|
157
|
-
|
|
173
|
+
|
|
158
174
|
"timeSinceLastInstallationMounted" |
|
|
159
175
|
"timeAtLastInstallationMounted" |
|
|
160
176
|
|
|
@@ -183,7 +199,7 @@ export type RegisterId =
|
|
|
183
199
|
"kamstrupMulticalInfocodeType4" |
|
|
184
200
|
"kamstrupMulticalInfocode" |
|
|
185
201
|
"kamstrupModuleType" |
|
|
186
|
-
|
|
202
|
+
|
|
187
203
|
"diehlInfocodeType1" |
|
|
188
204
|
"diehlInfocode" |
|
|
189
205
|
|
|
@@ -193,5 +209,5 @@ export type RegisterId =
|
|
|
193
209
|
"landisGyrInfocodeType1" |
|
|
194
210
|
"landisGyrInfocodeType2" |
|
|
195
211
|
"landisGyrInfocode" |
|
|
196
|
-
|
|
197
|
-
"infocode";
|
|
212
|
+
|
|
213
|
+
"infocode";
|
package/src/repository.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
// This is clearly not correct but it provides some amazing type safety
|
|
2
|
-
export type Repository = "some/repo";
|
|
3
|
-
|
|
4
|
-
export function Repository(repo: string): Repository;
|
|
5
|
-
export function Repository(team: string, name: string): Repository;
|
|
6
|
-
export function Repository(repoOrTeam: string, name?: string): Repository {
|
|
7
|
-
if (name) {
|
|
8
|
-
return <Repository>`${repoOrTeam}/${name}`;
|
|
9
|
-
} else if (repoOrTeam.indexOf("/") > 0) {
|
|
10
|
-
return <Repository>repoOrTeam;
|
|
11
|
-
} else {
|
|
12
|
-
throw new TypeError("Invalid repository format");
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export namespace Repository {
|
|
17
|
-
export function split(repo: Repository) {
|
|
18
|
-
const parts = repo.split("/");
|
|
19
|
-
return {
|
|
20
|
-
team: parts[0],
|
|
21
|
-
name: parts[1],
|
|
22
|
-
};
|
|
23
|
-
}
|
|
1
|
+
// This is clearly not correct but it provides some amazing type safety
|
|
2
|
+
export type Repository = "some/repo";
|
|
3
|
+
|
|
4
|
+
export function Repository(repo: string): Repository;
|
|
5
|
+
export function Repository(team: string, name: string): Repository;
|
|
6
|
+
export function Repository(repoOrTeam: string, name?: string): Repository {
|
|
7
|
+
if (name) {
|
|
8
|
+
return <Repository>`${repoOrTeam}/${name}`;
|
|
9
|
+
} else if (repoOrTeam.indexOf("/") > 0) {
|
|
10
|
+
return <Repository>repoOrTeam;
|
|
11
|
+
} else {
|
|
12
|
+
throw new TypeError("Invalid repository format");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export namespace Repository {
|
|
17
|
+
export function split(repo: Repository) {
|
|
18
|
+
const parts = repo.split("/");
|
|
19
|
+
return {
|
|
20
|
+
team: parts[0],
|
|
21
|
+
name: parts[1],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
24
|
}
|
package/src/step.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { DateTime, Duration } from "luxon";
|
|
2
|
-
|
|
3
|
-
export type Step = "hour" | "day" | "week" | "month" | "year";
|
|
4
|
-
|
|
5
|
-
export enum DayOfWeek {
|
|
6
|
-
Monday = 1,
|
|
7
|
-
Tuesday = 2,
|
|
8
|
-
Wednesday = 3,
|
|
9
|
-
Thursday = 4,
|
|
10
|
-
Friday = 5,
|
|
11
|
-
Saturday = 6,
|
|
12
|
-
Sunday = 7,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export namespace Step {
|
|
16
|
-
export function startOf(dateTime: DateTime, step: Step, firstDayOfWeek?: DayOfWeek): DateTime {
|
|
17
|
-
if (step === "week") {
|
|
18
|
-
const value = dateTime.startOf("day").set({ weekday: firstDayOfWeek ?? DayOfWeek.Monday });
|
|
19
|
-
return value > dateTime
|
|
20
|
-
? value.minus({ days: 7 })
|
|
21
|
-
: value;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
return dateTime.startOf(step);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function asDuration(step: Step, amount = 1): Duration {
|
|
29
|
-
switch (step) {
|
|
30
|
-
case "hour": return Duration.fromObject({ hours: amount });
|
|
31
|
-
case "day": return Duration.fromObject({ days: amount });
|
|
32
|
-
case "week": return Duration.fromObject({ days: 7 * amount });
|
|
33
|
-
case "month": return Duration.fromObject({ months: amount });
|
|
34
|
-
case "year": return Duration.fromObject({ years: amount });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
import { DateTime, Duration } from "luxon";
|
|
2
|
+
|
|
3
|
+
export type Step = "hour" | "day" | "week" | "month" | "year";
|
|
4
|
+
|
|
5
|
+
export enum DayOfWeek {
|
|
6
|
+
Monday = 1,
|
|
7
|
+
Tuesday = 2,
|
|
8
|
+
Wednesday = 3,
|
|
9
|
+
Thursday = 4,
|
|
10
|
+
Friday = 5,
|
|
11
|
+
Saturday = 6,
|
|
12
|
+
Sunday = 7,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export namespace Step {
|
|
16
|
+
export function startOf(dateTime: DateTime, step: Step, firstDayOfWeek?: DayOfWeek): DateTime {
|
|
17
|
+
if (step === "week") {
|
|
18
|
+
const value = dateTime.startOf("day").set({ weekday: firstDayOfWeek ?? DayOfWeek.Monday });
|
|
19
|
+
return value > dateTime
|
|
20
|
+
? value.minus({ days: 7 })
|
|
21
|
+
: value;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return dateTime.startOf(step);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function asDuration(step: Step, amount = 1): Duration {
|
|
29
|
+
switch (step) {
|
|
30
|
+
case "hour": return Duration.fromObject({ hours: amount });
|
|
31
|
+
case "day": return Duration.fromObject({ days: amount });
|
|
32
|
+
case "week": return Duration.fromObject({ days: 7 * amount });
|
|
33
|
+
case "month": return Duration.fromObject({ months: amount });
|
|
34
|
+
case "year": return Duration.fromObject({ years: amount });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/time-or-rule.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { DateTime } from "luxon";
|
|
2
|
-
|
|
3
|
-
export type TimeOrRule = Date | DateTime | string;
|
|
4
|
-
|
|
5
|
-
export namespace TimeOrRule {
|
|
6
|
-
export function isTime(input: TimeOrRule): input is Date | DateTime {
|
|
7
|
-
return typeof input !== "string";
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isRule(input: TimeOrRule): input is string {
|
|
11
|
-
return typeof input === "string";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function asJSON(input: TimeOrRule) {
|
|
15
|
-
return isRule(input) ? input : input.toJSON();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
|
|
3
|
+
export type TimeOrRule = Date | DateTime | string;
|
|
4
|
+
|
|
5
|
+
export namespace TimeOrRule {
|
|
6
|
+
export function isTime(input: TimeOrRule): input is Date | DateTime {
|
|
7
|
+
return typeof input !== "string";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function isRule(input: TimeOrRule): input is string {
|
|
11
|
+
return typeof input === "string";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function asJSON(input: TimeOrRule) {
|
|
15
|
+
return isRule(input) ? input : input.toJSON();
|
|
16
|
+
}
|
|
17
|
+
}
|