@eliasrrosa/tutorhub-public-assets 0.0.3 → 0.0.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.
- package/dist/domain/entities/AsaasCustomer.js +5 -1
- package/dist/domain/entities/Class.js +5 -1
- package/dist/domain/entities/ClassRequest.js +2 -1
- package/dist/domain/entities/Contract.js +2 -1
- package/dist/domain/entities/Course.js +2 -1
- package/dist/domain/entities/CourseToSchoolConnectionRequest.js +2 -1
- package/dist/domain/entities/Date.js +2 -1
- package/dist/domain/entities/DateTimeSlot.js +2 -1
- package/dist/domain/entities/DateValidator.js +2 -1
- package/dist/domain/entities/File.js +2 -1
- package/dist/domain/entities/FreeTimeSlot.js +5 -1
- package/dist/domain/entities/GenericNotification.js +2 -1
- package/dist/domain/entities/GoogleAuth.js +2 -1
- package/dist/domain/entities/GoogleCalendar.js +2 -1
- package/dist/domain/entities/GoogleCalendarEvent.js +2 -1
- package/dist/domain/entities/ISO8601Date.js +7 -3
- package/dist/domain/entities/ISO8601Date.test.js +35 -33
- package/dist/domain/entities/ISO8601DateTime.js +5 -1
- package/dist/domain/entities/ISO8601DateTime.test.js +53 -51
- package/dist/domain/entities/ISO8601DateValidator.js +5 -1
- package/dist/domain/entities/ISO8601DateValidator.test.js +5 -3
- package/dist/domain/entities/ISO8601Time.js +7 -3
- package/dist/domain/entities/ISO8601Time.test.js +14 -12
- package/dist/domain/entities/ISO8601TimeValidator.js +5 -1
- package/dist/domain/entities/ISO8601TimeValidator.test.js +4 -2
- package/dist/domain/entities/PasswordRecovery.js +2 -1
- package/dist/domain/entities/Payment.js +2 -1
- package/dist/domain/entities/PaymentRecognitionRequest.js +2 -1
- package/dist/domain/entities/PreApprovedUser.js +2 -1
- package/dist/domain/entities/RescheduleRequest.js +2 -1
- package/dist/domain/entities/School.js +2 -1
- package/dist/domain/entities/SchoolConnection.js +2 -1
- package/dist/domain/entities/SchoolConnectionRequest.js +2 -1
- package/dist/domain/entities/SchoolStudent.js +2 -1
- package/dist/domain/entities/SchoolTeacher.js +2 -1
- package/dist/domain/entities/Time.js +2 -1
- package/dist/domain/entities/TimeSlot.js +2 -1
- package/dist/domain/entities/TimeValidator.js +2 -1
- package/dist/domain/entities/UnauthorizedUser.js +2 -1
- package/dist/domain/entities/UserAuth.js +2 -1
- package/dist/domain/entities/UserConnection.js +2 -1
- package/dist/domain/entities/UserConnectionRequest.js +2 -1
- package/dist/domain/entities/UserCredentials.js +5 -1
- package/dist/domain/entities/UserNavigation.js +2 -1
- package/dist/domain/entities/UserPreferences.js +2 -1
- package/dist/domain/entities/UserPremium.js +2 -1
- package/dist/domain/entities/UserProfile.js +2 -1
- package/dist/domain/entities/UserRoles.js +2 -1
- package/dist/domain/entities/UserSharedFileTimestamps.js +2 -1
- package/dist/domain/entities/UserUnavailableTime.js +5 -1
- package/dist/domain/entities/UserUnavailableTime.test.js +6 -4
- package/dist/domain/repositories/UnavailableTimeRepository.js +2 -1
- package/dist/index.cjs +341 -0
- package/dist/index.d.ts +47 -47
- package/dist/index.js +21 -10
- package/dist/restful/responses/GetFixedAvailableTimesResponseBody.js +2 -1
- package/package.json +9 -4
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsaasCustomer = void 0;
|
|
4
|
+
class AsaasCustomer {
|
|
2
5
|
constructor(opts) {
|
|
3
6
|
this.name = opts.name;
|
|
4
7
|
this.cpfCnpj = opts.cpfCnpj;
|
|
@@ -7,3 +10,4 @@ export class AsaasCustomer {
|
|
|
7
10
|
this.externalReference = opts.externalReference;
|
|
8
11
|
}
|
|
9
12
|
}
|
|
13
|
+
exports.AsaasCustomer = AsaasCustomer;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Class = void 0;
|
|
4
|
+
class Class {
|
|
2
5
|
constructor(params) {
|
|
3
6
|
this.id = params.id;
|
|
4
7
|
this.groupId = params.groupId ? params.groupId : null;
|
|
@@ -24,3 +27,4 @@ export class Class {
|
|
|
24
27
|
this.ownerId = params.ownerId;
|
|
25
28
|
}
|
|
26
29
|
}
|
|
30
|
+
exports.Class = Class;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FreeDateTimeSlot = void 0;
|
|
4
|
+
class FreeDateTimeSlot {
|
|
2
5
|
constructor(opts) {
|
|
3
6
|
this.date = opts.date;
|
|
4
7
|
this.startTime = opts.startTime;
|
|
@@ -6,3 +9,4 @@ export class FreeDateTimeSlot {
|
|
|
6
9
|
this.userId = opts.userId;
|
|
7
10
|
}
|
|
8
11
|
}
|
|
12
|
+
exports.FreeDateTimeSlot = FreeDateTimeSlot;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISO8601Date = void 0;
|
|
4
|
+
const ISO8601DateValidator_1 = require("./ISO8601DateValidator");
|
|
5
|
+
class ISO8601Date {
|
|
3
6
|
constructor(value) {
|
|
4
|
-
this.validator = new ISO8601DateValidator();
|
|
7
|
+
this.validator = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
5
8
|
this.getDay = () => {
|
|
6
9
|
this.throwIfFormatIsNotValid();
|
|
7
10
|
return this.value.split("-")[2];
|
|
@@ -65,6 +68,7 @@ export class ISO8601Date {
|
|
|
65
68
|
return `${year}-${month}-${day}`;
|
|
66
69
|
}
|
|
67
70
|
}
|
|
71
|
+
exports.ISO8601Date = ISO8601Date;
|
|
68
72
|
/**
|
|
69
73
|
* Converts a Javascript Date instance into an IDate instance. Uses local timezone as default.
|
|
70
74
|
* @param useUtc set to `true` to consider UTC when extracting year, month and date
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ISO8601Date_1 = require("./ISO8601Date");
|
|
2
4
|
describe("ISO8601Date", () => {
|
|
3
5
|
describe("ISO8601Date constructor", () => {
|
|
4
6
|
beforeEach(() => {
|
|
@@ -8,21 +10,21 @@ describe("ISO8601Date", () => {
|
|
|
8
10
|
jest.useRealTimers();
|
|
9
11
|
});
|
|
10
12
|
it("Should construct if date is valid", () => {
|
|
11
|
-
const date = new ISO8601Date("2025-01-01");
|
|
13
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01");
|
|
12
14
|
expect(date.value).toBe("2025-01-01");
|
|
13
15
|
});
|
|
14
16
|
it("Should throw if value is not valid", () => {
|
|
15
17
|
const instantiateDate = () => {
|
|
16
|
-
new ISO8601Date("2025-01-011");
|
|
18
|
+
new ISO8601Date_1.ISO8601Date("2025-01-011");
|
|
17
19
|
};
|
|
18
20
|
expect(instantiateDate).toThrow();
|
|
19
21
|
});
|
|
20
22
|
it("Should construct with no arguments.", () => {
|
|
21
|
-
const date = new ISO8601Date();
|
|
23
|
+
const date = new ISO8601Date_1.ISO8601Date();
|
|
22
24
|
expect(date).toBeDefined();
|
|
23
25
|
});
|
|
24
26
|
it("Should have value set as today when constructed with no arguments.", () => {
|
|
25
|
-
const date = new ISO8601Date();
|
|
27
|
+
const date = new ISO8601Date_1.ISO8601Date();
|
|
26
28
|
expect(date.value).toBe("2025-01-01");
|
|
27
29
|
const validateFormat = () => {
|
|
28
30
|
return date.validator.formatIsValid(date.value);
|
|
@@ -32,45 +34,45 @@ describe("ISO8601Date", () => {
|
|
|
32
34
|
});
|
|
33
35
|
describe("ISO8601Date.getDay()", () => {
|
|
34
36
|
it("Should return the day if format is valid.", () => {
|
|
35
|
-
const date = new ISO8601Date("2025-01-02");
|
|
37
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
36
38
|
expect(date.getDay()).toBe("02");
|
|
37
39
|
});
|
|
38
40
|
});
|
|
39
41
|
describe("ISO8601Date.getMonth()", () => {
|
|
40
42
|
it("Should return the month if format is valid.", () => {
|
|
41
|
-
const date = new ISO8601Date("2025-01-02");
|
|
43
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
42
44
|
expect(date.getMonth()).toBe("01");
|
|
43
45
|
});
|
|
44
46
|
});
|
|
45
47
|
describe("ISO8601Date.getYear()", () => {
|
|
46
48
|
it("Should return the year if format is valid.", () => {
|
|
47
|
-
const date = new ISO8601Date("2025-01-02");
|
|
49
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
48
50
|
expect(date.getYear()).toBe("2025");
|
|
49
51
|
});
|
|
50
52
|
});
|
|
51
53
|
describe("ISO8601Date.addDays()", () => {
|
|
52
54
|
it("Should add days resulting in the same month", () => {
|
|
53
|
-
const date = new ISO8601Date("2025-01-02");
|
|
55
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
54
56
|
expect(date.addDays(10).value).toBe("2025-01-12");
|
|
55
57
|
});
|
|
56
58
|
it("Should add days resulting in the next month", () => {
|
|
57
|
-
const date = new ISO8601Date("2025-01-01");
|
|
59
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01");
|
|
58
60
|
expect(date.addDays(31).value).toBe("2025-02-01");
|
|
59
61
|
});
|
|
60
62
|
it("Should add days resulting in multiple months ahead", () => {
|
|
61
|
-
const date = new ISO8601Date("2025-03-01");
|
|
63
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
62
64
|
expect(date.addDays(31 + 30 + 31 + 3).value).toBe("2025-06-04");
|
|
63
65
|
});
|
|
64
66
|
it("Should add days resulting in multiple months ahead", () => {
|
|
65
|
-
const date = new ISO8601Date("2025-03-01");
|
|
67
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
66
68
|
expect(date.addDays(31 + 30 + 31 + 3).value).toBe("2025-06-04");
|
|
67
69
|
});
|
|
68
70
|
it("Should be chainable.", () => {
|
|
69
|
-
const date = new ISO8601Date("2025-03-01");
|
|
71
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
70
72
|
expect(date.addDays(31).addDays(30).addDays(31).addDays(3).value).toBe("2025-06-04");
|
|
71
73
|
});
|
|
72
74
|
it("Should accept negative values", () => {
|
|
73
|
-
const date = new ISO8601Date("2025-03-02");
|
|
75
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-02");
|
|
74
76
|
expect(date.addDays(-1).value).toBe("2025-03-01");
|
|
75
77
|
});
|
|
76
78
|
describe("ISO8601Date.addDays() in a timezone ahead of UTC", () => {
|
|
@@ -83,43 +85,43 @@ describe("ISO8601Date", () => {
|
|
|
83
85
|
jest.useRealTimers();
|
|
84
86
|
});
|
|
85
87
|
it("Should add days resulting in the same month", () => {
|
|
86
|
-
const date = new ISO8601Date("2025-01-02");
|
|
88
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
87
89
|
expect(date.addDays(10).value).toBe("2025-01-12");
|
|
88
90
|
});
|
|
89
91
|
it("Should add days resulting in the next month", () => {
|
|
90
|
-
const date = new ISO8601Date("2025-01-01");
|
|
92
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01");
|
|
91
93
|
expect(date.addDays(31).value).toBe("2025-02-01");
|
|
92
94
|
});
|
|
93
95
|
it("Should add days resulting in multiple months ahead", () => {
|
|
94
|
-
const date = new ISO8601Date("2025-03-01");
|
|
96
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
95
97
|
expect(date.addDays(31 + 30 + 31 + 3).value).toBe("2025-06-04");
|
|
96
98
|
});
|
|
97
99
|
it("Should add days resulting in multiple months ahead", () => {
|
|
98
|
-
const date = new ISO8601Date("2025-03-01");
|
|
100
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
99
101
|
expect(date.addDays(31 + 30 + 31 + 3).value).toBe("2025-06-04");
|
|
100
102
|
});
|
|
101
103
|
it("Should be chainable.", () => {
|
|
102
|
-
const date = new ISO8601Date("2025-03-01");
|
|
104
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
103
105
|
expect(date.addDays(31).addDays(30).addDays(31).addDays(3).value).toBe("2025-06-04");
|
|
104
106
|
});
|
|
105
107
|
});
|
|
106
108
|
});
|
|
107
109
|
describe("ISO8601Date.jsDateTimeToDate()", () => {
|
|
108
110
|
it("Should return an IDate instance", () => {
|
|
109
|
-
expect(ISO8601Date.jsDateTimeToDate(new Date(2025, 5, 4))).toBeInstanceOf(ISO8601Date);
|
|
111
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date(2025, 5, 4))).toBeInstanceOf(ISO8601Date_1.ISO8601Date);
|
|
110
112
|
});
|
|
111
113
|
it("Should return expected value in ISO8601 format.", () => {
|
|
112
|
-
expect(ISO8601Date.jsDateTimeToDate(new Date(2025, 5, 4)).value).toBe("2025-06-04");
|
|
113
|
-
expect(ISO8601Date.jsDateTimeToDate(new Date(2025, 0, 1)).value).toBe("2025-01-01");
|
|
114
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date(2025, 5, 4)).value).toBe("2025-06-04");
|
|
115
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date(2025, 0, 1)).value).toBe("2025-01-01");
|
|
114
116
|
});
|
|
115
117
|
it("If js date is in UTC (created without timezone and with a string) and converting would cause a change of date, should return date changed.", () => {
|
|
116
|
-
expect(ISO8601Date.jsDateTimeToDate(new Date("2025-06-04")).value).toBe("2025-06-03");
|
|
118
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date("2025-06-04")).value).toBe("2025-06-03");
|
|
117
119
|
});
|
|
118
120
|
it("If js date is in UTC (created with timezone and with a string) and converting would cause a change of date, should return date changed.", () => {
|
|
119
|
-
expect(ISO8601Date.jsDateTimeToDate(new Date("2025-06-04T00:00:00Z")).value).toBe("2025-06-03");
|
|
121
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date("2025-06-04T00:00:00Z")).value).toBe("2025-06-03");
|
|
120
122
|
});
|
|
121
123
|
it("If js date is in UTC and useUtc param is true, should return utc date.", () => {
|
|
122
|
-
expect(ISO8601Date.jsDateTimeToDate(new Date("2025-06-04T00:00:00Z"), {
|
|
124
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date("2025-06-04T00:00:00Z"), {
|
|
123
125
|
useUtc: true,
|
|
124
126
|
}).value).toBe("2025-06-04");
|
|
125
127
|
});
|
|
@@ -130,16 +132,16 @@ describe("ISO8601Date", () => {
|
|
|
130
132
|
});
|
|
131
133
|
it("Should return today's date properly with different timezones", () => {
|
|
132
134
|
jest.useFakeTimers().setSystemTime(new Date("2025-01-01T23:00:00-03:00"));
|
|
133
|
-
expect(ISO8601Date.getToday()).toBe("2025-01-01");
|
|
135
|
+
expect(ISO8601Date_1.ISO8601Date.getToday()).toBe("2025-01-01");
|
|
134
136
|
jest.setSystemTime(new Date("2025-01-02T23:00:00+03:00"));
|
|
135
|
-
expect(ISO8601Date.getToday()).toBe("2025-01-02");
|
|
137
|
+
expect(ISO8601Date_1.ISO8601Date.getToday()).toBe("2025-01-02");
|
|
136
138
|
jest.setSystemTime(new Date("2025-01-04T23:00:00+12:00"));
|
|
137
|
-
expect(ISO8601Date.getToday()).toBe("2025-01-04");
|
|
139
|
+
expect(ISO8601Date_1.ISO8601Date.getToday()).toBe("2025-01-04");
|
|
138
140
|
});
|
|
139
141
|
});
|
|
140
142
|
describe("ISO8601Date.toLocalJsDateTime()", () => {
|
|
141
143
|
it("Should return js date time of same day, month and year, considering local time.", () => {
|
|
142
|
-
const date = new ISO8601Date("2025-01-01").toLocalJsDateTime();
|
|
144
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01").toLocalJsDateTime();
|
|
143
145
|
expect(date.getMonth()).toEqual(0);
|
|
144
146
|
expect(date.getDate()).toEqual(1);
|
|
145
147
|
expect(date.getFullYear()).toEqual(2025);
|
|
@@ -154,7 +156,7 @@ describe("ISO8601Date", () => {
|
|
|
154
156
|
});
|
|
155
157
|
it("Should return js date time of same day, month and year, considering utc time.", () => {
|
|
156
158
|
jest.useFakeTimers().setSystemTime(new Date("2025-01-01T00:00:00Z"));
|
|
157
|
-
const date = new ISO8601Date("2025-01-01").toUtcJsDateTime();
|
|
159
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01").toUtcJsDateTime();
|
|
158
160
|
expect(date).toBeInstanceOf(Date);
|
|
159
161
|
expect(date.getUTCMonth()).toEqual(0);
|
|
160
162
|
expect(date.getUTCDate()).toEqual(1);
|
|
@@ -166,12 +168,12 @@ describe("ISO8601Date", () => {
|
|
|
166
168
|
});
|
|
167
169
|
describe("ISO8601Date.getDaysSinceEpoch()", () => {
|
|
168
170
|
it("Should return expected days count", () => {
|
|
169
|
-
const days = new ISO8601Date("1970-01-02").getDaysSinceEpoch();
|
|
171
|
+
const days = new ISO8601Date_1.ISO8601Date("1970-01-02").getDaysSinceEpoch();
|
|
170
172
|
expect(days).toEqual(1);
|
|
171
173
|
});
|
|
172
174
|
it("From a UTC date, should return expected days count", () => {
|
|
173
175
|
const utcDate = new Date("1970-01-02T00:00:00Z");
|
|
174
|
-
const days = new ISO8601Date()
|
|
176
|
+
const days = new ISO8601Date_1.ISO8601Date()
|
|
175
177
|
.jsDateTimeToDate(utcDate, { useUtc: true })
|
|
176
178
|
.getDaysSinceEpoch();
|
|
177
179
|
expect(days).toEqual(1);
|
|
@@ -182,7 +184,7 @@ describe("ISO8601Date", () => {
|
|
|
182
184
|
jest.useRealTimers();
|
|
183
185
|
});
|
|
184
186
|
jest.useFakeTimers().setSystemTime(new Date("2025-04-21"));
|
|
185
|
-
const today = new ISO8601Date();
|
|
187
|
+
const today = new ISO8601Date_1.ISO8601Date();
|
|
186
188
|
it("Should return 0 for Monday.", () => {
|
|
187
189
|
expect(today.getDayOfTheWeek()).toEqual(0);
|
|
188
190
|
});
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISO8601DateTime = void 0;
|
|
4
|
+
class ISO8601DateTime {
|
|
2
5
|
constructor(opts) {
|
|
3
6
|
this.getJSDateTime = () => {
|
|
4
7
|
return new Date(parseInt(this.date.getYear()), parseInt(this.date.getMonth()) - 1, parseInt(this.date.getDay()), parseInt(this.time.getHours()), parseInt(this.time.getMinutes()), parseInt(this.time.getSeconds()));
|
|
@@ -38,3 +41,4 @@ export class ISO8601DateTime {
|
|
|
38
41
|
return `${year}-${month}-${day}T${hour}:${minute}:${second}${timezone}`;
|
|
39
42
|
}
|
|
40
43
|
}
|
|
44
|
+
exports.ISO8601DateTime = ISO8601DateTime;
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ISO8601Date_1 = require("./ISO8601Date");
|
|
4
|
+
const ISO8601DateTime_1 = require("./ISO8601DateTime");
|
|
5
|
+
const ISO8601Time_1 = require("./ISO8601Time");
|
|
4
6
|
describe("ISO8601DateTime", () => {
|
|
5
7
|
describe("ISO8601DateTime getJSDateTime()", () => {
|
|
6
8
|
it("Should return a JS Date object.", () => {
|
|
7
|
-
const dateTime = new ISO8601DateTime({
|
|
8
|
-
date: new ISO8601Date("2025-01-01"),
|
|
9
|
-
time: new ISO8601Time("10:00:00"),
|
|
9
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
10
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-01"),
|
|
11
|
+
time: new ISO8601Time_1.ISO8601Time("10:00:00"),
|
|
10
12
|
});
|
|
11
13
|
const jsDateTime = dateTime.getJSDateTime();
|
|
12
14
|
expect(jsDateTime).toBeInstanceOf(Date);
|
|
13
15
|
});
|
|
14
16
|
it("Should return the same year, month and day when returning UTC date.", () => {
|
|
15
|
-
const dateTime = new ISO8601DateTime({
|
|
16
|
-
date: new ISO8601Date("2025-01-02"),
|
|
17
|
-
time: new ISO8601Time("00:00:00"),
|
|
17
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
18
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
19
|
+
time: new ISO8601Time_1.ISO8601Time("00:00:00"),
|
|
18
20
|
});
|
|
19
21
|
const jsDateTime = dateTime.getJSDateTime();
|
|
20
22
|
expect(jsDateTime.getUTCDate()).toBe(2);
|
|
@@ -22,17 +24,17 @@ describe("ISO8601DateTime", () => {
|
|
|
22
24
|
expect(jsDateTime.getUTCFullYear()).toBe(2025);
|
|
23
25
|
});
|
|
24
26
|
it("Should return locale date string of same date and time as constructed.", () => {
|
|
25
|
-
const dateTime = new ISO8601DateTime({
|
|
26
|
-
date: new ISO8601Date("2025-01-02"),
|
|
27
|
-
time: new ISO8601Time("01:02:03"),
|
|
27
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
28
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
29
|
+
time: new ISO8601Time_1.ISO8601Time("01:02:03"),
|
|
28
30
|
});
|
|
29
31
|
const jsDateTime = dateTime.getJSDateTime();
|
|
30
32
|
expect(jsDateTime.toLocaleDateString("pt-BR")).toBe("02/01/2025");
|
|
31
33
|
});
|
|
32
34
|
it("Should return ISO string converted to UTC.", () => {
|
|
33
|
-
const dateTime = new ISO8601DateTime({
|
|
34
|
-
date: new ISO8601Date("2025-01-02"),
|
|
35
|
-
time: new ISO8601Time("01:02:03"),
|
|
35
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
36
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
37
|
+
time: new ISO8601Time_1.ISO8601Time("01:02:03"),
|
|
36
38
|
});
|
|
37
39
|
const jsDateTime = dateTime.getJSDateTime();
|
|
38
40
|
expect(jsDateTime.toISOString()).toBe("2025-01-02T04:02:03.000Z");
|
|
@@ -40,9 +42,9 @@ describe("ISO8601DateTime", () => {
|
|
|
40
42
|
});
|
|
41
43
|
describe("ISO8601DateTime.getBrazilianIsoString()", () => {
|
|
42
44
|
it("Should return ISO string converted to Brazilian time.", () => {
|
|
43
|
-
const dateTime = new ISO8601DateTime({
|
|
44
|
-
date: new ISO8601Date("2025-01-02"),
|
|
45
|
-
time: new ISO8601Time("01:02:03"),
|
|
45
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
46
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
47
|
+
time: new ISO8601Time_1.ISO8601Time("01:02:03"),
|
|
46
48
|
});
|
|
47
49
|
const brazilianIsoString = dateTime.getBrazilianIsoString();
|
|
48
50
|
expect(brazilianIsoString).toBe("2025-01-02T01:02:03-03:00");
|
|
@@ -50,25 +52,25 @@ describe("ISO8601DateTime", () => {
|
|
|
50
52
|
});
|
|
51
53
|
describe("ISO8601DateTime.getIsoString()", () => {
|
|
52
54
|
it("Should return ISO UTC string if no arguments.", () => {
|
|
53
|
-
const dateTime = new ISO8601DateTime({
|
|
54
|
-
date: new ISO8601Date("2025-01-02"),
|
|
55
|
-
time: new ISO8601Time("03:01:02"),
|
|
55
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
56
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
57
|
+
time: new ISO8601Time_1.ISO8601Time("03:01:02"),
|
|
56
58
|
});
|
|
57
59
|
const utcIsoString = dateTime.getIsoString();
|
|
58
60
|
expect(utcIsoString).toBe("2025-01-02T03:01:02.000Z");
|
|
59
61
|
});
|
|
60
62
|
it("Should return ISO string +01:00 for London timezone.", () => {
|
|
61
|
-
const dateTime = new ISO8601DateTime({
|
|
62
|
-
date: new ISO8601Date("2025-01-02"),
|
|
63
|
-
time: new ISO8601Time("03:01:02"),
|
|
63
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
64
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
65
|
+
time: new ISO8601Time_1.ISO8601Time("03:01:02"),
|
|
64
66
|
});
|
|
65
67
|
const isoString = dateTime.getIsoString({ timezoneOffsetMinutes: 60 });
|
|
66
68
|
expect(isoString).toBe("2025-01-02T03:01:02+01:00");
|
|
67
69
|
});
|
|
68
70
|
it("Should return ISO string -05:00 for Chicago DST timezone.", () => {
|
|
69
|
-
const dateTime = new ISO8601DateTime({
|
|
70
|
-
date: new ISO8601Date("2025-01-02"),
|
|
71
|
-
time: new ISO8601Time("03:01:02"),
|
|
71
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
72
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
73
|
+
time: new ISO8601Time_1.ISO8601Time("03:01:02"),
|
|
72
74
|
});
|
|
73
75
|
const isoString = dateTime.getIsoString({
|
|
74
76
|
timezoneOffsetMinutes: -300,
|
|
@@ -76,9 +78,9 @@ describe("ISO8601DateTime", () => {
|
|
|
76
78
|
expect(isoString).toBe("2025-01-02T03:01:02-05:00");
|
|
77
79
|
});
|
|
78
80
|
it("Should return ISO string -03:00 for Brazilian timezone.", () => {
|
|
79
|
-
const dateTime = new ISO8601DateTime({
|
|
80
|
-
date: new ISO8601Date("2025-01-02"),
|
|
81
|
-
time: new ISO8601Time("03:01:02"),
|
|
81
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
82
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
83
|
+
time: new ISO8601Time_1.ISO8601Time("03:01:02"),
|
|
82
84
|
});
|
|
83
85
|
const isoString = dateTime.getIsoString({
|
|
84
86
|
timezoneOffsetMinutes: -180,
|
|
@@ -86,9 +88,9 @@ describe("ISO8601DateTime", () => {
|
|
|
86
88
|
expect(isoString).toBe("2025-01-02T03:01:02-03:00");
|
|
87
89
|
});
|
|
88
90
|
it("Should return ISO string -03:00 for Brazilian timezone derived from Date.", () => {
|
|
89
|
-
const dateTime = new ISO8601DateTime({
|
|
90
|
-
date: new ISO8601Date("2025-01-02"),
|
|
91
|
-
time: new ISO8601Time("03:01:02"),
|
|
91
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
92
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
93
|
+
time: new ISO8601Time_1.ISO8601Time("03:01:02"),
|
|
92
94
|
});
|
|
93
95
|
const isoString = dateTime.getIsoString({
|
|
94
96
|
timezoneOffsetMinutes: -new Date().getTimezoneOffset(),
|
|
@@ -96,47 +98,47 @@ describe("ISO8601DateTime", () => {
|
|
|
96
98
|
expect(isoString).toBe("2025-01-02T03:01:02-03:00");
|
|
97
99
|
});
|
|
98
100
|
it("Should accept newDate and properly output it.", () => {
|
|
99
|
-
const dateTime = new ISO8601DateTime({
|
|
100
|
-
date: new ISO8601Date("2025-01-02"),
|
|
101
|
-
time: new ISO8601Time("03:01:02"),
|
|
101
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
102
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
103
|
+
time: new ISO8601Time_1.ISO8601Time("03:01:02"),
|
|
102
104
|
});
|
|
103
105
|
const isoString = dateTime.getIsoString({
|
|
104
106
|
timezoneOffsetMinutes: -new Date().getTimezoneOffset(),
|
|
105
|
-
newDate: new ISO8601Date("2025-01-03"),
|
|
107
|
+
newDate: new ISO8601Date_1.ISO8601Date("2025-01-03"),
|
|
106
108
|
});
|
|
107
109
|
expect(isoString).toBe("2025-01-03T03:01:02-03:00");
|
|
108
110
|
});
|
|
109
111
|
it("Should accept newTime and properly output it.", () => {
|
|
110
|
-
const dateTime = new ISO8601DateTime({
|
|
111
|
-
date: new ISO8601Date("2025-01-02"),
|
|
112
|
-
time: new ISO8601Time("03:01:02"),
|
|
112
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
113
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
114
|
+
time: new ISO8601Time_1.ISO8601Time("03:01:02"),
|
|
113
115
|
});
|
|
114
116
|
const isoString = dateTime.getIsoString({
|
|
115
117
|
timezoneOffsetMinutes: -new Date().getTimezoneOffset(),
|
|
116
|
-
newTime: new ISO8601Time("03:01:03")
|
|
118
|
+
newTime: new ISO8601Time_1.ISO8601Time("03:01:03")
|
|
117
119
|
});
|
|
118
120
|
expect(isoString).toBe("2025-01-02T03:01:03-03:00");
|
|
119
121
|
});
|
|
120
122
|
it("Should accept newTime and newDate and properly output them.", () => {
|
|
121
|
-
const dateTime = new ISO8601DateTime({
|
|
122
|
-
date: new ISO8601Date("2025-01-02"),
|
|
123
|
-
time: new ISO8601Time("03:01:02"),
|
|
123
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
124
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
125
|
+
time: new ISO8601Time_1.ISO8601Time("03:01:02"),
|
|
124
126
|
});
|
|
125
127
|
const isoString = dateTime.getIsoString({
|
|
126
128
|
timezoneOffsetMinutes: -new Date().getTimezoneOffset(),
|
|
127
|
-
newTime: new ISO8601Time("03:01:03"),
|
|
128
|
-
newDate: new ISO8601Date("2025-01-03")
|
|
129
|
+
newTime: new ISO8601Time_1.ISO8601Time("03:01:03"),
|
|
130
|
+
newDate: new ISO8601Date_1.ISO8601Date("2025-01-03")
|
|
129
131
|
});
|
|
130
132
|
expect(isoString).toBe("2025-01-03T03:01:03-03:00");
|
|
131
133
|
});
|
|
132
134
|
it("Should accept newTime and newDate and properly output them, even when timezone is UTC.", () => {
|
|
133
|
-
const dateTime = new ISO8601DateTime({
|
|
134
|
-
date: new ISO8601Date("2025-01-02"),
|
|
135
|
-
time: new ISO8601Time("03:01:02"),
|
|
135
|
+
const dateTime = new ISO8601DateTime_1.ISO8601DateTime({
|
|
136
|
+
date: new ISO8601Date_1.ISO8601Date("2025-01-02"),
|
|
137
|
+
time: new ISO8601Time_1.ISO8601Time("03:01:02"),
|
|
136
138
|
});
|
|
137
139
|
const isoString = dateTime.getIsoString({
|
|
138
|
-
newTime: new ISO8601Time("03:01:03"),
|
|
139
|
-
newDate: new ISO8601Date("2025-01-03")
|
|
140
|
+
newTime: new ISO8601Time_1.ISO8601Time("03:01:03"),
|
|
141
|
+
newDate: new ISO8601Date_1.ISO8601Date("2025-01-03")
|
|
140
142
|
});
|
|
141
143
|
expect(isoString).toBe("2025-01-03T03:01:03.000Z");
|
|
142
144
|
});
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISO8601DateValidator = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Accepted format: YYYY-MM-DD
|
|
3
6
|
* @throws on construction if format is wrong
|
|
4
7
|
* @throws on get methods if format is wrong
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
class ISO8601DateValidator {
|
|
7
10
|
constructor() {
|
|
8
11
|
this.YYYYmmDD = new RegExp("^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])$");
|
|
9
12
|
}
|
|
@@ -14,3 +17,4 @@ export class ISO8601DateValidator {
|
|
|
14
17
|
return this.YYYYmmDD.test(date);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
20
|
+
exports.ISO8601DateValidator = ISO8601DateValidator;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ISO8601DateValidator_1 = require("./ISO8601DateValidator");
|
|
2
4
|
describe("ISO8601DateValidator", () => {
|
|
3
5
|
describe("ISO8601DateValidator.formatIsValid()", () => {
|
|
4
6
|
it("Should return true if format is YYYY-MM-DD.", () => {
|
|
5
|
-
const date = new ISO8601DateValidator();
|
|
7
|
+
const date = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
6
8
|
expect(date.formatIsValid("2025-01-01")).toBe(true);
|
|
7
9
|
});
|
|
8
10
|
it("Should return false if format is not YYYY-MM-DD.", () => {
|
|
9
|
-
const date = new ISO8601DateValidator();
|
|
11
|
+
const date = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
10
12
|
expect(date.formatIsValid("2025-01-011")).toBe(false);
|
|
11
13
|
});
|
|
12
14
|
});
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISO8601Time = void 0;
|
|
4
|
+
const ISO8601TimeValidator_1 = require("./ISO8601TimeValidator");
|
|
2
5
|
/**
|
|
3
6
|
* Interface for interacting with ISO8601 time formats.
|
|
4
7
|
* Accepted formats: HH:MM:SS and HH:MM.
|
|
@@ -6,13 +9,13 @@ import { ISO8601TimeValidator } from "./ISO8601TimeValidator";
|
|
|
6
9
|
* @throws if instantiated with a different format
|
|
7
10
|
* @throws if any method is called with a different format
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
class ISO8601Time {
|
|
10
13
|
/**
|
|
11
14
|
* Throws if format is invalid.
|
|
12
15
|
* Accepted formats: HH:MM:SS and HH:MM.
|
|
13
16
|
*/
|
|
14
17
|
constructor(value) {
|
|
15
|
-
this.validator = new ISO8601TimeValidator();
|
|
18
|
+
this.validator = new ISO8601TimeValidator_1.ISO8601TimeValidator();
|
|
16
19
|
this.getNow = ISO8601Time.getNow;
|
|
17
20
|
this.value = value ? value : this.getNow();
|
|
18
21
|
this.validateFormatOrThrow();
|
|
@@ -51,3 +54,4 @@ export class ISO8601Time {
|
|
|
51
54
|
return `${hours}:${minutes}:${seconds}`;
|
|
52
55
|
}
|
|
53
56
|
}
|
|
57
|
+
exports.ISO8601Time = ISO8601Time;
|