disacomp-dateservice 1.0.7 → 1.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.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +14 -3
- package/package.json +1 -1
- package/src/index.ts +33 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ interface IDateManipulator {
|
|
|
21
21
|
startDate: string;
|
|
22
22
|
endDate: string;
|
|
23
23
|
};
|
|
24
|
+
validateDateIsBetweenPeriods(start: string, end: string, date: string): boolean;
|
|
24
25
|
}
|
|
25
26
|
declare class DateService {
|
|
26
27
|
private dateManipulator;
|
|
@@ -42,6 +43,7 @@ declare class DateService {
|
|
|
42
43
|
startDate: string;
|
|
43
44
|
endDate: string;
|
|
44
45
|
};
|
|
46
|
+
validateDateIsBetweenPeriods(start: string, end: string, date: string): boolean;
|
|
45
47
|
}
|
|
46
48
|
declare const DisacompDateService: DateService;
|
|
47
49
|
export default DisacompDateService;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.bothDatesFormated = bothDatesFormated;
|
|
4
|
+
exports.dateClarionToSQL = dateClarionToSQL;
|
|
4
5
|
function AddCeroAtBegin(numero) {
|
|
5
6
|
return numero < 10 ? `0${numero}` : numero;
|
|
6
7
|
}
|
|
@@ -23,7 +24,6 @@ function bothDatesFormated(dateToFormat) {
|
|
|
23
24
|
normalDate: `${day}-${month}-${year}`,
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
exports.bothDatesFormated = bothDatesFormated;
|
|
27
27
|
function dateClarionToSQL(clarionDate) {
|
|
28
28
|
let response;
|
|
29
29
|
if (clarionDate <= 0) {
|
|
@@ -35,7 +35,6 @@ function dateClarionToSQL(clarionDate) {
|
|
|
35
35
|
}
|
|
36
36
|
return response.toISOString();
|
|
37
37
|
}
|
|
38
|
-
exports.dateClarionToSQL = dateClarionToSQL;
|
|
39
38
|
class DateHelper {
|
|
40
39
|
static isLeapYear(year) {
|
|
41
40
|
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
@@ -147,6 +146,15 @@ class DateManipulator {
|
|
|
147
146
|
const endDate = `${this.addCeroAtBegin(DateHelper.getDaysInMonth(month, year))}-${this.addCeroAtBegin(month)}-${year}`;
|
|
148
147
|
return { startDate, endDate };
|
|
149
148
|
}
|
|
149
|
+
validateDateIsBetweenPeriods(start, end, date) {
|
|
150
|
+
const [startMonth, startYear] = start.split("-").map(Number);
|
|
151
|
+
const startDate = new Date(startYear, startMonth - 1, 1);
|
|
152
|
+
const [endMonth, endYear] = end.split("-").map(Number);
|
|
153
|
+
const endDate = new Date(endYear, endMonth, 0);
|
|
154
|
+
const [day, month, year] = date.split("-").map(Number);
|
|
155
|
+
const targetDate = new Date(year, month - 1, day);
|
|
156
|
+
return targetDate >= startDate && targetDate <= endDate;
|
|
157
|
+
}
|
|
150
158
|
}
|
|
151
159
|
class DateService {
|
|
152
160
|
constructor(dateManipulator) {
|
|
@@ -185,6 +193,9 @@ class DateService {
|
|
|
185
193
|
getStartAndEndDateOfMonthWithYear(month, year) {
|
|
186
194
|
return this.dateManipulator.getStartAndEndDateOfMonthWithYear(month, year);
|
|
187
195
|
}
|
|
196
|
+
validateDateIsBetweenPeriods(start, end, date) {
|
|
197
|
+
return this.dateManipulator.validateDateIsBetweenPeriods(start, end, date);
|
|
198
|
+
}
|
|
188
199
|
}
|
|
189
200
|
const DisacompDateService = new DateService(new DateManipulator());
|
|
190
201
|
exports.default = DisacompDateService;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -56,6 +56,11 @@ interface IDateManipulator {
|
|
|
56
56
|
startDate: string;
|
|
57
57
|
endDate: string;
|
|
58
58
|
};
|
|
59
|
+
validateDateIsBetweenPeriods(
|
|
60
|
+
start: string, // mm-yyyy
|
|
61
|
+
end: string, // mm-yyyy
|
|
62
|
+
date: string // dd-mm-yyyy
|
|
63
|
+
): boolean;
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
// Helper class to handle leap years and days in months
|
|
@@ -219,6 +224,26 @@ class DateManipulator implements IDateManipulator {
|
|
|
219
224
|
)}-${this.addCeroAtBegin(month)}-${year}`;
|
|
220
225
|
return { startDate, endDate };
|
|
221
226
|
}
|
|
227
|
+
|
|
228
|
+
public validateDateIsBetweenPeriods(
|
|
229
|
+
start: string, // mm-yyyy
|
|
230
|
+
end: string, // mm-yyyy
|
|
231
|
+
date: string // dd-mm-yyyy
|
|
232
|
+
): boolean {
|
|
233
|
+
// Parse start (mm-yyyy) → primer día del mes
|
|
234
|
+
const [startMonth, startYear] = start.split("-").map(Number);
|
|
235
|
+
const startDate = new Date(startYear, startMonth - 1, 1);
|
|
236
|
+
|
|
237
|
+
// Parse end (mm-yyyy) → último día del mes
|
|
238
|
+
const [endMonth, endYear] = end.split("-").map(Number);
|
|
239
|
+
const endDate = new Date(endYear, endMonth, 0); // día 0 = último día del mes anterior
|
|
240
|
+
|
|
241
|
+
// Parse date (dd-mm-yyyy)
|
|
242
|
+
const [day, month, year] = date.split("-").map(Number);
|
|
243
|
+
const targetDate = new Date(year, month - 1, day);
|
|
244
|
+
|
|
245
|
+
return targetDate >= startDate && targetDate <= endDate;
|
|
246
|
+
}
|
|
222
247
|
}
|
|
223
248
|
|
|
224
249
|
// Client code using dependency inversion
|
|
@@ -281,6 +306,14 @@ class DateService {
|
|
|
281
306
|
} {
|
|
282
307
|
return this.dateManipulator.getStartAndEndDateOfMonthWithYear(month, year);
|
|
283
308
|
}
|
|
309
|
+
|
|
310
|
+
public validateDateIsBetweenPeriods(
|
|
311
|
+
start: string, // mm-yyyy
|
|
312
|
+
end: string, // mm-yyyy
|
|
313
|
+
date: string // dd-mm-yyyy
|
|
314
|
+
): boolean {
|
|
315
|
+
return this.dateManipulator.validateDateIsBetweenPeriods(start, end, date);
|
|
316
|
+
}
|
|
284
317
|
}
|
|
285
318
|
const DisacompDateService = new DateService(new DateManipulator());
|
|
286
319
|
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"fileNames":["../../../.npm-global/lib/node_modules/typescript/lib/lib.es5.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2016.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2017.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.dom.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.scripthost.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.decorators.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../.npm-global/lib/node_modules/typescript/lib/lib.es2017.full.d.ts","./src/index.ts"],"fileInfos":[{"version":"c430d44666289dae81f30fa7b2edebf186ecc91a2d4c71266ea6ae76388792e1","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"080941d9f9ff9307f7e27a83bcd888b7c8270716c39af943532438932ec1d0b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"2e80ee7a49e8ac312cc11b77f1475804bee36b3b2bc896bead8b6e1266befb43","affectsGlobalScope":true,"impliedFormat":1},{"version":"80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89","affectsGlobalScope":true,"impliedFormat":1},{"version":"cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb0f136d372979348d59b3f5020b4cdb81b5504192b1cacff5d1fbba29378aa1","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"a680117f487a4d2f30ea46f1b4b7f58bef1480456e18ba53ee85c2746eeca012","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"1d242d5c24cf285c88bc4fb93c5ff903de8319064e282986edeb6247ba028d5e","impliedFormat":1},{"version":"f73c9ce6370f9ca3de8f7e803eabaa71cac2e75703e6c19e6ba2726821c11fb8","signature":"b1ecc19de7f20c1cb8dd8547e92e090de3bddd9ef4e918dde889ea577594f1bf"}],"root":[30],"options":{"composite":true,"module":1,"noImplicitAny":true,"noImplicitThis":true,"outDir":"./dist","removeComments":true,"rootDir":"./src","strict":true,"strictNullChecks":true,"target":4},"latestChangedDtsFile":"./dist/index.d.ts","version":"5.9.3"}
|