disacomp-dateservice 1.0.1 → 1.0.2
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/package.json +1 -1
- package/src/index.ts +11 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -43,6 +43,7 @@ interface IDateManipulator {
|
|
|
43
43
|
getPeriodFromDate(date: string): string;
|
|
44
44
|
isValidDate(date: string): boolean;
|
|
45
45
|
getSignDate(): string;
|
|
46
|
+
getISODateStringFromString(date: string): string;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
// Helper class to handle leap years and days in months
|
|
@@ -168,6 +169,12 @@ class DateManipulator implements IDateManipulator {
|
|
|
168
169
|
|
|
169
170
|
return `${day}-${month}-${year} ${hours}:${min}:${sec}`;
|
|
170
171
|
}
|
|
172
|
+
|
|
173
|
+
public getISODateStringFromString(date: string): string {
|
|
174
|
+
const [day, month, year] = date.split("-").map(Number);
|
|
175
|
+
|
|
176
|
+
return `${year}-${this.addCeroAtBegin(month)}-${this.addCeroAtBegin(day)}`; // Formato ISO YYYY-MM-DD
|
|
177
|
+
}
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
// Client code using dependency inversion
|
|
@@ -205,6 +212,10 @@ class DateService {
|
|
|
205
212
|
public getSignDate(): string {
|
|
206
213
|
return this.dateManipulator.getSignDate();
|
|
207
214
|
}
|
|
215
|
+
|
|
216
|
+
public getISODateStringFromString(date: string): string {
|
|
217
|
+
return this.dateManipulator.getISODateStringFromString(date);
|
|
218
|
+
}
|
|
208
219
|
}
|
|
209
220
|
const DisacompDateService = new DateService(new DateManipulator());
|
|
210
221
|
|