disacomp-dateservice 1.0.11 → 1.0.13

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 CHANGED
@@ -24,6 +24,8 @@ interface IDateManipulator {
24
24
  validateDateIsBetweenPeriods(start: string, end: string, date: string): boolean;
25
25
  addMonths(month: number, addMonthsCount: number): number;
26
26
  substractMonths(month: number, substractMonthsCount: number): number;
27
+ getListOfDatesBetweenTwoDates(start: string, end: string, includeStartEnd: boolean): string[];
28
+ dateStringToMs(dateStr: string): number;
27
29
  }
28
30
  declare class DateService {
29
31
  private dateManipulator;
@@ -48,6 +50,8 @@ declare class DateService {
48
50
  validateDateIsBetweenPeriods(start: string, end: string, date: string): boolean;
49
51
  addMonths(month: number, addMonthsCount: number): number;
50
52
  substractMonths(month: number, substractMonthsCount: number): number;
53
+ getListOfDatesBetweenTwoDates(start: string, end: string, includeStartEnd: boolean): string[];
54
+ dateStringToMs(dateStr: string): number;
51
55
  }
52
56
  declare const DisacompDateService: DateService;
53
57
  export default DisacompDateService;
package/dist/index.js CHANGED
@@ -163,6 +163,43 @@ class DateManipulator {
163
163
  const totalMonths = month - substractMonthsCount;
164
164
  return ((totalMonths - 1 + 12) % 12) + 1;
165
165
  }
166
+ getListOfDatesBetweenTwoDates(start, end, includeStartEnd) {
167
+ const OFFSET = -4 * 60;
168
+ const DIA_MS = 24 * 60 * 60 * 1000;
169
+ function parse(fecha) {
170
+ const [d, m, y] = fecha.split("-").map(Number);
171
+ return Date.UTC(y, m - 1, d) - OFFSET * 60 * 1000;
172
+ }
173
+ function formatear(ms) {
174
+ const local = new Date(ms + OFFSET * 60 * 1000);
175
+ const d = String(local.getUTCDate()).padStart(2, "0");
176
+ const m = String(local.getUTCMonth() + 1).padStart(2, "0");
177
+ const y = local.getUTCFullYear();
178
+ return `${d}-${m}-${y}`;
179
+ }
180
+ let begin = parse(start);
181
+ let ending = parse(end);
182
+ if (begin > ending)
183
+ [begin, ending] = [ending, begin];
184
+ if (!includeStartEnd) {
185
+ begin += DIA_MS;
186
+ ending -= DIA_MS;
187
+ }
188
+ const result = [];
189
+ for (let t = begin; t <= ending; t += DIA_MS) {
190
+ result.push(formatear(t));
191
+ }
192
+ return result;
193
+ }
194
+ dateStringToMs(dateStr) {
195
+ const [day, month, year] = dateStr.split("-").map(Number);
196
+ if (!day || !month || !year) {
197
+ throw new Error("Formato inválido, usa dd-mm-yyyy");
198
+ }
199
+ const utcMs = Date.UTC(year, month - 1, day, 0, 0, 0);
200
+ const offsetMs = 4 * 60 * 60 * 1000;
201
+ return utcMs + offsetMs;
202
+ }
166
203
  }
167
204
  class DateService {
168
205
  constructor(dateManipulator) {
@@ -210,6 +247,12 @@ class DateService {
210
247
  substractMonths(month, substractMonthsCount) {
211
248
  return this.dateManipulator.substractMonths(month, substractMonthsCount);
212
249
  }
250
+ getListOfDatesBetweenTwoDates(start, end, includeStartEnd) {
251
+ return this.dateManipulator.getListOfDatesBetweenTwoDates(start, end, includeStartEnd);
252
+ }
253
+ dateStringToMs(dateStr) {
254
+ return this.dateManipulator.dateStringToMs(dateStr);
255
+ }
213
256
  }
214
257
  const DisacompDateService = new DateService(new DateManipulator());
215
258
  exports.default = DisacompDateService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "disacomp-dateservice",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Disacomp Date Service",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -63,6 +63,12 @@ interface IDateManipulator {
63
63
  ): boolean;
64
64
  addMonths(month: number, addMonthsCount: number): number;
65
65
  substractMonths(month: number, substractMonthsCount: number): number;
66
+ getListOfDatesBetweenTwoDates(
67
+ start: string,
68
+ end: string,
69
+ includeStartEnd: boolean,
70
+ ): string[];
71
+ dateStringToMs(dateStr: string): number;
66
72
  }
67
73
 
68
74
  // Helper class to handle leap years and days in months
@@ -256,6 +262,66 @@ class DateManipulator implements IDateManipulator {
256
262
  const totalMonths = month - substractMonthsCount;
257
263
  return ((totalMonths - 1 + 12) % 12) + 1; // Ajusta para que el resultado esté entre 1 y 12
258
264
  }
265
+
266
+ public getListOfDatesBetweenTwoDates(
267
+ start: string,
268
+ end: string,
269
+ includeStartEnd: boolean,
270
+ ): string[] {
271
+ const OFFSET = -4 * 60; // UTC-4 en minutos
272
+ const DIA_MS = 24 * 60 * 60 * 1000;
273
+
274
+ function parse(fecha: string): number {
275
+ const [d, m, y] = fecha.split("-").map(Number);
276
+
277
+ // convertimos medianoche UTC-4 → UTC real
278
+ return Date.UTC(y, m - 1, d) - OFFSET * 60 * 1000;
279
+ }
280
+
281
+ function formatear(ms: number): string {
282
+ const local = new Date(ms + OFFSET * 60 * 1000);
283
+
284
+ const d = String(local.getUTCDate()).padStart(2, "0");
285
+ const m = String(local.getUTCMonth() + 1).padStart(2, "0");
286
+ const y = local.getUTCFullYear();
287
+
288
+ return `${d}-${m}-${y}`;
289
+ }
290
+
291
+ let begin = parse(start);
292
+ let ending = parse(end);
293
+
294
+ if (begin > ending) [begin, ending] = [ending, begin];
295
+
296
+ if (!includeStartEnd) {
297
+ begin += DIA_MS;
298
+ ending -= DIA_MS;
299
+ }
300
+
301
+ const result: string[] = [];
302
+
303
+ for (let t = begin; t <= ending; t += DIA_MS) {
304
+ result.push(formatear(t));
305
+ }
306
+
307
+ return result;
308
+ }
309
+
310
+ dateStringToMs(dateStr: string): number {
311
+ const [day, month, year] = dateStr.split("-").map(Number);
312
+
313
+ if (!day || !month || !year) {
314
+ throw new Error("Formato inválido, usa dd-mm-yyyy");
315
+ }
316
+
317
+ // Creamos la fecha como si fuera UTC
318
+ const utcMs = Date.UTC(year, month - 1, day, 0, 0, 0);
319
+
320
+ // Ajustamos a UTC-4 → sumamos 4 horas para llevarlo a UTC real
321
+ const offsetMs = 4 * 60 * 60 * 1000;
322
+
323
+ return utcMs + offsetMs;
324
+ }
259
325
  }
260
326
 
261
327
  // Client code using dependency inversion
@@ -334,6 +400,22 @@ class DateService {
334
400
  public substractMonths(month: number, substractMonthsCount: number): number {
335
401
  return this.dateManipulator.substractMonths(month, substractMonthsCount);
336
402
  }
403
+
404
+ public getListOfDatesBetweenTwoDates(
405
+ start: string,
406
+ end: string,
407
+ includeStartEnd: boolean,
408
+ ): string[] {
409
+ return this.dateManipulator.getListOfDatesBetweenTwoDates(
410
+ start,
411
+ end,
412
+ includeStartEnd,
413
+ );
414
+ }
415
+
416
+ public dateStringToMs(dateStr: string): number {
417
+ return this.dateManipulator.dateStringToMs(dateStr);
418
+ }
337
419
  }
338
420
  const DisacompDateService = new DateService(new DateManipulator());
339
421
 
@@ -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":"a374fc6626a52aebae625c5814aa0656253edefeee34f7bd4d1fef1540214594","signature":"4d47c226b0e5a3482e4f0f24c1e9903ee3025072f4b339c11f33674bb63b5595"}],"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"}
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":"c33f0a0d5174c75c1d3525849ca64992857a4b23600c5644c1609dda17399d47","signature":"9bf06f933970df7042d62d37147f4a7f23e70c08bf7c14a99c537756622eaadd"}],"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"}