disacomp-dateservice 1.0.0 → 1.0.1

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
@@ -9,6 +9,8 @@ interface IDateManipulator {
9
9
  getDateFromDateSrting(date: string): Date;
10
10
  calculateDaysBetweenDates(date1: string, date2: string): number;
11
11
  getPeriodFromDate(date: string): string;
12
+ isValidDate(date: string): boolean;
13
+ getSignDate(): string;
12
14
  }
13
15
  declare class DateService {
14
16
  private dateManipulator;
@@ -18,6 +20,8 @@ declare class DateService {
18
20
  getCurrentDate(): string;
19
21
  getDateFromDateString(dateString: string): Date;
20
22
  getPeriodFromDate(date: string): string;
23
+ isValidDate(dateString: string): boolean;
24
+ getSignDate(): string;
21
25
  }
22
26
  declare const DisacompDateService: DateService;
23
27
  export default DisacompDateService;
package/dist/index.js CHANGED
@@ -105,6 +105,29 @@ class DateManipulator {
105
105
  const [day, month, year] = date.split("-").map(Number);
106
106
  return `${month}-${year}`;
107
107
  }
108
+ isValidDate(date) {
109
+ const regex = /^(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[0-2])-\d{4}$/;
110
+ if (!regex.test(date))
111
+ return false;
112
+ const [day, month, year] = date.split("-").map(Number);
113
+ const parsedDate = new Date(Date.UTC(year, month - 1, day));
114
+ return (parsedDate.getUTCFullYear() === year &&
115
+ parsedDate.getUTCMonth() + 1 === month &&
116
+ parsedDate.getUTCDate() === day);
117
+ }
118
+ addCeroAtBegin(numero) {
119
+ return numero < 10 ? `0${numero}` : `${numero}`;
120
+ }
121
+ getSignDate() {
122
+ let date = new Date();
123
+ const day = this.addCeroAtBegin(date.getUTCDate());
124
+ const month = this.addCeroAtBegin(date.getMonth() + 1);
125
+ const year = date.getFullYear();
126
+ const hours = this.addCeroAtBegin(date.getHours());
127
+ const min = this.addCeroAtBegin(date.getMinutes());
128
+ const sec = this.addCeroAtBegin(date.getSeconds());
129
+ return `${day}-${month}-${year} ${hours}:${min}:${sec}`;
130
+ }
108
131
  }
109
132
  class DateService {
110
133
  constructor(dateManipulator) {
@@ -125,6 +148,12 @@ class DateService {
125
148
  getPeriodFromDate(date) {
126
149
  return this.dateManipulator.getPeriodFromDate(date);
127
150
  }
151
+ isValidDate(dateString) {
152
+ return this.dateManipulator.isValidDate(dateString);
153
+ }
154
+ getSignDate() {
155
+ return this.dateManipulator.getSignDate();
156
+ }
128
157
  }
129
158
  const DisacompDateService = new DateService(new DateManipulator());
130
159
  exports.default = DisacompDateService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "disacomp-dateservice",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Disacomp Date Service",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -41,6 +41,8 @@ interface IDateManipulator {
41
41
  getDateFromDateSrting(date: string): Date;
42
42
  calculateDaysBetweenDates(date1: string, date2: string): number;
43
43
  getPeriodFromDate(date: string): string;
44
+ isValidDate(date: string): boolean;
45
+ getSignDate(): string;
44
46
  }
45
47
 
46
48
  // Helper class to handle leap years and days in months
@@ -132,6 +134,40 @@ class DateManipulator implements IDateManipulator {
132
134
 
133
135
  return `${month}-${year}`; // Concatenate year and month
134
136
  }
137
+
138
+ public isValidDate(date: string): boolean {
139
+ const regex = /^(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[0-2])-\d{4}$/;
140
+
141
+ if (!regex.test(date)) return false; // Verifica el formato
142
+
143
+ const [day, month, year] = date.split("-").map(Number);
144
+
145
+ // Crear la fecha con UTC para evitar problemas de zonas horarias
146
+ const parsedDate = new Date(Date.UTC(year, month - 1, day));
147
+
148
+ return (
149
+ parsedDate.getUTCFullYear() === year &&
150
+ parsedDate.getUTCMonth() + 1 === month &&
151
+ parsedDate.getUTCDate() === day
152
+ );
153
+ }
154
+
155
+ private addCeroAtBegin(numero: number): string {
156
+ return numero < 10 ? `0${numero}` : `${numero}`;
157
+ }
158
+
159
+ public getSignDate(): string {
160
+ let date = new Date();
161
+ const day = this.addCeroAtBegin(date.getUTCDate());
162
+ const month = this.addCeroAtBegin(date.getMonth() + 1); // Meses son indexados desde 0
163
+ const year = date.getFullYear();
164
+
165
+ const hours = this.addCeroAtBegin(date.getHours());
166
+ const min = this.addCeroAtBegin(date.getMinutes());
167
+ const sec = this.addCeroAtBegin(date.getSeconds());
168
+
169
+ return `${day}-${month}-${year} ${hours}:${min}:${sec}`;
170
+ }
135
171
  }
136
172
 
137
173
  // Client code using dependency inversion
@@ -161,6 +197,14 @@ class DateService {
161
197
  public getPeriodFromDate(date: string): string {
162
198
  return this.dateManipulator.getPeriodFromDate(date);
163
199
  }
200
+
201
+ public isValidDate(dateString: string): boolean {
202
+ return this.dateManipulator.isValidDate(dateString);
203
+ }
204
+
205
+ public getSignDate(): string {
206
+ return this.dateManipulator.getSignDate();
207
+ }
164
208
  }
165
209
  const DisacompDateService = new DateService(new DateManipulator());
166
210
 
@@ -1 +1 @@
1
- {"program":{"fileNames":["../../../../../usr/local/lib/node_modules/typescript/lib/lib.es5.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2016.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.dom.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.scripthost.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.decorators.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.full.d.ts","./src/index.ts"],"fileInfos":[{"version":"f59215c5f1d886b05395ee7aca73e0ac69ddfad2843aa88530e797879d511bad","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","dc48272d7c333ccf58034c0026162576b7d50ea0e69c3b9292f803fc20720fd5","27147504487dc1159369da4f4da8a26406364624fa9bc3db632f7d94a5bae2c3",{"version":"3dda5344576193a4ae48b8d03f105c86f20b2f2aff0a1d1fd7935f5d68649654","affectsGlobalScope":true},{"version":"35299ae4a62086698444a5aaee27fc7aa377c68cbb90b441c9ace246ffd05c97","affectsGlobalScope":true},{"version":"c5c5565225fce2ede835725a92a28ece149f83542aa4866cfb10290bff7b8996","affectsGlobalScope":true},{"version":"7d2dbc2a0250400af0809b0ad5f84686e84c73526de931f84560e483eb16b03c","affectsGlobalScope":true},{"version":"9d9885c728913c1d16e0d2831b40341d6ad9a0ceecaabc55209b306ad9c736a5","affectsGlobalScope":true},{"version":"17bea081b9c0541f39dd1ae9bc8c78bdd561879a682e60e2f25f688c0ecab248","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"ab22100fdd0d24cfc2cc59d0a00fc8cf449830d9c4030dc54390a46bd562e929","affectsGlobalScope":true},{"version":"f7bd636ae3a4623c503359ada74510c4005df5b36de7f23e1db8a5c543fd176b","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"0c20f4d2358eb679e4ae8a4432bdd96c857a2960fd6800b21ec4008ec59d60ea","affectsGlobalScope":true},{"version":"36ae84ccc0633f7c0787bc6108386c8b773e95d3b052d9464a99cd9b8795fbec","affectsGlobalScope":true},{"version":"82d0d8e269b9eeac02c3bd1c9e884e85d483fcb2cd168bccd6bc54df663da031","affectsGlobalScope":true},{"version":"b8deab98702588840be73d67f02412a2d45a417a3c097b2e96f7f3a42ac483d1","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"376d554d042fb409cb55b5cbaf0b2b4b7e669619493c5d18d5fa8bd67273f82a","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"189c0703923150aa30673fa3de411346d727cc44a11c75d05d7cf9ef095daa22","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"994c234848afc14a2586b6565777f4c0b05dc479ede0a041bfd5becf6dceb586",{"version":"07831f807514afbc10818f997b7825969712b0bf110593845249abe17105d7bd","signature":"5163fa2cf70f01f0c3e09202f543d138f56675ec88cfdddd5566d45f89e8fadf"}],"root":[27],"options":{"composite":true,"module":1,"noImplicitAny":true,"noImplicitThis":true,"outDir":"./dist","removeComments":true,"rootDir":"./src","strict":true,"strictNullChecks":true,"target":4},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[27,24,25,5,6,10,9,2,11,12,13,14,15,16,17,18,3,4,26,22,19,20,21,23,1,8,7],"latestChangedDtsFile":"./dist/index.d.ts"},"version":"5.1.6"}
1
+ {"program":{"fileNames":["../../../../../usr/local/lib/node_modules/typescript/lib/lib.es5.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2016.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.dom.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.scripthost.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.decorators.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../../../usr/local/lib/node_modules/typescript/lib/lib.es2017.full.d.ts","./src/index.ts"],"fileInfos":[{"version":"f59215c5f1d886b05395ee7aca73e0ac69ddfad2843aa88530e797879d511bad","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","dc48272d7c333ccf58034c0026162576b7d50ea0e69c3b9292f803fc20720fd5","27147504487dc1159369da4f4da8a26406364624fa9bc3db632f7d94a5bae2c3",{"version":"3dda5344576193a4ae48b8d03f105c86f20b2f2aff0a1d1fd7935f5d68649654","affectsGlobalScope":true},{"version":"35299ae4a62086698444a5aaee27fc7aa377c68cbb90b441c9ace246ffd05c97","affectsGlobalScope":true},{"version":"c5c5565225fce2ede835725a92a28ece149f83542aa4866cfb10290bff7b8996","affectsGlobalScope":true},{"version":"7d2dbc2a0250400af0809b0ad5f84686e84c73526de931f84560e483eb16b03c","affectsGlobalScope":true},{"version":"9d9885c728913c1d16e0d2831b40341d6ad9a0ceecaabc55209b306ad9c736a5","affectsGlobalScope":true},{"version":"17bea081b9c0541f39dd1ae9bc8c78bdd561879a682e60e2f25f688c0ecab248","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"ab22100fdd0d24cfc2cc59d0a00fc8cf449830d9c4030dc54390a46bd562e929","affectsGlobalScope":true},{"version":"f7bd636ae3a4623c503359ada74510c4005df5b36de7f23e1db8a5c543fd176b","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"0c20f4d2358eb679e4ae8a4432bdd96c857a2960fd6800b21ec4008ec59d60ea","affectsGlobalScope":true},{"version":"36ae84ccc0633f7c0787bc6108386c8b773e95d3b052d9464a99cd9b8795fbec","affectsGlobalScope":true},{"version":"82d0d8e269b9eeac02c3bd1c9e884e85d483fcb2cd168bccd6bc54df663da031","affectsGlobalScope":true},{"version":"b8deab98702588840be73d67f02412a2d45a417a3c097b2e96f7f3a42ac483d1","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"376d554d042fb409cb55b5cbaf0b2b4b7e669619493c5d18d5fa8bd67273f82a","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"189c0703923150aa30673fa3de411346d727cc44a11c75d05d7cf9ef095daa22","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"994c234848afc14a2586b6565777f4c0b05dc479ede0a041bfd5becf6dceb586",{"version":"2f251c617e0156b2abac061de2eaf844c9d652cdf208ca54b219c9115358fb88","signature":"fd73947b1680f8406cf9726048519845f73ae98b68abbcd46728fb926fd5aadb"}],"root":[27],"options":{"composite":true,"module":1,"noImplicitAny":true,"noImplicitThis":true,"outDir":"./dist","removeComments":true,"rootDir":"./src","strict":true,"strictNullChecks":true,"target":4},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[27,24,25,5,6,10,9,2,11,12,13,14,15,16,17,18,3,4,26,22,19,20,21,23,1,8,7],"latestChangedDtsFile":"./dist/index.d.ts"},"version":"5.1.6"}