@eliasrrosa/tutorhub-public-assets 0.7.3 → 0.7.5
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.
|
@@ -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
|
@@ -436,15 +436,16 @@ var ISO8601TimezoneConverter = class {
|
|
|
436
436
|
};
|
|
437
437
|
|
|
438
438
|
// src/domain/entities/ISO8601Time.ts
|
|
439
|
-
var
|
|
439
|
+
var _ISO8601Time = class _ISO8601Time {
|
|
440
440
|
/**
|
|
441
441
|
* Throws if format is invalid.
|
|
442
442
|
* Accepted formats: HH:MM:SS, HH:MM, HH:MM:SS(+|-)HH:MM, HH:MM:SS.sssZ and HH:MM:SSZ.
|
|
443
443
|
*/
|
|
444
|
-
constructor(value) {
|
|
444
|
+
constructor(value, opts) {
|
|
445
445
|
this.timeValidator = new ISO8601TimeValidator();
|
|
446
446
|
this.timezoneConverter = new ISO8601TimezoneConverter();
|
|
447
447
|
this.timezoneParser = new ISO8601TimezoneParser();
|
|
448
|
+
this.fromJsDateTime = _ISO8601Time.fromJsDateTime;
|
|
448
449
|
this.getNowTimeString = _ISO8601Time.getNow;
|
|
449
450
|
this.getTimezone = () => {
|
|
450
451
|
return new ISO8601Timezone(this.originalTimeString);
|
|
@@ -486,9 +487,14 @@ var ISO8601Time = class _ISO8601Time {
|
|
|
486
487
|
`${this.getHoursString()}:${this.getMinutesString()}:${this.getSecondsString()}${newTimezone}`
|
|
487
488
|
);
|
|
488
489
|
};
|
|
489
|
-
this.originalTimeString = value ?
|
|
490
|
+
this.originalTimeString = this.normalizeValue(value, opts == null ? void 0 : opts.useUtc);
|
|
490
491
|
this.validateFormatOrThrow();
|
|
491
492
|
}
|
|
493
|
+
normalizeValue(value, useUtc) {
|
|
494
|
+
return value == void 0 ? this.getNowTimeString() : typeof value == "string" ? value : this.fromJsDateTime(value, {
|
|
495
|
+
useUtc
|
|
496
|
+
});
|
|
497
|
+
}
|
|
492
498
|
validateFormatOrThrow() {
|
|
493
499
|
if (!this.timeValidator.formatIsValid(this.originalTimeString))
|
|
494
500
|
throw new Error("Time format must be ISO8601.");
|
|
@@ -538,6 +544,20 @@ var ISO8601Time = class _ISO8601Time {
|
|
|
538
544
|
);
|
|
539
545
|
}
|
|
540
546
|
};
|
|
547
|
+
/**
|
|
548
|
+
* Returns a string like HH:MM:SS from a js Date
|
|
549
|
+
*/
|
|
550
|
+
_ISO8601Time.fromJsDateTime = (dateTime, opts) => {
|
|
551
|
+
const toStringAndPadStart = (x) => x.toString().padStart(2, "0");
|
|
552
|
+
const hours = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCHours() : dateTime.getHours();
|
|
553
|
+
const hoursString = toStringAndPadStart(hours);
|
|
554
|
+
const minutes = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCMinutes() : dateTime.getMinutes();
|
|
555
|
+
const minutesString = toStringAndPadStart(minutes);
|
|
556
|
+
const seconds = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCSeconds() : dateTime.getSeconds();
|
|
557
|
+
const secondsString = toStringAndPadStart(seconds);
|
|
558
|
+
return `${hoursString}:${minutesString}:${secondsString}`;
|
|
559
|
+
};
|
|
560
|
+
var ISO8601Time = _ISO8601Time;
|
|
541
561
|
|
|
542
562
|
// src/infrastructure/restful/requests/forms/ClassCreationForm.ts
|
|
543
563
|
var import_zod2 = require("zod");
|
package/dist/index.js
CHANGED
|
@@ -398,15 +398,16 @@ var ISO8601TimezoneConverter = class {
|
|
|
398
398
|
};
|
|
399
399
|
|
|
400
400
|
// src/domain/entities/ISO8601Time.ts
|
|
401
|
-
var
|
|
401
|
+
var _ISO8601Time = class _ISO8601Time {
|
|
402
402
|
/**
|
|
403
403
|
* Throws if format is invalid.
|
|
404
404
|
* Accepted formats: HH:MM:SS, HH:MM, HH:MM:SS(+|-)HH:MM, HH:MM:SS.sssZ and HH:MM:SSZ.
|
|
405
405
|
*/
|
|
406
|
-
constructor(value) {
|
|
406
|
+
constructor(value, opts) {
|
|
407
407
|
this.timeValidator = new ISO8601TimeValidator();
|
|
408
408
|
this.timezoneConverter = new ISO8601TimezoneConverter();
|
|
409
409
|
this.timezoneParser = new ISO8601TimezoneParser();
|
|
410
|
+
this.fromJsDateTime = _ISO8601Time.fromJsDateTime;
|
|
410
411
|
this.getNowTimeString = _ISO8601Time.getNow;
|
|
411
412
|
this.getTimezone = () => {
|
|
412
413
|
return new ISO8601Timezone(this.originalTimeString);
|
|
@@ -448,9 +449,14 @@ var ISO8601Time = class _ISO8601Time {
|
|
|
448
449
|
`${this.getHoursString()}:${this.getMinutesString()}:${this.getSecondsString()}${newTimezone}`
|
|
449
450
|
);
|
|
450
451
|
};
|
|
451
|
-
this.originalTimeString = value ?
|
|
452
|
+
this.originalTimeString = this.normalizeValue(value, opts == null ? void 0 : opts.useUtc);
|
|
452
453
|
this.validateFormatOrThrow();
|
|
453
454
|
}
|
|
455
|
+
normalizeValue(value, useUtc) {
|
|
456
|
+
return value == void 0 ? this.getNowTimeString() : typeof value == "string" ? value : this.fromJsDateTime(value, {
|
|
457
|
+
useUtc
|
|
458
|
+
});
|
|
459
|
+
}
|
|
454
460
|
validateFormatOrThrow() {
|
|
455
461
|
if (!this.timeValidator.formatIsValid(this.originalTimeString))
|
|
456
462
|
throw new Error("Time format must be ISO8601.");
|
|
@@ -500,6 +506,20 @@ var ISO8601Time = class _ISO8601Time {
|
|
|
500
506
|
);
|
|
501
507
|
}
|
|
502
508
|
};
|
|
509
|
+
/**
|
|
510
|
+
* Returns a string like HH:MM:SS from a js Date
|
|
511
|
+
*/
|
|
512
|
+
_ISO8601Time.fromJsDateTime = (dateTime, opts) => {
|
|
513
|
+
const toStringAndPadStart = (x) => x.toString().padStart(2, "0");
|
|
514
|
+
const hours = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCHours() : dateTime.getHours();
|
|
515
|
+
const hoursString = toStringAndPadStart(hours);
|
|
516
|
+
const minutes = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCMinutes() : dateTime.getMinutes();
|
|
517
|
+
const minutesString = toStringAndPadStart(minutes);
|
|
518
|
+
const seconds = (opts == null ? void 0 : opts.useUtc) ? dateTime.getUTCSeconds() : dateTime.getSeconds();
|
|
519
|
+
const secondsString = toStringAndPadStart(seconds);
|
|
520
|
+
return `${hoursString}:${minutesString}:${secondsString}`;
|
|
521
|
+
};
|
|
522
|
+
var ISO8601Time = _ISO8601Time;
|
|
503
523
|
|
|
504
524
|
// src/infrastructure/restful/requests/forms/ClassCreationForm.ts
|
|
505
525
|
import { z as z2 } from "zod";
|