@eliasrrosa/tutorhub-public-assets 0.0.8 → 0.0.10

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.
@@ -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
@@ -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 ITimeValidator {
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.hhMMssPattern = new RegExp("^([0-1][0-9]|[2][0-3]):[0-5][0-9]:[0-5][0-9]$");
7
- this.hhMMPattern = new RegExp("^([0-1][0-9]|[2][0-3]):[0-5][0-9]$");
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) || this.isHHmmSS(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 not accept ISO8601 timestamp with offset.", () => {
7
+ it("Should accept ISO8601 timestamp with offset.", () => {
8
8
  const time = "00:00:00-03:00";
9
- expect(validator.formatIsValid(time)).toBe(false);
9
+ expect(validator.formatIsValid(time)).toBe(true);
10
10
  });
11
- it("Should not accept ISO8601 format with timestamp.", () => {
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.", () => {
@@ -1,4 +1,5 @@
1
+ import { ITime } from "./Time";
1
2
  export interface ITimeSlot {
2
- startTime: string;
3
- endTime: string;
3
+ startTime: ITime;
4
+ endTime: ITime;
4
5
  }
@@ -3,6 +3,7 @@ import { ICourse } from "./Course";
3
3
  import { IRescheduleRequest } from "./RescheduleRequest";
4
4
  import { IDateTimeSlot } from "./DateTimeSlot";
5
5
  import { IDate } from "./Date";
6
+ import { ITime } from "./Time";
6
7
  export interface IUserUnavailableTime {
7
8
  id: string;
8
9
  userId: string;
@@ -10,8 +11,8 @@ export interface IUserUnavailableTime {
10
11
  groupId: string;
11
12
  date: IDate;
12
13
  dayOfTheWeek: number;
13
- startTime: string;
14
- endTime: string;
14
+ startTime: ITime;
15
+ endTime: ITime;
15
16
  isAvailableTime: boolean;
16
17
  course?: ICourse;
17
18
  courseId: string | null;
@@ -24,8 +25,8 @@ export declare class UserUnavailableTime implements IUserUnavailableTime {
24
25
  user?: IUserAuth;
25
26
  groupId: string;
26
27
  date: IDate;
27
- startTime: string;
28
- endTime: string;
28
+ startTime: ITime;
29
+ endTime: ITime;
29
30
  isAvailableTime: boolean;
30
31
  dayOfTheWeek: number;
31
32
  course?: ICourse;
@@ -37,8 +38,8 @@ export declare class UserUnavailableTime implements IUserUnavailableTime {
37
38
  user?: IUserAuth;
38
39
  groupId: string;
39
40
  date: IDate;
40
- startTime: string;
41
- endTime: string;
41
+ startTime: ITime | string;
42
+ endTime: ITime | string;
42
43
  isAvailableTime: boolean;
43
44
  course?: ICourse;
44
45
  courseId: string | null;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserUnavailableTime = void 0;
4
+ const ISO8601Time_1 = require("./ISO8601Time");
4
5
  class UserUnavailableTime {
5
6
  constructor(opts) {
6
7
  this.getDateTimeSlot = () => {
@@ -18,8 +19,8 @@ class UserUnavailableTime {
18
19
  this.groupId = opts.groupId;
19
20
  this.date = opts.date;
20
21
  this.dayOfTheWeek = this.getDayOfTheWeek();
21
- this.startTime = opts.startTime;
22
- this.endTime = opts.endTime;
22
+ this.startTime = typeof opts.startTime == "string" ? new ISO8601Time_1.ISO8601Time(opts.startTime) : opts.startTime;
23
+ this.endTime = typeof opts.endTime == "string" ? new ISO8601Time_1.ISO8601Time(opts.endTime) : opts.endTime;
23
24
  this.isAvailableTime = opts.isAvailableTime;
24
25
  this.course = opts.course;
25
26
  this.courseId = opts.courseId;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ISO8601Date_1 = require("./ISO8601Date");
4
+ const ISO8601Time_1 = require("./ISO8601Time");
4
5
  const UserUnavailableTime_1 = require("./UserUnavailableTime");
5
6
  describe("UserUnavailableTime", () => {
6
- const availableTime = new UserUnavailableTime_1.UserUnavailableTime({
7
+ const availableTimeData = {
7
8
  courseId: "courseId",
8
9
  date: new ISO8601Date_1.ISO8601Date("2025-01-01"),
9
10
  endTime: "15:00",
@@ -12,11 +13,32 @@ describe("UserUnavailableTime", () => {
12
13
  id: "id",
13
14
  isAvailableTime: true,
14
15
  userId: "userId",
16
+ };
17
+ describe("UserUnavailableTime constructor()", () => {
18
+ it("Should be instantiable.", () => {
19
+ const availableTime = new UserUnavailableTime_1.UserUnavailableTime(availableTimeData);
20
+ expect(availableTime).toBeDefined();
21
+ });
22
+ it("Should contain the proper dayOfTheWeek.", () => {
23
+ const availableTime = new UserUnavailableTime_1.UserUnavailableTime(availableTimeData);
24
+ expect(availableTime.dayOfTheWeek).toBe(3);
25
+ });
26
+ it("Should instantiate ISO8601Time for startTime and endTime", () => {
27
+ const availableTime = new UserUnavailableTime_1.UserUnavailableTime(availableTimeData);
28
+ expect(availableTime.startTime).toBeInstanceOf(ISO8601Time_1.ISO8601Time);
29
+ expect(availableTime.endTime).toBeInstanceOf(ISO8601Time_1.ISO8601Time);
30
+ });
31
+ it("Should throw given invalid startTime or endTime format", () => {
32
+ const availableTime = () => new UserUnavailableTime_1.UserUnavailableTime(Object.assign(Object.assign({}, availableTimeData), { startTime: "25:00:00" }));
33
+ expect(availableTime).toThrow();
34
+ });
15
35
  });
16
- it("Should be instantiable.", () => {
17
- expect(availableTime).toBeDefined();
18
- });
19
- it("Should contain the proper dayOfTheWeek.", () => {
20
- expect(availableTime.dayOfTheWeek).toBe(3);
36
+ describe("UserUnavailableTime.getDateTimeSlot()", () => {
37
+ const availableTime = new UserUnavailableTime_1.UserUnavailableTime(Object.assign({}, availableTimeData));
38
+ it("Should return an object of type IDateTimeSlot", () => {
39
+ expect(availableTime.getDateTimeSlot().date).toBeInstanceOf(ISO8601Date_1.ISO8601Date);
40
+ expect(availableTime.getDateTimeSlot().timeSlot.endTime).toBeInstanceOf(ISO8601Time_1.ISO8601Time);
41
+ expect(availableTime.getDateTimeSlot().timeSlot.startTime).toBeInstanceOf(ISO8601Time_1.ISO8601Time);
42
+ });
21
43
  });
22
44
  });
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
- "^([0-1][0-9]|[2][0-3]):[0-5][0-9]:[0-5][0-9]$"
230
+ `^${this.upTo23}:${this.upTo59}:${this.upTo59}$`
229
231
  );
230
- this.hhMMPattern = new RegExp(
231
- "^([0-1][0-9]|[2][0-3]):[0-5][0-9]$"
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);
@@ -315,8 +333,8 @@ var UserUnavailableTime = class {
315
333
  this.groupId = opts.groupId;
316
334
  this.date = opts.date;
317
335
  this.dayOfTheWeek = this.getDayOfTheWeek();
318
- this.startTime = opts.startTime;
319
- this.endTime = opts.endTime;
336
+ this.startTime = typeof opts.startTime == "string" ? new ISO8601Time(opts.startTime) : opts.startTime;
337
+ this.endTime = typeof opts.endTime == "string" ? new ISO8601Time(opts.endTime) : opts.endTime;
320
338
  this.isAvailableTime = opts.isAvailableTime;
321
339
  this.course = opts.course;
322
340
  this.courseId = opts.courseId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eliasrrosa/tutorhub-public-assets",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Assets, mainly interfaces, to be shared among different Tutorhub apps.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",