@eliasrrosa/tutorhub-public-assets 0.0.6 → 0.0.8

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.
@@ -16,7 +16,9 @@ export declare class ISO8601Time implements ITime {
16
16
  */
17
17
  constructor(value?: string);
18
18
  private validateFormatOrThrow;
19
- getTime(): string;
19
+ getTime(opts?: {
20
+ format?: "HH:MM" | "HH:MM:SS";
21
+ }): string;
20
22
  getMinutes(): string;
21
23
  getHours(): string;
22
24
  getSeconds(): string;
@@ -24,12 +24,23 @@ class ISO8601Time {
24
24
  if (!this.validator.formatIsValid(this.value))
25
25
  throw new Error("Time format must be ISO8601.");
26
26
  }
27
- getTime() {
27
+ getTime(opts) {
28
28
  this.validateFormatOrThrow();
29
- if (this.validator.isHHmm(this.value)) {
30
- return `${this.value}:00`;
29
+ if ((opts === null || opts === void 0 ? void 0 : opts.format) == "HH:MM" && this.validator.isHHmm(this.value)) {
30
+ return this.value;
31
31
  }
32
- return this.value;
32
+ if (((opts === null || opts === void 0 ? void 0 : opts.format) == "HH:MM:SS" || !(opts === null || opts === void 0 ? void 0 : opts.format)) &&
33
+ this.validator.isHHmmSS(this.value)) {
34
+ return this.value;
35
+ }
36
+ if ((opts === null || opts === void 0 ? void 0 : opts.format) == "HH:MM" && this.validator.isHHmmSS(this.value)) {
37
+ return `${this.getHours()}:${this.getMinutes()}`;
38
+ }
39
+ if (((opts === null || opts === void 0 ? void 0 : opts.format) == "HH:MM:SS" || !(opts === null || opts === void 0 ? void 0 : opts.format)) &&
40
+ this.validator.isHHmm(this.value)) {
41
+ return `${this.getHours()}:${this.getMinutes()}:${this.getSeconds()}`;
42
+ }
43
+ throw new Error("Time format is invalid.");
33
44
  }
34
45
  getMinutes() {
35
46
  this.validateFormatOrThrow();
@@ -59,5 +59,25 @@ describe("ISO8601Time", () => {
59
59
  const time2 = new ISO8601Time_1.ISO8601Time("00:01:02");
60
60
  expect(time2.getTime()).toBe("00:01:02");
61
61
  });
62
+ it("Should return HH:MM if format argument is passed", () => {
63
+ const time = new ISO8601Time_1.ISO8601Time("00:01");
64
+ expect(time.getTime({ format: "HH:MM" })).toBe("00:01");
65
+ });
66
+ it("Should return HH:MM if format argument is passed and time format is HH:MM:SS", () => {
67
+ const time = new ISO8601Time_1.ISO8601Time("00:01:10");
68
+ expect(time.getTime({ format: "HH:MM" })).toBe("00:01");
69
+ });
70
+ it("Should return HH:MM:SS by default", () => {
71
+ const time = new ISO8601Time_1.ISO8601Time("00:01:10");
72
+ expect(time.getTime()).toBe("00:01:10");
73
+ });
74
+ it("Should return HH:MM:SS by default even if format is HH:MM", () => {
75
+ const time = new ISO8601Time_1.ISO8601Time("00:01");
76
+ expect(time.getTime()).toBe("00:01:00");
77
+ });
78
+ it("Should return HH:MM:SS given format argument", () => {
79
+ const time = new ISO8601Time_1.ISO8601Time("00:01");
80
+ expect(time.getTime({ format: "HH:MM:SS" })).toBe("00:01:00");
81
+ });
62
82
  });
63
83
  });
package/dist/index.cjs CHANGED
@@ -246,7 +246,7 @@ var ISO8601TimeValidator = class {
246
246
  var ISO8601Time = class _ISO8601Time {
247
247
  /**
248
248
  * Throws if format is invalid.
249
- * Accepted formats: HH:MM:SS and HH:MM.
249
+ * Accepted formats: HH:MM:SS and HH:MM.
250
250
  */
251
251
  constructor(value) {
252
252
  this.validator = new ISO8601TimeValidator();
@@ -258,12 +258,21 @@ var ISO8601Time = class _ISO8601Time {
258
258
  if (!this.validator.formatIsValid(this.value))
259
259
  throw new Error("Time format must be ISO8601.");
260
260
  }
261
- getTime() {
261
+ getTime(opts) {
262
262
  this.validateFormatOrThrow();
263
- if (this.validator.isHHmm(this.value)) {
264
- return `${this.value}:00`;
263
+ if ((opts == null ? void 0 : opts.format) == "HH:MM" && this.validator.isHHmm(this.value)) {
264
+ return this.value;
265
265
  }
266
- return this.value;
266
+ if (((opts == null ? void 0 : opts.format) == "HH:MM:SS" || !(opts == null ? void 0 : opts.format)) && this.validator.isHHmmSS(this.value)) {
267
+ return this.value;
268
+ }
269
+ if ((opts == null ? void 0 : opts.format) == "HH:MM" && this.validator.isHHmmSS(this.value)) {
270
+ return `${this.getHours()}:${this.getMinutes()}`;
271
+ }
272
+ if (((opts == null ? void 0 : opts.format) == "HH:MM:SS" || !(opts == null ? void 0 : opts.format)) && this.validator.isHHmm(this.value)) {
273
+ return `${this.getHours()}:${this.getMinutes()}:${this.getSeconds()}`;
274
+ }
275
+ throw new Error("Time format is invalid.");
267
276
  }
268
277
  getMinutes() {
269
278
  this.validateFormatOrThrow();
@@ -1,4 +1,5 @@
1
1
  import { IUserUnavailableTime } from "../../domain/entities/UserUnavailableTime";
2
2
  export type GetFixedAvailableTimeResponseBody = {
3
3
  fixedAvailableTimes: IUserUnavailableTime[];
4
+ shareableText?: string;
4
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eliasrrosa/tutorhub-public-assets",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Assets, mainly interfaces, to be shared among different Tutorhub apps.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",