@eliasrrosa/tutorhub-public-assets 0.7.5 → 0.7.6
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.
|
@@ -6,7 +6,15 @@ export declare class ISO8601Date implements IDate {
|
|
|
6
6
|
/**Accepts YYYY-MM-DD date format. All other characters after this will be disconsidered.
|
|
7
7
|
* Disconsiders timezones.
|
|
8
8
|
*/
|
|
9
|
-
constructor(value?: string
|
|
9
|
+
constructor(value?: string | Date, opts?: {
|
|
10
|
+
/**
|
|
11
|
+
* If `value` is of type `Date`, set this to `true`
|
|
12
|
+
* so that hours, minutes and seconds are extracted
|
|
13
|
+
* considering UTC.
|
|
14
|
+
*/
|
|
15
|
+
useUtc?: boolean;
|
|
16
|
+
});
|
|
17
|
+
private normalizeValue;
|
|
10
18
|
private throwIfFormatIsNotValid;
|
|
11
19
|
getDay: () => string;
|
|
12
20
|
getMonth: () => string;
|
|
@@ -6,7 +6,7 @@ class ISO8601Date {
|
|
|
6
6
|
/**Accepts YYYY-MM-DD date format. All other characters after this will be disconsidered.
|
|
7
7
|
* Disconsiders timezones.
|
|
8
8
|
*/
|
|
9
|
-
constructor(value) {
|
|
9
|
+
constructor(value, opts) {
|
|
10
10
|
this.validator = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
11
11
|
this.getDay = () => {
|
|
12
12
|
this.throwIfFormatIsNotValid();
|
|
@@ -52,14 +52,21 @@ class ISO8601Date {
|
|
|
52
52
|
const targetDate = date || this;
|
|
53
53
|
return targetDate.toUtcJsDateTime().getUTCDay();
|
|
54
54
|
};
|
|
55
|
-
const normalizedValue = value
|
|
56
|
-
? this.validator.match(value)
|
|
57
|
-
: this.getToday();
|
|
55
|
+
const normalizedValue = this.normalizeValue(value, opts === null || opts === void 0 ? void 0 : opts.useUtc);
|
|
58
56
|
if (!normalizedValue)
|
|
59
57
|
throw new Error("Date format is invalid.");
|
|
60
58
|
this.value = normalizedValue;
|
|
61
59
|
this.throwIfFormatIsNotValid();
|
|
62
60
|
}
|
|
61
|
+
normalizeValue(value, useUtc) {
|
|
62
|
+
return typeof value == "string"
|
|
63
|
+
? this.validator.match(value)
|
|
64
|
+
: value instanceof Date
|
|
65
|
+
? this.jsDateTimeToDate(value, {
|
|
66
|
+
useUtc: useUtc,
|
|
67
|
+
}).value
|
|
68
|
+
: this.getToday();
|
|
69
|
+
}
|
|
63
70
|
throwIfFormatIsNotValid() {
|
|
64
71
|
if (!this.validator.formatIsValid(this.value)) {
|
|
65
72
|
throw new Error("Date format must be YYYY-MM-DD.");
|
|
@@ -38,6 +38,13 @@ describe("ISO8601Date", () => {
|
|
|
38
38
|
};
|
|
39
39
|
expect(validateFormat).not.toThrow();
|
|
40
40
|
});
|
|
41
|
+
it("Should be able to be constructed using js Date", () => {
|
|
42
|
+
const jsDate = new Date("2025-01-01T00:00:00Z");
|
|
43
|
+
const date = new ISO8601Date_1.ISO8601Date(jsDate, {
|
|
44
|
+
useUtc: true
|
|
45
|
+
});
|
|
46
|
+
expect(date.value).toEqual("2025-01-01");
|
|
47
|
+
});
|
|
41
48
|
});
|
|
42
49
|
describe("ISO8601Date.getDay()", () => {
|
|
43
50
|
it("Should return the day if format is valid.", () => {
|
package/dist/index.cjs
CHANGED
|
@@ -95,7 +95,7 @@ var _ISO8601Date = class _ISO8601Date {
|
|
|
95
95
|
/**Accepts YYYY-MM-DD date format. All other characters after this will be disconsidered.
|
|
96
96
|
* Disconsiders timezones.
|
|
97
97
|
*/
|
|
98
|
-
constructor(value) {
|
|
98
|
+
constructor(value, opts) {
|
|
99
99
|
this.validator = new ISO8601DateValidator();
|
|
100
100
|
this.getDay = () => {
|
|
101
101
|
this.throwIfFormatIsNotValid();
|
|
@@ -151,11 +151,16 @@ var _ISO8601Date = class _ISO8601Date {
|
|
|
151
151
|
const targetDate = date || this;
|
|
152
152
|
return targetDate.toUtcJsDateTime().getUTCDay();
|
|
153
153
|
};
|
|
154
|
-
const normalizedValue =
|
|
154
|
+
const normalizedValue = this.normalizeValue(value, opts == null ? void 0 : opts.useUtc);
|
|
155
155
|
if (!normalizedValue) throw new Error("Date format is invalid.");
|
|
156
156
|
this.value = normalizedValue;
|
|
157
157
|
this.throwIfFormatIsNotValid();
|
|
158
158
|
}
|
|
159
|
+
normalizeValue(value, useUtc) {
|
|
160
|
+
return typeof value == "string" ? this.validator.match(value) : value instanceof Date ? this.jsDateTimeToDate(value, {
|
|
161
|
+
useUtc
|
|
162
|
+
}).value : this.getToday();
|
|
163
|
+
}
|
|
159
164
|
throwIfFormatIsNotValid() {
|
|
160
165
|
if (!this.validator.formatIsValid(this.value)) {
|
|
161
166
|
throw new Error("Date format must be YYYY-MM-DD.");
|
package/dist/index.js
CHANGED
|
@@ -57,7 +57,7 @@ var _ISO8601Date = class _ISO8601Date {
|
|
|
57
57
|
/**Accepts YYYY-MM-DD date format. All other characters after this will be disconsidered.
|
|
58
58
|
* Disconsiders timezones.
|
|
59
59
|
*/
|
|
60
|
-
constructor(value) {
|
|
60
|
+
constructor(value, opts) {
|
|
61
61
|
this.validator = new ISO8601DateValidator();
|
|
62
62
|
this.getDay = () => {
|
|
63
63
|
this.throwIfFormatIsNotValid();
|
|
@@ -113,11 +113,16 @@ var _ISO8601Date = class _ISO8601Date {
|
|
|
113
113
|
const targetDate = date || this;
|
|
114
114
|
return targetDate.toUtcJsDateTime().getUTCDay();
|
|
115
115
|
};
|
|
116
|
-
const normalizedValue =
|
|
116
|
+
const normalizedValue = this.normalizeValue(value, opts == null ? void 0 : opts.useUtc);
|
|
117
117
|
if (!normalizedValue) throw new Error("Date format is invalid.");
|
|
118
118
|
this.value = normalizedValue;
|
|
119
119
|
this.throwIfFormatIsNotValid();
|
|
120
120
|
}
|
|
121
|
+
normalizeValue(value, useUtc) {
|
|
122
|
+
return typeof value == "string" ? this.validator.match(value) : value instanceof Date ? this.jsDateTimeToDate(value, {
|
|
123
|
+
useUtc
|
|
124
|
+
}).value : this.getToday();
|
|
125
|
+
}
|
|
121
126
|
throwIfFormatIsNotValid() {
|
|
122
127
|
if (!this.validator.formatIsValid(this.value)) {
|
|
123
128
|
throw new Error("Date format must be YYYY-MM-DD.");
|