@energinet/watt 2.0.7 → 2.0.8

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.
@@ -11,6 +11,15 @@ class WattRangeValidators {
11
11
  // this condition checks for `maxDays` - 1 (as the diff is in whole days only).
12
12
  return dayjs(value.end).diff(value.start, 'days') > maxDays - 1 ? { maxDays: true } : null;
13
13
  };
14
+ static maxMonths = (maxMonths) => ({ value }) => {
15
+ if (!value?.end || !value?.start)
16
+ return null;
17
+ // Since the date range does not include the last millisecond (ends at 23:59:59.999),
18
+ // this condition checks for `maxMonths` - 1 (as the diff is in whole months only).
19
+ return dayjs(value.end).diff(value.start, 'months') > maxMonths - 1
20
+ ? { maxMonths: true }
21
+ : null;
22
+ };
14
23
  }
15
24
 
16
25
  //#region License
@@ -1 +1 @@
1
- {"version":3,"file":"energinet-watt-validators.mjs","sources":["../../../libs/watt/package/validators/watt-range.validators.ts","../../../libs/watt/package/validators/index.ts","../../../libs/watt/package/validators/energinet-watt-validators.ts"],"sourcesContent":["//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport { AbstractControl, ValidatorFn } from '@angular/forms';\nimport { dayjs, WattDateRange } from '@energinet/watt/core/date';\n\nexport class WattRangeValidators {\n static required: ValidatorFn = (control: AbstractControl<WattDateRange | null>) =>\n control.value?.start && control.value?.end ? null : { rangeRequired: true };\n\n static startRequired: ValidatorFn = (control: AbstractControl<WattDateRange | null>) =>\n control.value?.start ? null : { startOfRangeRequired: true };\n\n static endRequired: ValidatorFn = (control: AbstractControl<WattDateRange | null>) =>\n control.value?.end ? null : { endOfRangeRequired: true };\n\n static maxDays =\n (maxDays: number): ValidatorFn =>\n ({ value }: AbstractControl<WattDateRange | null>) => {\n if (!value?.end || !value?.start) return null;\n // Since the date range does not include the last millisecond (ends at 23:59:59.999),\n // this condition checks for `maxDays` - 1 (as the diff is in whole days only).\n return dayjs(value.end).diff(value.start, 'days') > maxDays - 1 ? { maxDays: true } : null;\n };\n}\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nexport * from './watt-range.validators';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;MAqBa,mBAAmB,CAAA;AAC9B,IAAA,OAAO,QAAQ,GAAgB,CAAC,OAA8C,KAC5E,OAAO,CAAC,KAAK,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE;IAE7E,OAAO,aAAa,GAAgB,CAAC,OAA8C,KACjF,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,EAAE,oBAAoB,EAAE,IAAI,EAAE;IAE9D,OAAO,WAAW,GAAgB,CAAC,OAA8C,KAC/E,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE;AAE1D,IAAA,OAAO,OAAO,GACZ,CAAC,OAAe,KAChB,CAAC,EAAE,KAAK,EAAyC,KAAI;QACnD,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK;AAAE,YAAA,OAAO,IAAI;;;AAG7C,QAAA,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI;AAC5F,KAAC;;;ACtCL;AACA;;;;;;;;;;;;;;;AAeG;AACH;;ACjBA;;AAEG;;;;"}
1
+ {"version":3,"file":"energinet-watt-validators.mjs","sources":["../../../libs/watt/package/validators/watt-range.validators.ts","../../../libs/watt/package/validators/index.ts","../../../libs/watt/package/validators/energinet-watt-validators.ts"],"sourcesContent":["//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport { AbstractControl, ValidatorFn } from '@angular/forms';\nimport { dayjs, WattDateRange } from '@energinet/watt/core/date';\n\nexport class WattRangeValidators {\n static required: ValidatorFn = (control: AbstractControl<WattDateRange | null>) =>\n control.value?.start && control.value?.end ? null : { rangeRequired: true };\n\n static startRequired: ValidatorFn = (control: AbstractControl<WattDateRange | null>) =>\n control.value?.start ? null : { startOfRangeRequired: true };\n\n static endRequired: ValidatorFn = (control: AbstractControl<WattDateRange | null>) =>\n control.value?.end ? null : { endOfRangeRequired: true };\n\n static maxDays =\n (maxDays: number): ValidatorFn =>\n ({ value }: AbstractControl<WattDateRange | null>) => {\n if (!value?.end || !value?.start) return null;\n // Since the date range does not include the last millisecond (ends at 23:59:59.999),\n // this condition checks for `maxDays` - 1 (as the diff is in whole days only).\n return dayjs(value.end).diff(value.start, 'days') > maxDays - 1 ? { maxDays: true } : null;\n };\n\n static maxMonths =\n (maxMonths: number): ValidatorFn =>\n ({ value }: AbstractControl<WattDateRange | null>) => {\n if (!value?.end || !value?.start) return null;\n // Since the date range does not include the last millisecond (ends at 23:59:59.999),\n // this condition checks for `maxMonths` - 1 (as the diff is in whole months only).\n return dayjs(value.end).diff(value.start, 'months') > maxMonths - 1\n ? { maxMonths: true }\n : null;\n };\n}\n","//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nexport * from './watt-range.validators';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;MAqBa,mBAAmB,CAAA;AAC9B,IAAA,OAAO,QAAQ,GAAgB,CAAC,OAA8C,KAC5E,OAAO,CAAC,KAAK,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE;IAE7E,OAAO,aAAa,GAAgB,CAAC,OAA8C,KACjF,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,EAAE,oBAAoB,EAAE,IAAI,EAAE;IAE9D,OAAO,WAAW,GAAgB,CAAC,OAA8C,KAC/E,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE;AAE1D,IAAA,OAAO,OAAO,GACZ,CAAC,OAAe,KAChB,CAAC,EAAE,KAAK,EAAyC,KAAI;QACnD,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK;AAAE,YAAA,OAAO,IAAI;;;AAG7C,QAAA,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI;AAC5F,KAAC;AAEH,IAAA,OAAO,SAAS,GACd,CAAC,SAAiB,KAClB,CAAC,EAAE,KAAK,EAAyC,KAAI;QACnD,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK;AAAE,YAAA,OAAO,IAAI;;;AAG7C,QAAA,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,SAAS,GAAG;AAChE,cAAE,EAAE,SAAS,EAAE,IAAI;cACjB,IAAI;AACV,KAAC;;;ACjDL;AACA;;;;;;;;;;;;;;;AAeG;AACH;;ACjBA;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@energinet/watt",
4
- "version": "2.0.7",
4
+ "version": "2.0.8",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  ".": {
@@ -20,4 +20,5 @@ export declare class WattRangeValidators {
20
20
  static startRequired: ValidatorFn;
21
21
  static endRequired: ValidatorFn;
22
22
  static maxDays: (maxDays: number) => ValidatorFn;
23
+ static maxMonths: (maxMonths: number) => ValidatorFn;
23
24
  }