@eliasrrosa/tutorhub-public-assets 0.7.4 → 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.
- package/dist/domain/entities/ISO8601Date.d.ts +9 -1
- package/dist/domain/entities/ISO8601Date.js +11 -4
- package/dist/domain/entities/ISO8601Date.test.js +7 -0
- package/dist/domain/entities/ISO8601Time.d.ts +26 -1
- package/dist/domain/entities/ISO8601Time.js +29 -2
- package/dist/domain/entities/ISO8601Time.test.js +15 -0
- package/dist/index.cjs +30 -5
- package/dist/index.js +30 -5
- package/package.json +1 -1
|
@@ -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.", () => {
|
|
@@ -19,7 +19,32 @@ export declare class ISO8601Time implements ITime {
|
|
|
19
19
|
* Throws if format is invalid.
|
|
20
20
|
* Accepted formats: HH:MM:SS, HH:MM, HH:MM:SS(+|-)HH:MM, HH:MM:SS.sssZ and HH:MM:SSZ.
|
|
21
21
|
*/
|
|
22
|
-
constructor(value?: string
|
|
22
|
+
constructor(value?: string | Date, opts?: {
|
|
23
|
+
/**
|
|
24
|
+
* If `value` is of type `Date`, set this to `true`
|
|
25
|
+
* so that hours, minutes and seconds are extracted
|
|
26
|
+
* considering UTC.
|
|
27
|
+
*/
|
|
28
|
+
useUtc?: boolean;
|
|
29
|
+
});
|
|
30
|
+
private normalizeValue;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a string like HH:MM:SS from a js Date
|
|
33
|
+
*/
|
|
34
|
+
static fromJsDateTime: (dateTime: Date, opts?: {
|
|
35
|
+
/**
|
|
36
|
+
* Set this to `true` so that hours, minutes and seconds are extracted
|
|
37
|
+
* considering UTC.
|
|
38
|
+
*/
|
|
39
|
+
useUtc?: boolean;
|
|
40
|
+
}) => string;
|
|
41
|
+
fromJsDateTime: (dateTime: Date, opts?: {
|
|
42
|
+
/**
|
|
43
|
+
* Set this to `true` so that hours, minutes and seconds are extracted
|
|
44
|
+
* considering UTC.
|
|
45
|
+
*/
|
|
46
|
+
useUtc?: boolean;
|
|
47
|
+
}) => string;
|
|
23
48
|
private validateFormatOrThrow;
|
|
24
49
|
getTimeString(opts?: {
|
|
25
50
|
format?: "HH:MM" | "HH:MM:SS" | "HH:MM:SS(+|-)HH:MM";
|
|
@@ -17,10 +17,11 @@ class ISO8601Time {
|
|
|
17
17
|
* Throws if format is invalid.
|
|
18
18
|
* Accepted formats: HH:MM:SS, HH:MM, HH:MM:SS(+|-)HH:MM, HH:MM:SS.sssZ and HH:MM:SSZ.
|
|
19
19
|
*/
|
|
20
|
-
constructor(value) {
|
|
20
|
+
constructor(value, opts) {
|
|
21
21
|
this.timeValidator = new ISO8601TimeValidator_1.ISO8601TimeValidator();
|
|
22
22
|
this.timezoneConverter = new ISO8601TimezoneConverter_1.ISO8601TimezoneConverter();
|
|
23
23
|
this.timezoneParser = new ISO8601TimezoneParser_1.ISO8601TimezoneParser();
|
|
24
|
+
this.fromJsDateTime = ISO8601Time.fromJsDateTime;
|
|
24
25
|
this.getNowTimeString = ISO8601Time.getNow;
|
|
25
26
|
this.getTimezone = () => {
|
|
26
27
|
return new ISO8601Timezone_1.ISO8601Timezone(this.originalTimeString);
|
|
@@ -60,9 +61,18 @@ class ISO8601Time {
|
|
|
60
61
|
: timezone;
|
|
61
62
|
return new ISO8601Time(`${this.getHoursString()}:${this.getMinutesString()}:${this.getSecondsString()}${newTimezone}`);
|
|
62
63
|
};
|
|
63
|
-
this.originalTimeString = value ?
|
|
64
|
+
this.originalTimeString = this.normalizeValue(value, opts === null || opts === void 0 ? void 0 : opts.useUtc);
|
|
64
65
|
this.validateFormatOrThrow();
|
|
65
66
|
}
|
|
67
|
+
normalizeValue(value, useUtc) {
|
|
68
|
+
return value == undefined
|
|
69
|
+
? this.getNowTimeString()
|
|
70
|
+
: typeof value == "string"
|
|
71
|
+
? value
|
|
72
|
+
: this.fromJsDateTime(value, {
|
|
73
|
+
useUtc: useUtc,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
66
76
|
validateFormatOrThrow() {
|
|
67
77
|
if (!this.timeValidator.formatIsValid(this.originalTimeString))
|
|
68
78
|
throw new Error("Time format must be ISO8601.");
|
|
@@ -110,3 +120,20 @@ class ISO8601Time {
|
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
exports.ISO8601Time = ISO8601Time;
|
|
123
|
+
/**
|
|
124
|
+
* Returns a string like HH:MM:SS from a js Date
|
|
125
|
+
*/
|
|
126
|
+
ISO8601Time.fromJsDateTime = (dateTime, opts) => {
|
|
127
|
+
const toStringAndPadStart = (x) => x.toString().padStart(2, "0");
|
|
128
|
+
const hours = (opts === null || opts === void 0 ? void 0 : opts.useUtc) ? dateTime.getUTCHours() : dateTime.getHours();
|
|
129
|
+
const hoursString = toStringAndPadStart(hours);
|
|
130
|
+
const minutes = (opts === null || opts === void 0 ? void 0 : opts.useUtc)
|
|
131
|
+
? dateTime.getUTCMinutes()
|
|
132
|
+
: dateTime.getMinutes();
|
|
133
|
+
const minutesString = toStringAndPadStart(minutes);
|
|
134
|
+
const seconds = (opts === null || opts === void 0 ? void 0 : opts.useUtc)
|
|
135
|
+
? dateTime.getUTCSeconds()
|
|
136
|
+
: dateTime.getSeconds();
|
|
137
|
+
const secondsString = toStringAndPadStart(seconds);
|
|
138
|
+
return `${hoursString}:${minutesString}:${secondsString}`;
|
|
139
|
+
};
|
|
@@ -233,4 +233,19 @@ describe("ISO8601Time", () => {
|
|
|
233
233
|
expect(time.getTimeInMinutes()).toEqual(90);
|
|
234
234
|
});
|
|
235
235
|
});
|
|
236
|
+
describe("ISO8601Time.fromJsDateTime()", () => {
|
|
237
|
+
afterEach(() => jest.useRealTimers());
|
|
238
|
+
it("Should return the expected time according to local time", () => {
|
|
239
|
+
jest.useFakeTimers().setSystemTime(new Date("2025-01-01T12:00:00-03:00"));
|
|
240
|
+
const dateTime = new Date("2025-01-01T12:00:00-03:00");
|
|
241
|
+
const time = ISO8601Time_1.ISO8601Time.fromJsDateTime(dateTime);
|
|
242
|
+
expect(time).toEqual("12:00:00");
|
|
243
|
+
});
|
|
244
|
+
it("Should return the expected time according to utc given parameter", () => {
|
|
245
|
+
jest.useFakeTimers().setSystemTime(new Date("2025-01-01T12:00:00-03:00"));
|
|
246
|
+
const dateTime = new Date("2025-01-01T12:00:00Z");
|
|
247
|
+
const time = ISO8601Time_1.ISO8601Time.fromJsDateTime(dateTime, { useUtc: true });
|
|
248
|
+
expect(time).toEqual("12:00:00");
|
|
249
|
+
});
|
|
250
|
+
});
|
|
236
251
|
});
|
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.");
|
|
@@ -436,15 +441,16 @@ var ISO8601TimezoneConverter = class {
|
|
|
436
441
|
};
|
|
437
442
|
|
|
438
443
|
// src/domain/entities/ISO8601Time.ts
|
|
439
|
-
var
|
|
444
|
+
var _ISO8601Time = class _ISO8601Time {
|
|
440
445
|
/**
|
|
441
446
|
* Throws if format is invalid.
|
|
442
447
|
* Accepted formats: HH:MM:SS, HH:MM, HH:MM:SS(+|-)HH:MM, HH:MM:SS.sssZ and HH:MM:SSZ.
|
|
443
448
|
*/
|
|
444
|
-
constructor(value) {
|
|
449
|
+
constructor(value, opts) {
|
|
445
450
|
this.timeValidator = new ISO8601TimeValidator();
|
|
446
451
|
this.timezoneConverter = new ISO8601TimezoneConverter();
|
|
447
452
|
this.timezoneParser = new ISO8601TimezoneParser();
|
|
453
|
+
this.fromJsDateTime = _ISO8601Time.fromJsDateTime;
|
|
448
454
|
this.getNowTimeString = _ISO8601Time.getNow;
|
|
449
455
|
this.getTimezone = () => {
|
|
450
456
|
return new ISO8601Timezone(this.originalTimeString);
|
|
@@ -486,9 +492,14 @@ var ISO8601Time = class _ISO8601Time {
|
|
|
486
492
|
`${this.getHoursString()}:${this.getMinutesString()}:${this.getSecondsString()}${newTimezone}`
|
|
487
493
|
);
|
|
488
494
|
};
|
|
489
|
-
this.originalTimeString = value ?
|
|
495
|
+
this.originalTimeString = this.normalizeValue(value, opts == null ? void 0 : opts.useUtc);
|
|
490
496
|
this.validateFormatOrThrow();
|
|
491
497
|
}
|
|
498
|
+
normalizeValue(value, useUtc) {
|
|
499
|
+
return value == void 0 ? this.getNowTimeString() : typeof value == "string" ? value : this.fromJsDateTime(value, {
|
|
500
|
+
useUtc
|
|
501
|
+
});
|
|
502
|
+
}
|
|
492
503
|
validateFormatOrThrow() {
|
|
493
504
|
if (!this.timeValidator.formatIsValid(this.originalTimeString))
|
|
494
505
|
throw new Error("Time format must be ISO8601.");
|
|
@@ -538,6 +549,20 @@ var ISO8601Time = class _ISO8601Time {
|
|
|
538
549
|
);
|
|
539
550
|
}
|
|
540
551
|
};
|
|
552
|
+
/**
|
|
553
|
+
* Returns a string like HH:MM:SS from a js Date
|
|
554
|
+
*/
|
|
555
|
+
_ISO8601Time.fromJsDateTime = (dateTime, opts) => {
|
|
556
|
+
const toStringAndPadStart = (x) => x.toString().padStart(2, "0");
|
|
557
|
+
const hours = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCHours() : dateTime.getHours();
|
|
558
|
+
const hoursString = toStringAndPadStart(hours);
|
|
559
|
+
const minutes = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCMinutes() : dateTime.getMinutes();
|
|
560
|
+
const minutesString = toStringAndPadStart(minutes);
|
|
561
|
+
const seconds = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCSeconds() : dateTime.getSeconds();
|
|
562
|
+
const secondsString = toStringAndPadStart(seconds);
|
|
563
|
+
return `${hoursString}:${minutesString}:${secondsString}`;
|
|
564
|
+
};
|
|
565
|
+
var ISO8601Time = _ISO8601Time;
|
|
541
566
|
|
|
542
567
|
// src/infrastructure/restful/requests/forms/ClassCreationForm.ts
|
|
543
568
|
var import_zod2 = require("zod");
|
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.");
|
|
@@ -398,15 +403,16 @@ var ISO8601TimezoneConverter = class {
|
|
|
398
403
|
};
|
|
399
404
|
|
|
400
405
|
// src/domain/entities/ISO8601Time.ts
|
|
401
|
-
var
|
|
406
|
+
var _ISO8601Time = class _ISO8601Time {
|
|
402
407
|
/**
|
|
403
408
|
* Throws if format is invalid.
|
|
404
409
|
* Accepted formats: HH:MM:SS, HH:MM, HH:MM:SS(+|-)HH:MM, HH:MM:SS.sssZ and HH:MM:SSZ.
|
|
405
410
|
*/
|
|
406
|
-
constructor(value) {
|
|
411
|
+
constructor(value, opts) {
|
|
407
412
|
this.timeValidator = new ISO8601TimeValidator();
|
|
408
413
|
this.timezoneConverter = new ISO8601TimezoneConverter();
|
|
409
414
|
this.timezoneParser = new ISO8601TimezoneParser();
|
|
415
|
+
this.fromJsDateTime = _ISO8601Time.fromJsDateTime;
|
|
410
416
|
this.getNowTimeString = _ISO8601Time.getNow;
|
|
411
417
|
this.getTimezone = () => {
|
|
412
418
|
return new ISO8601Timezone(this.originalTimeString);
|
|
@@ -448,9 +454,14 @@ var ISO8601Time = class _ISO8601Time {
|
|
|
448
454
|
`${this.getHoursString()}:${this.getMinutesString()}:${this.getSecondsString()}${newTimezone}`
|
|
449
455
|
);
|
|
450
456
|
};
|
|
451
|
-
this.originalTimeString = value ?
|
|
457
|
+
this.originalTimeString = this.normalizeValue(value, opts == null ? void 0 : opts.useUtc);
|
|
452
458
|
this.validateFormatOrThrow();
|
|
453
459
|
}
|
|
460
|
+
normalizeValue(value, useUtc) {
|
|
461
|
+
return value == void 0 ? this.getNowTimeString() : typeof value == "string" ? value : this.fromJsDateTime(value, {
|
|
462
|
+
useUtc
|
|
463
|
+
});
|
|
464
|
+
}
|
|
454
465
|
validateFormatOrThrow() {
|
|
455
466
|
if (!this.timeValidator.formatIsValid(this.originalTimeString))
|
|
456
467
|
throw new Error("Time format must be ISO8601.");
|
|
@@ -500,6 +511,20 @@ var ISO8601Time = class _ISO8601Time {
|
|
|
500
511
|
);
|
|
501
512
|
}
|
|
502
513
|
};
|
|
514
|
+
/**
|
|
515
|
+
* Returns a string like HH:MM:SS from a js Date
|
|
516
|
+
*/
|
|
517
|
+
_ISO8601Time.fromJsDateTime = (dateTime, opts) => {
|
|
518
|
+
const toStringAndPadStart = (x) => x.toString().padStart(2, "0");
|
|
519
|
+
const hours = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCHours() : dateTime.getHours();
|
|
520
|
+
const hoursString = toStringAndPadStart(hours);
|
|
521
|
+
const minutes = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCMinutes() : dateTime.getMinutes();
|
|
522
|
+
const minutesString = toStringAndPadStart(minutes);
|
|
523
|
+
const seconds = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCSeconds() : dateTime.getSeconds();
|
|
524
|
+
const secondsString = toStringAndPadStart(seconds);
|
|
525
|
+
return `${hoursString}:${minutesString}:${secondsString}`;
|
|
526
|
+
};
|
|
527
|
+
var ISO8601Time = _ISO8601Time;
|
|
503
528
|
|
|
504
529
|
// src/infrastructure/restful/requests/forms/ClassCreationForm.ts
|
|
505
530
|
import { z as z2 } from "zod";
|