@eliasrrosa/tutorhub-public-assets 0.9.0 → 0.9.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.
|
@@ -15,6 +15,17 @@ export interface IDateTime {
|
|
|
15
15
|
getMinutesString: () => string;
|
|
16
16
|
getSecondsString: () => string;
|
|
17
17
|
getMilisecondsString: () => string;
|
|
18
|
+
/**
|
|
19
|
+
* @returns only the date like YYYY-MM-DD
|
|
20
|
+
*/
|
|
21
|
+
getDateString: () => string;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @returns the day of the month like DD
|
|
25
|
+
*/
|
|
26
|
+
getDayString: () => string;
|
|
27
|
+
getMonthString: () => string;
|
|
28
|
+
getYearString: () => string;
|
|
18
29
|
}
|
|
19
30
|
export declare class ISO8601DateTime implements IDateTime {
|
|
20
31
|
private readonly timeFormatValidator;
|
|
@@ -41,4 +52,8 @@ export declare class ISO8601DateTime implements IDateTime {
|
|
|
41
52
|
timezone?: string | number;
|
|
42
53
|
}) => string;
|
|
43
54
|
toMidnight: () => IDateTime;
|
|
55
|
+
getDateString: () => string;
|
|
56
|
+
getDayString: () => string;
|
|
57
|
+
getMonthString: () => string;
|
|
58
|
+
getYearString: () => string;
|
|
44
59
|
}
|
|
@@ -65,6 +65,18 @@ class ISO8601DateTime {
|
|
|
65
65
|
const timezone = this.dateString.slice(matchedString.length + matches.index);
|
|
66
66
|
return new ISO8601DateTime(`${datePlusT}00:00:00${timezone}`);
|
|
67
67
|
};
|
|
68
|
+
this.getDateString = () => {
|
|
69
|
+
return `${this.getYearString()}-${this.getMonthString()}-${this.getDayString()}`;
|
|
70
|
+
};
|
|
71
|
+
this.getDayString = () => {
|
|
72
|
+
return this.dateString.split("T")[0].split("-")[2];
|
|
73
|
+
};
|
|
74
|
+
this.getMonthString = () => {
|
|
75
|
+
return this.dateString.split("T")[0].split("-")[1];
|
|
76
|
+
};
|
|
77
|
+
this.getYearString = () => {
|
|
78
|
+
return this.dateString.split("T")[0].split("-")[0];
|
|
79
|
+
};
|
|
68
80
|
const normalizedDateString = this.normalizeDateString(dateString);
|
|
69
81
|
if (!normalizedDateString)
|
|
70
82
|
throw new Error("Date time format invalid.");
|
|
@@ -56,9 +56,27 @@ describe("ISO8601DateTime", () => {
|
|
|
56
56
|
});
|
|
57
57
|
describe("ISO8601DateTime.toMidnight().getIsoString()", () => {
|
|
58
58
|
it("Must take UTC ISO string and return it midnight", () => {
|
|
59
|
-
expect(new ISO8601DateTime_1.ISO8601DateTime("2025-01-01T03:00:00Z")
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
expect(new ISO8601DateTime_1.ISO8601DateTime("2025-01-01T03:00:00Z").toMidnight().getIsoString()).toEqual("2025-01-01T00:00:00.000Z");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe("ISO8601DateTime.getDay()", () => {
|
|
63
|
+
it("Should return the day if format is valid.", () => {
|
|
64
|
+
const date = new ISO8601DateTime_1.ISO8601DateTime("2025-01-02");
|
|
65
|
+
expect(date.getDayString()).toBe("02");
|
|
66
|
+
const date2 = new ISO8601DateTime_1.ISO8601DateTime("2025-01-02T15:00:00-03:00");
|
|
67
|
+
expect(date2.getDayString()).toBe("02");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe("ISO8601DateTime.getMonth()", () => {
|
|
71
|
+
it("Should return the month if format is valid.", () => {
|
|
72
|
+
const date = new ISO8601DateTime_1.ISO8601DateTime("2025-01-02");
|
|
73
|
+
expect(date.getMonthString()).toBe("01");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe("ISO8601DateTime.getYear()", () => {
|
|
77
|
+
it("Should return the year if format is valid.", () => {
|
|
78
|
+
const date = new ISO8601DateTime_1.ISO8601DateTime("2025-01-02");
|
|
79
|
+
expect(date.getYearString()).toBe("2025");
|
|
62
80
|
});
|
|
63
81
|
});
|
|
64
82
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -416,12 +416,27 @@ var ISO8601DateTime = class _ISO8601DateTime {
|
|
|
416
416
|
this.toMidnight = () => {
|
|
417
417
|
const currentTimeString = this.getTimeString();
|
|
418
418
|
const matches = new RegExp(currentTimeString).exec(this.dateString);
|
|
419
|
-
if (!matches || matches.length < 1)
|
|
419
|
+
if (!matches || matches.length < 1)
|
|
420
|
+
throw new Error("Error getting current time string.");
|
|
420
421
|
const datePlusT = this.dateString.slice(0, matches.index);
|
|
421
422
|
const matchedString = matches[0];
|
|
422
|
-
const timezone = this.dateString.slice(
|
|
423
|
+
const timezone = this.dateString.slice(
|
|
424
|
+
matchedString.length + matches.index
|
|
425
|
+
);
|
|
423
426
|
return new _ISO8601DateTime(`${datePlusT}00:00:00${timezone}`);
|
|
424
427
|
};
|
|
428
|
+
this.getDateString = () => {
|
|
429
|
+
return `${this.getYearString()}-${this.getMonthString()}-${this.getDayString()}`;
|
|
430
|
+
};
|
|
431
|
+
this.getDayString = () => {
|
|
432
|
+
return this.dateString.split("T")[0].split("-")[2];
|
|
433
|
+
};
|
|
434
|
+
this.getMonthString = () => {
|
|
435
|
+
return this.dateString.split("T")[0].split("-")[1];
|
|
436
|
+
};
|
|
437
|
+
this.getYearString = () => {
|
|
438
|
+
return this.dateString.split("T")[0].split("-")[0];
|
|
439
|
+
};
|
|
425
440
|
const normalizedDateString = this.normalizeDateString(dateString);
|
|
426
441
|
if (!normalizedDateString) throw new Error("Date time format invalid.");
|
|
427
442
|
this.dateString = normalizedDateString;
|
package/dist/index.js
CHANGED
|
@@ -380,12 +380,27 @@ var ISO8601DateTime = class _ISO8601DateTime {
|
|
|
380
380
|
this.toMidnight = () => {
|
|
381
381
|
const currentTimeString = this.getTimeString();
|
|
382
382
|
const matches = new RegExp(currentTimeString).exec(this.dateString);
|
|
383
|
-
if (!matches || matches.length < 1)
|
|
383
|
+
if (!matches || matches.length < 1)
|
|
384
|
+
throw new Error("Error getting current time string.");
|
|
384
385
|
const datePlusT = this.dateString.slice(0, matches.index);
|
|
385
386
|
const matchedString = matches[0];
|
|
386
|
-
const timezone = this.dateString.slice(
|
|
387
|
+
const timezone = this.dateString.slice(
|
|
388
|
+
matchedString.length + matches.index
|
|
389
|
+
);
|
|
387
390
|
return new _ISO8601DateTime(`${datePlusT}00:00:00${timezone}`);
|
|
388
391
|
};
|
|
392
|
+
this.getDateString = () => {
|
|
393
|
+
return `${this.getYearString()}-${this.getMonthString()}-${this.getDayString()}`;
|
|
394
|
+
};
|
|
395
|
+
this.getDayString = () => {
|
|
396
|
+
return this.dateString.split("T")[0].split("-")[2];
|
|
397
|
+
};
|
|
398
|
+
this.getMonthString = () => {
|
|
399
|
+
return this.dateString.split("T")[0].split("-")[1];
|
|
400
|
+
};
|
|
401
|
+
this.getYearString = () => {
|
|
402
|
+
return this.dateString.split("T")[0].split("-")[0];
|
|
403
|
+
};
|
|
389
404
|
const normalizedDateString = this.normalizeDateString(dateString);
|
|
390
405
|
if (!normalizedDateString) throw new Error("Date time format invalid.");
|
|
391
406
|
this.dateString = normalizedDateString;
|