@eliasrrosa/tutorhub-public-assets 0.0.8 → 0.0.9
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/ISO8601Time.d.ts +2 -1
- package/dist/domain/entities/ISO8601Time.js +1 -1
- package/dist/domain/entities/ISO8601Time.test.js +40 -0
- package/dist/domain/entities/ISO8601TimeValidator.d.ts +14 -1
- package/dist/domain/entities/ISO8601TimeValidator.js +21 -3
- package/dist/domain/entities/ISO8601TimeValidator.test.js +15 -3
- package/dist/domain/entities/Time.d.ts +1 -0
- package/dist/index.cjs +22 -4
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { IISO8601TimeValidator } from "./ISO8601TimeValidator";
|
|
|
2
2
|
import { ITime } from "./Time";
|
|
3
3
|
/**
|
|
4
4
|
* Interface for interacting with ISO8601 time formats.
|
|
5
|
-
* Accepted formats: HH:MM:SS and HH:MM.
|
|
5
|
+
* Accepted formats: HH:MM:SS, HH:MM, HH:MM:SSZ, HH:MM:SS.sssZ and HH:MM:SS(+|-)HH:MM.
|
|
6
6
|
*
|
|
7
7
|
* @throws if instantiated with a different format
|
|
8
8
|
* @throws if any method is called with a different format
|
|
@@ -10,6 +10,7 @@ import { ITime } from "./Time";
|
|
|
10
10
|
export declare class ISO8601Time implements ITime {
|
|
11
11
|
readonly value: string;
|
|
12
12
|
readonly validator: IISO8601TimeValidator;
|
|
13
|
+
readonly timezone?: string;
|
|
13
14
|
/**
|
|
14
15
|
* Throws if format is invalid.
|
|
15
16
|
* Accepted formats: HH:MM:SS and HH:MM.
|
|
@@ -4,7 +4,7 @@ exports.ISO8601Time = void 0;
|
|
|
4
4
|
const ISO8601TimeValidator_1 = require("./ISO8601TimeValidator");
|
|
5
5
|
/**
|
|
6
6
|
* Interface for interacting with ISO8601 time formats.
|
|
7
|
-
* Accepted formats: HH:MM:SS and HH:MM.
|
|
7
|
+
* Accepted formats: HH:MM:SS, HH:MM, HH:MM:SSZ, HH:MM:SS.sssZ and HH:MM:SS(+|-)HH:MM.
|
|
8
8
|
*
|
|
9
9
|
* @throws if instantiated with a different format
|
|
10
10
|
* @throws if any method is called with a different format
|
|
@@ -20,6 +20,46 @@ describe("ISO8601Time", () => {
|
|
|
20
20
|
const time = new ISO8601Time_1.ISO8601Time();
|
|
21
21
|
expect(time.value).toBe("23:00:00");
|
|
22
22
|
});
|
|
23
|
+
it("Should throw given irregular time format", () => {
|
|
24
|
+
const time = () => new ISO8601Time_1.ISO8601Time("000:00:10");
|
|
25
|
+
expect(time).toThrow();
|
|
26
|
+
});
|
|
27
|
+
it("Should not throw given HH:MM format", () => {
|
|
28
|
+
const time = () => new ISO8601Time_1.ISO8601Time("10:00");
|
|
29
|
+
expect(time).not.toThrow();
|
|
30
|
+
});
|
|
31
|
+
it("Should not throw given HH:MM:SS format", () => {
|
|
32
|
+
const time = () => new ISO8601Time_1.ISO8601Time("10:00:00");
|
|
33
|
+
expect(time).not.toThrow();
|
|
34
|
+
});
|
|
35
|
+
it("Should throw given invalid HH:MM:SS format", () => {
|
|
36
|
+
const time = () => new ISO8601Time_1.ISO8601Time("25:00:00");
|
|
37
|
+
expect(time).toThrow();
|
|
38
|
+
});
|
|
39
|
+
it("Should throw given invalid HH:MM format", () => {
|
|
40
|
+
const time = () => new ISO8601Time_1.ISO8601Time("12:60");
|
|
41
|
+
expect(time).toThrow();
|
|
42
|
+
});
|
|
43
|
+
it("Should throw given invalid negative timezone", () => {
|
|
44
|
+
const time = () => new ISO8601Time_1.ISO8601Time("12:00:00-15:00");
|
|
45
|
+
expect(time).toThrow();
|
|
46
|
+
});
|
|
47
|
+
it("Should throw given invalid positive timezone", () => {
|
|
48
|
+
const time = () => new ISO8601Time_1.ISO8601Time("12:00:00+13:00");
|
|
49
|
+
expect(time).toThrow();
|
|
50
|
+
});
|
|
51
|
+
it("Should not throw given HH:MM:SS(+|-)HH:MM format", () => {
|
|
52
|
+
const time = () => new ISO8601Time_1.ISO8601Time("12:00:00-03:00");
|
|
53
|
+
expect(time).not.toThrow();
|
|
54
|
+
});
|
|
55
|
+
it("Should not throw given HH:MM:SS.sssZ format", () => {
|
|
56
|
+
const time = () => new ISO8601Time_1.ISO8601Time("12:00:00.000Z");
|
|
57
|
+
expect(time).not.toThrow();
|
|
58
|
+
});
|
|
59
|
+
it("Should not throw given HH:MM:SSZ format", () => {
|
|
60
|
+
const time = () => new ISO8601Time_1.ISO8601Time("12:00:00Z");
|
|
61
|
+
expect(time).not.toThrow();
|
|
62
|
+
});
|
|
23
63
|
});
|
|
24
64
|
describe("ISO8601Time.getNow()", () => {
|
|
25
65
|
it("Should get now time.", () => {
|
|
@@ -2,11 +2,24 @@ import { ITimeValidator } from "./TimeValidator";
|
|
|
2
2
|
export interface IISO8601TimeValidator extends ITimeValidator {
|
|
3
3
|
isHHmmSS: (time: string) => boolean;
|
|
4
4
|
isHHmm: (time: string) => boolean;
|
|
5
|
+
isHHmmSSPlusNumberedTimezone: (time: string) => boolean;
|
|
6
|
+
isHHmmSSsssZ: (time: string) => boolean;
|
|
7
|
+
isHHmmSSZ: (time: string) => boolean;
|
|
8
|
+
/** Accepted formats: `HH:MM:SS`, `HH:MM`, `HH:MM:SSZ`, `HH:MM:SS.sssZ` and `HH:MM:SS(+|-)HH:MM`. */
|
|
9
|
+
formatIsValid: (time: string) => boolean;
|
|
5
10
|
}
|
|
6
|
-
export declare class ISO8601TimeValidator implements
|
|
11
|
+
export declare class ISO8601TimeValidator implements IISO8601TimeValidator {
|
|
12
|
+
private upTo23;
|
|
13
|
+
private upTo59;
|
|
7
14
|
private hhMMssPattern;
|
|
8
15
|
private hhMMPattern;
|
|
16
|
+
private hhMMssPlusNumberedTimezonePattern;
|
|
17
|
+
private hhMMssZPattern;
|
|
18
|
+
private hhMMssSSSZPattern;
|
|
9
19
|
formatIsValid(time: string): boolean;
|
|
10
20
|
isHHmmSS(time: string): boolean;
|
|
11
21
|
isHHmm(time: string): boolean;
|
|
22
|
+
isHHmmSSPlusNumberedTimezone: (time: string) => boolean;
|
|
23
|
+
isHHmmSSZ: (time: string) => boolean;
|
|
24
|
+
isHHmmSSsssZ: (time: string) => boolean;
|
|
12
25
|
}
|
|
@@ -3,11 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ISO8601TimeValidator = void 0;
|
|
4
4
|
class ISO8601TimeValidator {
|
|
5
5
|
constructor() {
|
|
6
|
-
this.
|
|
7
|
-
this.
|
|
6
|
+
this.upTo23 = "([0-1][0-9]|[2][0-3])";
|
|
7
|
+
this.upTo59 = "[0-5][0-9]";
|
|
8
|
+
this.hhMMssPattern = new RegExp(`^${this.upTo23}:${this.upTo59}:${this.upTo59}$`);
|
|
9
|
+
this.hhMMPattern = new RegExp(`^${this.upTo23}:${this.upTo59}$`);
|
|
10
|
+
this.hhMMssPlusNumberedTimezonePattern = new RegExp(`^${this.upTo23}:${this.upTo59}:${this.upTo59}(\\+((0[0-9]|1[0-2]):${this.upTo59})|\\-((0[0-9]|1[0-4]):${this.upTo59}))$`);
|
|
11
|
+
this.hhMMssZPattern = new RegExp(`^${this.upTo23}:${this.upTo59}:${this.upTo59}Z$`);
|
|
12
|
+
this.hhMMssSSSZPattern = new RegExp(`^${this.upTo23}:${this.upTo59}:${this.upTo59}.[0-9]{3}Z$`);
|
|
13
|
+
this.isHHmmSSPlusNumberedTimezone = (time) => {
|
|
14
|
+
return this.hhMMssPlusNumberedTimezonePattern.test(time);
|
|
15
|
+
};
|
|
16
|
+
this.isHHmmSSZ = (time) => {
|
|
17
|
+
return this.hhMMssZPattern.test(time);
|
|
18
|
+
};
|
|
19
|
+
this.isHHmmSSsssZ = (time) => {
|
|
20
|
+
return this.hhMMssSSSZPattern.test(time);
|
|
21
|
+
};
|
|
8
22
|
}
|
|
9
23
|
formatIsValid(time) {
|
|
10
|
-
return this.isHHmm(time) ||
|
|
24
|
+
return (this.isHHmm(time) ||
|
|
25
|
+
this.isHHmmSS(time) ||
|
|
26
|
+
this.isHHmmSSPlusNumberedTimezone(time) ||
|
|
27
|
+
this.isHHmmSSZ(time) ||
|
|
28
|
+
this.isHHmmSSsssZ(time));
|
|
11
29
|
}
|
|
12
30
|
isHHmmSS(time) {
|
|
13
31
|
return this.hhMMssPattern.test(time);
|
|
@@ -4,12 +4,24 @@ const ISO8601TimeValidator_1 = require("./ISO8601TimeValidator");
|
|
|
4
4
|
describe("ISO8601TimeValidator", () => {
|
|
5
5
|
const validator = new ISO8601TimeValidator_1.ISO8601TimeValidator();
|
|
6
6
|
describe("ISO8601TimeValidator.formatIsValid()", () => {
|
|
7
|
-
it("Should
|
|
7
|
+
it("Should accept ISO8601 timestamp with offset.", () => {
|
|
8
8
|
const time = "00:00:00-03:00";
|
|
9
|
-
expect(validator.formatIsValid(time)).toBe(
|
|
9
|
+
expect(validator.formatIsValid(time)).toBe(true);
|
|
10
10
|
});
|
|
11
|
-
it("Should
|
|
11
|
+
it("Should accept ISO8601 format with another offset.", () => {
|
|
12
12
|
const time = "00:00:00-02:00";
|
|
13
|
+
expect(validator.formatIsValid(time)).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
it("Should accept HH:MM:SSZ format.", () => {
|
|
16
|
+
const time = "00:00:00Z";
|
|
17
|
+
expect(validator.formatIsValid(time)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
it("Should accept HH:MM:SS.sssZ format.", () => {
|
|
20
|
+
const time = "00:00:00.000Z";
|
|
21
|
+
expect(validator.formatIsValid(time)).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
it("Should not accept HH:MM:SS.sssZ format with non-numeric digits.", () => {
|
|
24
|
+
const time = "00:00:00.00dZ";
|
|
13
25
|
expect(validator.formatIsValid(time)).toBe(false);
|
|
14
26
|
});
|
|
15
27
|
it("Should not accept non-ISO8601 formats.", () => {
|
package/dist/index.cjs
CHANGED
|
@@ -224,15 +224,33 @@ var ISO8601DateTime = class _ISO8601DateTime {
|
|
|
224
224
|
// src/domain/entities/ISO8601TimeValidator.ts
|
|
225
225
|
var ISO8601TimeValidator = class {
|
|
226
226
|
constructor() {
|
|
227
|
+
this.upTo23 = "([0-1][0-9]|[2][0-3])";
|
|
228
|
+
this.upTo59 = "[0-5][0-9]";
|
|
227
229
|
this.hhMMssPattern = new RegExp(
|
|
228
|
-
|
|
230
|
+
`^${this.upTo23}:${this.upTo59}:${this.upTo59}$`
|
|
229
231
|
);
|
|
230
|
-
this.hhMMPattern = new RegExp(
|
|
231
|
-
|
|
232
|
+
this.hhMMPattern = new RegExp(`^${this.upTo23}:${this.upTo59}$`);
|
|
233
|
+
this.hhMMssPlusNumberedTimezonePattern = new RegExp(
|
|
234
|
+
`^${this.upTo23}:${this.upTo59}:${this.upTo59}(\\+((0[0-9]|1[0-2]):${this.upTo59})|\\-((0[0-9]|1[0-4]):${this.upTo59}))$`
|
|
232
235
|
);
|
|
236
|
+
this.hhMMssZPattern = new RegExp(
|
|
237
|
+
`^${this.upTo23}:${this.upTo59}:${this.upTo59}Z$`
|
|
238
|
+
);
|
|
239
|
+
this.hhMMssSSSZPattern = new RegExp(
|
|
240
|
+
`^${this.upTo23}:${this.upTo59}:${this.upTo59}.[0-9]{3}Z$`
|
|
241
|
+
);
|
|
242
|
+
this.isHHmmSSPlusNumberedTimezone = (time) => {
|
|
243
|
+
return this.hhMMssPlusNumberedTimezonePattern.test(time);
|
|
244
|
+
};
|
|
245
|
+
this.isHHmmSSZ = (time) => {
|
|
246
|
+
return this.hhMMssZPattern.test(time);
|
|
247
|
+
};
|
|
248
|
+
this.isHHmmSSsssZ = (time) => {
|
|
249
|
+
return this.hhMMssSSSZPattern.test(time);
|
|
250
|
+
};
|
|
233
251
|
}
|
|
234
252
|
formatIsValid(time) {
|
|
235
|
-
return this.isHHmm(time) || this.isHHmmSS(time);
|
|
253
|
+
return this.isHHmm(time) || this.isHHmmSS(time) || this.isHHmmSSPlusNumberedTimezone(time) || this.isHHmmSSZ(time) || this.isHHmmSSsssZ(time);
|
|
236
254
|
}
|
|
237
255
|
isHHmmSS(time) {
|
|
238
256
|
return this.hhMMssPattern.test(time);
|