@eliasrrosa/tutorhub-public-assets 0.0.1 → 0.0.2
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.d.ts +14 -0
- package/dist/domain/entities/AsaasCustomer.js +13 -0
- package/dist/domain/entities/Class.d.ts +79 -0
- package/dist/domain/entities/Class.js +30 -0
- package/dist/domain/entities/ClassRequest.d.ts +15 -0
- package/dist/domain/entities/ClassRequest.js +2 -0
- package/dist/domain/entities/Contract.d.ts +40 -0
- package/dist/domain/entities/Contract.js +2 -0
- package/dist/domain/entities/Course.d.ts +34 -0
- package/dist/domain/entities/Course.js +2 -0
- package/dist/domain/entities/CourseToSchoolConnectionRequest.d.ts +10 -0
- package/dist/domain/entities/CourseToSchoolConnectionRequest.js +2 -0
- package/dist/domain/entities/Date.d.ts +56 -0
- package/dist/domain/entities/Date.js +2 -0
- package/dist/domain/entities/Date.test.d.ts +0 -0
- package/dist/domain/entities/Date.test.js +23 -0
- package/dist/domain/entities/DateTimeSlot.d.ts +6 -0
- package/dist/domain/entities/DateTimeSlot.js +2 -0
- package/dist/domain/entities/DateValidator.d.ts +3 -0
- package/dist/domain/entities/DateValidator.js +2 -0
- package/dist/domain/entities/File.d.ts +23 -0
- package/dist/domain/entities/File.js +2 -0
- package/dist/domain/entities/FreeTimeSlot.d.ts +19 -0
- package/dist/domain/entities/FreeTimeSlot.js +12 -0
- package/dist/domain/entities/GenericNotification.d.ts +11 -0
- package/dist/domain/entities/GenericNotification.js +2 -0
- package/dist/domain/entities/GoogleAuth.d.ts +8 -0
- package/dist/domain/entities/GoogleAuth.js +2 -0
- package/dist/domain/entities/GoogleCalendar.d.ts +10 -0
- package/dist/domain/entities/GoogleCalendar.js +2 -0
- package/dist/domain/entities/GoogleCalendarEvent.d.ts +10 -0
- package/dist/domain/entities/GoogleCalendarEvent.js +2 -0
- package/dist/domain/entities/ISO8601Date.d.ts +35 -0
- package/dist/domain/entities/ISO8601Date.js +86 -0
- package/dist/domain/entities/ISO8601Date.test.d.ts +1 -0
- package/dist/domain/entities/ISO8601Date.test.js +210 -0
- package/dist/domain/entities/ISO8601DateTime.d.ts +41 -0
- package/dist/domain/entities/ISO8601DateTime.js +44 -0
- package/dist/domain/entities/ISO8601DateTime.test.d.ts +1 -0
- package/dist/domain/entities/ISO8601DateTime.test.js +146 -0
- package/dist/domain/entities/ISO8601DateValidator.d.ts +13 -0
- package/dist/domain/entities/ISO8601DateValidator.js +20 -0
- package/dist/domain/entities/ISO8601DateValidator.test.d.ts +1 -0
- package/dist/domain/entities/ISO8601DateValidator.test.js +15 -0
- package/dist/domain/entities/ISO8601Time.d.ts +25 -0
- package/dist/domain/entities/ISO8601Time.js +57 -0
- package/dist/domain/entities/ISO8601Time.test.d.ts +1 -0
- package/dist/domain/entities/ISO8601Time.test.js +63 -0
- package/dist/domain/entities/ISO8601TimeValidator.d.ts +12 -0
- package/dist/domain/entities/ISO8601TimeValidator.js +19 -0
- package/dist/domain/entities/ISO8601TimeValidator.test.d.ts +1 -0
- package/dist/domain/entities/ISO8601TimeValidator.test.js +42 -0
- package/dist/domain/entities/PasswordRecovery.d.ts +6 -0
- package/dist/domain/entities/PasswordRecovery.js +2 -0
- package/dist/domain/entities/Payment.d.ts +42 -0
- package/dist/domain/entities/Payment.js +2 -0
- package/dist/domain/entities/PaymentRecognitionRequest.d.ts +12 -0
- package/dist/domain/entities/PaymentRecognitionRequest.js +2 -0
- package/dist/domain/entities/PreApprovedUser.d.ts +12 -0
- package/dist/domain/entities/PreApprovedUser.js +2 -0
- package/dist/domain/entities/RescheduleRequest.d.ts +16 -0
- package/dist/domain/entities/RescheduleRequest.js +2 -0
- package/dist/domain/entities/School.d.ts +31 -0
- package/dist/domain/entities/School.js +2 -0
- package/dist/domain/entities/SchoolConnection.d.ts +10 -0
- package/dist/domain/entities/SchoolConnection.js +2 -0
- package/dist/domain/entities/SchoolConnectionRequest.d.ts +7 -0
- package/dist/domain/entities/SchoolConnectionRequest.js +2 -0
- package/dist/domain/entities/SchoolStudent.d.ts +14 -0
- package/dist/domain/entities/SchoolStudent.js +2 -0
- package/dist/domain/entities/SchoolTeacher.d.ts +14 -0
- package/dist/domain/entities/SchoolTeacher.js +2 -0
- package/dist/domain/entities/Time.d.ts +9 -0
- package/dist/domain/entities/Time.js +2 -0
- package/dist/domain/entities/TimeSlot.d.ts +4 -0
- package/dist/domain/entities/TimeSlot.js +2 -0
- package/dist/domain/entities/TimeValidator.d.ts +3 -0
- package/dist/domain/entities/TimeValidator.js +2 -0
- package/dist/domain/entities/UnauthorizedUser.d.ts +16 -0
- package/dist/domain/entities/UnauthorizedUser.js +2 -0
- package/dist/domain/entities/UserAuth.d.ts +72 -0
- package/dist/domain/entities/UserAuth.js +2 -0
- package/dist/domain/entities/UserConnection.d.ts +8 -0
- package/dist/domain/entities/UserConnection.js +2 -0
- package/dist/domain/entities/UserConnectionRequest.d.ts +9 -0
- package/dist/domain/entities/UserConnectionRequest.js +2 -0
- package/dist/domain/entities/UserCredentials.d.ts +16 -0
- package/dist/domain/entities/UserCredentials.js +11 -0
- package/dist/domain/entities/UserNavigation.d.ts +8 -0
- package/dist/domain/entities/UserNavigation.js +2 -0
- package/dist/domain/entities/UserPreferences.d.ts +6 -0
- package/dist/domain/entities/UserPreferences.js +2 -0
- package/dist/domain/entities/UserPremium.d.ts +13 -0
- package/dist/domain/entities/UserPremium.js +2 -0
- package/dist/domain/entities/UserProfile.d.ts +9 -0
- package/dist/domain/entities/UserProfile.js +2 -0
- package/dist/domain/entities/UserRoles.d.ts +11 -0
- package/dist/domain/entities/UserRoles.js +2 -0
- package/dist/domain/entities/UserSharedFileTimestamps.d.ts +9 -0
- package/dist/domain/entities/UserSharedFileTimestamps.js +2 -0
- package/dist/domain/entities/UserUnavailableTime.d.ts +49 -0
- package/dist/domain/entities/UserUnavailableTime.js +32 -0
- package/dist/domain/entities/UserUnavailableTime.test.d.ts +1 -0
- package/dist/domain/entities/UserUnavailableTime.test.js +22 -0
- package/dist/domain/repositories/UnavailableTimeRepository.d.ts +20 -0
- package/dist/domain/repositories/UnavailableTimeRepository.js +2 -0
- package/dist/restful/responses/GetFixedAvailableTimesResponseBody.d.ts +4 -0
- package/dist/restful/responses/GetFixedAvailableTimesResponseBody.js +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ISO8601Date_1 = require("./ISO8601Date");
|
|
4
|
+
describe("ISO8601Date", () => {
|
|
5
|
+
describe("ISO8601Date constructor", () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
jest.useFakeTimers().setSystemTime(new Date("2025-01-01T23:00:00-03:00"));
|
|
8
|
+
});
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
jest.useRealTimers();
|
|
11
|
+
});
|
|
12
|
+
it("Should construct if date is valid", () => {
|
|
13
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01");
|
|
14
|
+
expect(date.value).toBe("2025-01-01");
|
|
15
|
+
});
|
|
16
|
+
it("Should throw if value is not valid", () => {
|
|
17
|
+
const instantiateDate = () => {
|
|
18
|
+
new ISO8601Date_1.ISO8601Date("2025-01-011");
|
|
19
|
+
};
|
|
20
|
+
expect(instantiateDate).toThrow();
|
|
21
|
+
});
|
|
22
|
+
it("Should construct with no arguments.", () => {
|
|
23
|
+
const date = new ISO8601Date_1.ISO8601Date();
|
|
24
|
+
expect(date).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
it("Should have value set as today when constructed with no arguments.", () => {
|
|
27
|
+
const date = new ISO8601Date_1.ISO8601Date();
|
|
28
|
+
expect(date.value).toBe("2025-01-01");
|
|
29
|
+
const validateFormat = () => {
|
|
30
|
+
return date.validator.formatIsValid(date.value);
|
|
31
|
+
};
|
|
32
|
+
expect(validateFormat).not.toThrow();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe("ISO8601Date.getDay()", () => {
|
|
36
|
+
it("Should return the day if format is valid.", () => {
|
|
37
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
38
|
+
expect(date.getDay()).toBe("02");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("ISO8601Date.getMonth()", () => {
|
|
42
|
+
it("Should return the month if format is valid.", () => {
|
|
43
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
44
|
+
expect(date.getMonth()).toBe("01");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe("ISO8601Date.getYear()", () => {
|
|
48
|
+
it("Should return the year if format is valid.", () => {
|
|
49
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
50
|
+
expect(date.getYear()).toBe("2025");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe("ISO8601Date.addDays()", () => {
|
|
54
|
+
it("Should add days resulting in the same month", () => {
|
|
55
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
56
|
+
expect(date.addDays(10).value).toBe("2025-01-12");
|
|
57
|
+
});
|
|
58
|
+
it("Should add days resulting in the next month", () => {
|
|
59
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01");
|
|
60
|
+
expect(date.addDays(31).value).toBe("2025-02-01");
|
|
61
|
+
});
|
|
62
|
+
it("Should add days resulting in multiple months ahead", () => {
|
|
63
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
64
|
+
expect(date.addDays(31 + 30 + 31 + 3).value).toBe("2025-06-04");
|
|
65
|
+
});
|
|
66
|
+
it("Should add days resulting in multiple months ahead", () => {
|
|
67
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
68
|
+
expect(date.addDays(31 + 30 + 31 + 3).value).toBe("2025-06-04");
|
|
69
|
+
});
|
|
70
|
+
it("Should be chainable.", () => {
|
|
71
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
72
|
+
expect(date.addDays(31).addDays(30).addDays(31).addDays(3).value).toBe("2025-06-04");
|
|
73
|
+
});
|
|
74
|
+
it("Should accept negative values", () => {
|
|
75
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-02");
|
|
76
|
+
expect(date.addDays(-1).value).toBe("2025-03-01");
|
|
77
|
+
});
|
|
78
|
+
describe("ISO8601Date.addDays() in a timezone ahead of UTC", () => {
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
jest
|
|
81
|
+
.useFakeTimers()
|
|
82
|
+
.setSystemTime(new Date("2025-01-01T23:00:00+03:00"));
|
|
83
|
+
});
|
|
84
|
+
afterEach(() => {
|
|
85
|
+
jest.useRealTimers();
|
|
86
|
+
});
|
|
87
|
+
it("Should add days resulting in the same month", () => {
|
|
88
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-02");
|
|
89
|
+
expect(date.addDays(10).value).toBe("2025-01-12");
|
|
90
|
+
});
|
|
91
|
+
it("Should add days resulting in the next month", () => {
|
|
92
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01");
|
|
93
|
+
expect(date.addDays(31).value).toBe("2025-02-01");
|
|
94
|
+
});
|
|
95
|
+
it("Should add days resulting in multiple months ahead", () => {
|
|
96
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
97
|
+
expect(date.addDays(31 + 30 + 31 + 3).value).toBe("2025-06-04");
|
|
98
|
+
});
|
|
99
|
+
it("Should add days resulting in multiple months ahead", () => {
|
|
100
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
101
|
+
expect(date.addDays(31 + 30 + 31 + 3).value).toBe("2025-06-04");
|
|
102
|
+
});
|
|
103
|
+
it("Should be chainable.", () => {
|
|
104
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-03-01");
|
|
105
|
+
expect(date.addDays(31).addDays(30).addDays(31).addDays(3).value).toBe("2025-06-04");
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
describe("ISO8601Date.jsDateTimeToDate()", () => {
|
|
110
|
+
it("Should return an IDate instance", () => {
|
|
111
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date(2025, 5, 4))).toBeInstanceOf(ISO8601Date_1.ISO8601Date);
|
|
112
|
+
});
|
|
113
|
+
it("Should return expected value in ISO8601 format.", () => {
|
|
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");
|
|
116
|
+
});
|
|
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.", () => {
|
|
118
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date("2025-06-04")).value).toBe("2025-06-03");
|
|
119
|
+
});
|
|
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.", () => {
|
|
121
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date("2025-06-04T00:00:00Z")).value).toBe("2025-06-03");
|
|
122
|
+
});
|
|
123
|
+
it("If js date is in UTC and useUtc param is true, should return utc date.", () => {
|
|
124
|
+
expect(ISO8601Date_1.ISO8601Date.jsDateTimeToDate(new Date("2025-06-04T00:00:00Z"), {
|
|
125
|
+
useUtc: true,
|
|
126
|
+
}).value).toBe("2025-06-04");
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
describe("ISO8601Date.getToday()", () => {
|
|
130
|
+
afterEach(() => {
|
|
131
|
+
jest.useRealTimers();
|
|
132
|
+
});
|
|
133
|
+
it("Should return today's date properly with different timezones", () => {
|
|
134
|
+
jest.useFakeTimers().setSystemTime(new Date("2025-01-01T23:00:00-03:00"));
|
|
135
|
+
expect(ISO8601Date_1.ISO8601Date.getToday()).toBe("2025-01-01");
|
|
136
|
+
jest.setSystemTime(new Date("2025-01-02T23:00:00+03:00"));
|
|
137
|
+
expect(ISO8601Date_1.ISO8601Date.getToday()).toBe("2025-01-02");
|
|
138
|
+
jest.setSystemTime(new Date("2025-01-04T23:00:00+12:00"));
|
|
139
|
+
expect(ISO8601Date_1.ISO8601Date.getToday()).toBe("2025-01-04");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe("ISO8601Date.toLocalJsDateTime()", () => {
|
|
143
|
+
it("Should return js date time of same day, month and year, considering local time.", () => {
|
|
144
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01").toLocalJsDateTime();
|
|
145
|
+
expect(date.getMonth()).toEqual(0);
|
|
146
|
+
expect(date.getDate()).toEqual(1);
|
|
147
|
+
expect(date.getFullYear()).toEqual(2025);
|
|
148
|
+
expect(date.getHours()).toEqual(0);
|
|
149
|
+
expect(date.getMinutes()).toEqual(0);
|
|
150
|
+
expect(date.getSeconds()).toEqual(0);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe("ISO8601Date.toUtcJsDateTime()", () => {
|
|
154
|
+
afterEach(() => {
|
|
155
|
+
jest.useRealTimers();
|
|
156
|
+
});
|
|
157
|
+
it("Should return js date time of same day, month and year, considering utc time.", () => {
|
|
158
|
+
jest.useFakeTimers().setSystemTime(new Date("2025-01-01T00:00:00Z"));
|
|
159
|
+
const date = new ISO8601Date_1.ISO8601Date("2025-01-01").toUtcJsDateTime();
|
|
160
|
+
expect(date).toBeInstanceOf(Date);
|
|
161
|
+
expect(date.getUTCMonth()).toEqual(0);
|
|
162
|
+
expect(date.getUTCDate()).toEqual(1);
|
|
163
|
+
expect(date.getUTCFullYear()).toEqual(2025);
|
|
164
|
+
expect(date.getUTCHours()).toEqual(0);
|
|
165
|
+
expect(date.getUTCMinutes()).toEqual(0);
|
|
166
|
+
expect(date.getUTCSeconds()).toEqual(0);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe("ISO8601Date.getDaysSinceEpoch()", () => {
|
|
170
|
+
it("Should return expected days count", () => {
|
|
171
|
+
const days = new ISO8601Date_1.ISO8601Date("1970-01-02").getDaysSinceEpoch();
|
|
172
|
+
expect(days).toEqual(1);
|
|
173
|
+
});
|
|
174
|
+
it("From a UTC date, should return expected days count", () => {
|
|
175
|
+
const utcDate = new Date("1970-01-02T00:00:00Z");
|
|
176
|
+
const days = new ISO8601Date_1.ISO8601Date()
|
|
177
|
+
.jsDateTimeToDate(utcDate, { useUtc: true })
|
|
178
|
+
.getDaysSinceEpoch();
|
|
179
|
+
expect(days).toEqual(1);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe("ISO8601Date.getDayOfTheWeek()", () => {
|
|
183
|
+
afterEach(() => {
|
|
184
|
+
jest.useRealTimers();
|
|
185
|
+
});
|
|
186
|
+
jest.useFakeTimers().setSystemTime(new Date("2025-04-21"));
|
|
187
|
+
const today = new ISO8601Date_1.ISO8601Date();
|
|
188
|
+
it("Should return 0 for Monday.", () => {
|
|
189
|
+
expect(today.getDayOfTheWeek()).toEqual(0);
|
|
190
|
+
});
|
|
191
|
+
it("Should return 1 for Tuesday.", () => {
|
|
192
|
+
expect(today.addDays(1).getDayOfTheWeek()).toEqual(1);
|
|
193
|
+
});
|
|
194
|
+
it("Should return 2 for Wednesday.", () => {
|
|
195
|
+
expect(today.addDays(2).getDayOfTheWeek()).toEqual(2);
|
|
196
|
+
});
|
|
197
|
+
it("Should return 3 for Thursday.", () => {
|
|
198
|
+
expect(today.addDays(3).getDayOfTheWeek()).toEqual(3);
|
|
199
|
+
});
|
|
200
|
+
it("Should return 4 for Friday.", () => {
|
|
201
|
+
expect(today.addDays(4).getDayOfTheWeek()).toEqual(4);
|
|
202
|
+
});
|
|
203
|
+
it("Should return 5 for Saturday.", () => {
|
|
204
|
+
expect(today.addDays(5).getDayOfTheWeek()).toEqual(5);
|
|
205
|
+
});
|
|
206
|
+
it("Should return 6 for Sunday.", () => {
|
|
207
|
+
expect(today.addDays(6).getDayOfTheWeek()).toEqual(6);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IDate } from "./Date";
|
|
2
|
+
import { ITime } from "./Time";
|
|
3
|
+
export interface IDateTime {
|
|
4
|
+
date: IDate;
|
|
5
|
+
time: ITime;
|
|
6
|
+
getJSDateTime: () => Date;
|
|
7
|
+
/**
|
|
8
|
+
* Returns DateTime string with added Brazilian timezone (-03:00) without converting the date or time.
|
|
9
|
+
* This function is analogous to ISO8601DateTime.getIsoString(-180)
|
|
10
|
+
* @returns an ISO8601 string with Brazilian timezone
|
|
11
|
+
*/
|
|
12
|
+
getBrazilianIsoString: () => string;
|
|
13
|
+
/**
|
|
14
|
+
* Returns DateTime string with added timezone (eg. +03:00, -01:00, .000Z) without converting the date or time.
|
|
15
|
+
* @param timezoneOffsetMinutes defaults to 0.
|
|
16
|
+
* Can be derived from the negative return value of Date.getTimezoneOffset()
|
|
17
|
+
* @param newDate overrides the date for the output string, but does not change state.
|
|
18
|
+
* @param newTime overrides the time for the output string, but does not change state.
|
|
19
|
+
* @returns an ISO8601 string with the added timezone.
|
|
20
|
+
*/
|
|
21
|
+
getIsoString: (opts?: {
|
|
22
|
+
timezoneOffsetMinutes?: number;
|
|
23
|
+
newDate?: IDate;
|
|
24
|
+
newTime?: ITime;
|
|
25
|
+
}) => string;
|
|
26
|
+
}
|
|
27
|
+
export declare class ISO8601DateTime implements IDateTime {
|
|
28
|
+
date: IDate;
|
|
29
|
+
time: ITime;
|
|
30
|
+
constructor(opts: {
|
|
31
|
+
date: IDate;
|
|
32
|
+
time: ITime;
|
|
33
|
+
});
|
|
34
|
+
getJSDateTime: () => Date;
|
|
35
|
+
getBrazilianIsoString: () => string;
|
|
36
|
+
getIsoString(opts?: {
|
|
37
|
+
timezoneOffsetMinutes?: number;
|
|
38
|
+
newDate?: IDate;
|
|
39
|
+
newTime?: ITime;
|
|
40
|
+
}): string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISO8601DateTime = void 0;
|
|
4
|
+
class ISO8601DateTime {
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
this.getJSDateTime = () => {
|
|
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()));
|
|
8
|
+
};
|
|
9
|
+
this.getBrazilianIsoString = () => {
|
|
10
|
+
return this.getIsoString({
|
|
11
|
+
timezoneOffsetMinutes: -180,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
this.date = opts.date;
|
|
15
|
+
this.time = opts.time;
|
|
16
|
+
}
|
|
17
|
+
getIsoString(opts) {
|
|
18
|
+
const padLeft = (n) => String(n).padStart(2, "0");
|
|
19
|
+
const newDateTime = new ISO8601DateTime({
|
|
20
|
+
date: (opts === null || opts === void 0 ? void 0 : opts.newDate) || this.date,
|
|
21
|
+
time: (opts === null || opts === void 0 ? void 0 : opts.newTime) || this.time,
|
|
22
|
+
});
|
|
23
|
+
const jsDate = newDateTime.getJSDateTime();
|
|
24
|
+
const year = jsDate.getFullYear();
|
|
25
|
+
const month = padLeft(jsDate.getMonth() + 1);
|
|
26
|
+
const day = padLeft(jsDate.getDate());
|
|
27
|
+
const hour = padLeft(jsDate.getHours());
|
|
28
|
+
const minute = padLeft(jsDate.getMinutes());
|
|
29
|
+
const second = padLeft(jsDate.getSeconds());
|
|
30
|
+
const timezoneOffsetMinutes = (opts === null || opts === void 0 ? void 0 : opts.timezoneOffsetMinutes)
|
|
31
|
+
? opts.timezoneOffsetMinutes
|
|
32
|
+
: 0;
|
|
33
|
+
const sign = timezoneOffsetMinutes == 0
|
|
34
|
+
? undefined
|
|
35
|
+
: timezoneOffsetMinutes < 0
|
|
36
|
+
? "-"
|
|
37
|
+
: "+";
|
|
38
|
+
const offsetHours = padLeft(Math.floor(Math.abs(timezoneOffsetMinutes) / 60));
|
|
39
|
+
const offsetMinutes = padLeft(Math.abs(timezoneOffsetMinutes) % 60);
|
|
40
|
+
const timezone = sign ? `${sign}${offsetHours}:${offsetMinutes}` : ".000Z";
|
|
41
|
+
return `${year}-${month}-${day}T${hour}:${minute}:${second}${timezone}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ISO8601DateTime = ISO8601DateTime;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
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");
|
|
6
|
+
describe("ISO8601DateTime", () => {
|
|
7
|
+
describe("ISO8601DateTime getJSDateTime()", () => {
|
|
8
|
+
it("Should return a JS Date object.", () => {
|
|
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"),
|
|
12
|
+
});
|
|
13
|
+
const jsDateTime = dateTime.getJSDateTime();
|
|
14
|
+
expect(jsDateTime).toBeInstanceOf(Date);
|
|
15
|
+
});
|
|
16
|
+
it("Should return the same year, month and day when returning UTC date.", () => {
|
|
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"),
|
|
20
|
+
});
|
|
21
|
+
const jsDateTime = dateTime.getJSDateTime();
|
|
22
|
+
expect(jsDateTime.getUTCDate()).toBe(2);
|
|
23
|
+
expect(jsDateTime.getUTCMonth()).toBe(0);
|
|
24
|
+
expect(jsDateTime.getUTCFullYear()).toBe(2025);
|
|
25
|
+
});
|
|
26
|
+
it("Should return locale date string of same date and time as constructed.", () => {
|
|
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"),
|
|
30
|
+
});
|
|
31
|
+
const jsDateTime = dateTime.getJSDateTime();
|
|
32
|
+
expect(jsDateTime.toLocaleDateString("pt-BR")).toBe("02/01/2025");
|
|
33
|
+
});
|
|
34
|
+
it("Should return ISO string converted to UTC.", () => {
|
|
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"),
|
|
38
|
+
});
|
|
39
|
+
const jsDateTime = dateTime.getJSDateTime();
|
|
40
|
+
expect(jsDateTime.toISOString()).toBe("2025-01-02T04:02:03.000Z");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe("ISO8601DateTime.getBrazilianIsoString()", () => {
|
|
44
|
+
it("Should return ISO string converted to Brazilian time.", () => {
|
|
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"),
|
|
48
|
+
});
|
|
49
|
+
const brazilianIsoString = dateTime.getBrazilianIsoString();
|
|
50
|
+
expect(brazilianIsoString).toBe("2025-01-02T01:02:03-03:00");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe("ISO8601DateTime.getIsoString()", () => {
|
|
54
|
+
it("Should return ISO UTC string if no arguments.", () => {
|
|
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"),
|
|
58
|
+
});
|
|
59
|
+
const utcIsoString = dateTime.getIsoString();
|
|
60
|
+
expect(utcIsoString).toBe("2025-01-02T03:01:02.000Z");
|
|
61
|
+
});
|
|
62
|
+
it("Should return ISO string +01:00 for London timezone.", () => {
|
|
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"),
|
|
66
|
+
});
|
|
67
|
+
const isoString = dateTime.getIsoString({ timezoneOffsetMinutes: 60 });
|
|
68
|
+
expect(isoString).toBe("2025-01-02T03:01:02+01:00");
|
|
69
|
+
});
|
|
70
|
+
it("Should return ISO string -05:00 for Chicago DST timezone.", () => {
|
|
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"),
|
|
74
|
+
});
|
|
75
|
+
const isoString = dateTime.getIsoString({
|
|
76
|
+
timezoneOffsetMinutes: -300,
|
|
77
|
+
});
|
|
78
|
+
expect(isoString).toBe("2025-01-02T03:01:02-05:00");
|
|
79
|
+
});
|
|
80
|
+
it("Should return ISO string -03:00 for Brazilian timezone.", () => {
|
|
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"),
|
|
84
|
+
});
|
|
85
|
+
const isoString = dateTime.getIsoString({
|
|
86
|
+
timezoneOffsetMinutes: -180,
|
|
87
|
+
});
|
|
88
|
+
expect(isoString).toBe("2025-01-02T03:01:02-03:00");
|
|
89
|
+
});
|
|
90
|
+
it("Should return ISO string -03:00 for Brazilian timezone derived from Date.", () => {
|
|
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"),
|
|
94
|
+
});
|
|
95
|
+
const isoString = dateTime.getIsoString({
|
|
96
|
+
timezoneOffsetMinutes: -new Date().getTimezoneOffset(),
|
|
97
|
+
});
|
|
98
|
+
expect(isoString).toBe("2025-01-02T03:01:02-03:00");
|
|
99
|
+
});
|
|
100
|
+
it("Should accept newDate and properly output it.", () => {
|
|
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"),
|
|
104
|
+
});
|
|
105
|
+
const isoString = dateTime.getIsoString({
|
|
106
|
+
timezoneOffsetMinutes: -new Date().getTimezoneOffset(),
|
|
107
|
+
newDate: new ISO8601Date_1.ISO8601Date("2025-01-03"),
|
|
108
|
+
});
|
|
109
|
+
expect(isoString).toBe("2025-01-03T03:01:02-03:00");
|
|
110
|
+
});
|
|
111
|
+
it("Should accept newTime and properly output it.", () => {
|
|
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"),
|
|
115
|
+
});
|
|
116
|
+
const isoString = dateTime.getIsoString({
|
|
117
|
+
timezoneOffsetMinutes: -new Date().getTimezoneOffset(),
|
|
118
|
+
newTime: new ISO8601Time_1.ISO8601Time("03:01:03")
|
|
119
|
+
});
|
|
120
|
+
expect(isoString).toBe("2025-01-02T03:01:03-03:00");
|
|
121
|
+
});
|
|
122
|
+
it("Should accept newTime and newDate and properly output them.", () => {
|
|
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"),
|
|
126
|
+
});
|
|
127
|
+
const isoString = dateTime.getIsoString({
|
|
128
|
+
timezoneOffsetMinutes: -new Date().getTimezoneOffset(),
|
|
129
|
+
newTime: new ISO8601Time_1.ISO8601Time("03:01:03"),
|
|
130
|
+
newDate: new ISO8601Date_1.ISO8601Date("2025-01-03")
|
|
131
|
+
});
|
|
132
|
+
expect(isoString).toBe("2025-01-03T03:01:03-03:00");
|
|
133
|
+
});
|
|
134
|
+
it("Should accept newTime and newDate and properly output them, even when timezone is UTC.", () => {
|
|
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"),
|
|
138
|
+
});
|
|
139
|
+
const isoString = dateTime.getIsoString({
|
|
140
|
+
newTime: new ISO8601Time_1.ISO8601Time("03:01:03"),
|
|
141
|
+
newDate: new ISO8601Date_1.ISO8601Date("2025-01-03")
|
|
142
|
+
});
|
|
143
|
+
expect(isoString).toBe("2025-01-03T03:01:03.000Z");
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IDateValidator } from "./DateValidator";
|
|
2
|
+
/**
|
|
3
|
+
* Accepted format: YYYY-MM-DD
|
|
4
|
+
* @throws on construction if format is wrong
|
|
5
|
+
* @throws on get methods if format is wrong
|
|
6
|
+
*/
|
|
7
|
+
export declare class ISO8601DateValidator implements IDateValidator {
|
|
8
|
+
private YYYYmmDD;
|
|
9
|
+
/**
|
|
10
|
+
* Accepted format: YYYY-MM-DD
|
|
11
|
+
*/
|
|
12
|
+
formatIsValid(date: string): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISO8601DateValidator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Accepted format: YYYY-MM-DD
|
|
6
|
+
* @throws on construction if format is wrong
|
|
7
|
+
* @throws on get methods if format is wrong
|
|
8
|
+
*/
|
|
9
|
+
class ISO8601DateValidator {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.YYYYmmDD = new RegExp("^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])$");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Accepted format: YYYY-MM-DD
|
|
15
|
+
*/
|
|
16
|
+
formatIsValid(date) {
|
|
17
|
+
return this.YYYYmmDD.test(date);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ISO8601DateValidator = ISO8601DateValidator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ISO8601DateValidator_1 = require("./ISO8601DateValidator");
|
|
4
|
+
describe("ISO8601DateValidator", () => {
|
|
5
|
+
describe("ISO8601DateValidator.formatIsValid()", () => {
|
|
6
|
+
it("Should return true if format is YYYY-MM-DD.", () => {
|
|
7
|
+
const date = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
8
|
+
expect(date.formatIsValid("2025-01-01")).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
it("Should return false if format is not YYYY-MM-DD.", () => {
|
|
11
|
+
const date = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
12
|
+
expect(date.formatIsValid("2025-01-011")).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IISO8601TimeValidator } from "./ISO8601TimeValidator";
|
|
2
|
+
import { ITime } from "./Time";
|
|
3
|
+
/**
|
|
4
|
+
* Interface for interacting with ISO8601 time formats.
|
|
5
|
+
* Accepted formats: HH:MM:SS and HH:MM.
|
|
6
|
+
*
|
|
7
|
+
* @throws if instantiated with a different format
|
|
8
|
+
* @throws if any method is called with a different format
|
|
9
|
+
*/
|
|
10
|
+
export declare class ISO8601Time implements ITime {
|
|
11
|
+
readonly value: string;
|
|
12
|
+
readonly validator: IISO8601TimeValidator;
|
|
13
|
+
/**
|
|
14
|
+
* Throws if format is invalid.
|
|
15
|
+
* Accepted formats: HH:MM:SS and HH:MM.
|
|
16
|
+
*/
|
|
17
|
+
constructor(value?: string);
|
|
18
|
+
private validateFormatOrThrow;
|
|
19
|
+
getTime(): string;
|
|
20
|
+
getMinutes(): string;
|
|
21
|
+
getHours(): string;
|
|
22
|
+
getSeconds(): string;
|
|
23
|
+
static getNow(): string;
|
|
24
|
+
getNow: typeof ISO8601Time.getNow;
|
|
25
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISO8601Time = void 0;
|
|
4
|
+
const ISO8601TimeValidator_1 = require("./ISO8601TimeValidator");
|
|
5
|
+
/**
|
|
6
|
+
* Interface for interacting with ISO8601 time formats.
|
|
7
|
+
* Accepted formats: HH:MM:SS and HH:MM.
|
|
8
|
+
*
|
|
9
|
+
* @throws if instantiated with a different format
|
|
10
|
+
* @throws if any method is called with a different format
|
|
11
|
+
*/
|
|
12
|
+
class ISO8601Time {
|
|
13
|
+
/**
|
|
14
|
+
* Throws if format is invalid.
|
|
15
|
+
* Accepted formats: HH:MM:SS and HH:MM.
|
|
16
|
+
*/
|
|
17
|
+
constructor(value) {
|
|
18
|
+
this.validator = new ISO8601TimeValidator_1.ISO8601TimeValidator();
|
|
19
|
+
this.getNow = ISO8601Time.getNow;
|
|
20
|
+
this.value = value ? value : this.getNow();
|
|
21
|
+
this.validateFormatOrThrow();
|
|
22
|
+
}
|
|
23
|
+
validateFormatOrThrow() {
|
|
24
|
+
if (!this.validator.formatIsValid(this.value))
|
|
25
|
+
throw new Error("Time format must be ISO8601.");
|
|
26
|
+
}
|
|
27
|
+
getTime() {
|
|
28
|
+
this.validateFormatOrThrow();
|
|
29
|
+
if (this.validator.isHHmm(this.value)) {
|
|
30
|
+
return `${this.value}:00`;
|
|
31
|
+
}
|
|
32
|
+
return this.value;
|
|
33
|
+
}
|
|
34
|
+
getMinutes() {
|
|
35
|
+
this.validateFormatOrThrow();
|
|
36
|
+
return this.value.split(":")[1];
|
|
37
|
+
}
|
|
38
|
+
getHours() {
|
|
39
|
+
this.validateFormatOrThrow();
|
|
40
|
+
return this.value.split(":")[0];
|
|
41
|
+
}
|
|
42
|
+
getSeconds() {
|
|
43
|
+
this.validateFormatOrThrow();
|
|
44
|
+
const seconds = this.value.split(":")[2];
|
|
45
|
+
if (seconds)
|
|
46
|
+
return seconds;
|
|
47
|
+
return "00";
|
|
48
|
+
}
|
|
49
|
+
static getNow() {
|
|
50
|
+
const nowDate = new Date();
|
|
51
|
+
const hours = nowDate.getHours().toString().padStart(2, "0");
|
|
52
|
+
const minutes = nowDate.getMinutes().toString().padStart(2, "0");
|
|
53
|
+
const seconds = nowDate.getSeconds().toString().padStart(2, "0");
|
|
54
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.ISO8601Time = ISO8601Time;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ISO8601Time_1 = require("./ISO8601Time");
|
|
4
|
+
describe("ISO8601Time", () => {
|
|
5
|
+
beforeAll(() => {
|
|
6
|
+
jest.useFakeTimers({
|
|
7
|
+
now: new Date("2025-01-01T23:00:00-03:00"),
|
|
8
|
+
legacyFakeTimers: false,
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
afterAll(() => {
|
|
12
|
+
jest.useRealTimers();
|
|
13
|
+
});
|
|
14
|
+
describe("ISO8601Time constructor", () => {
|
|
15
|
+
it("Should construct with no arguments.", () => {
|
|
16
|
+
const time = new ISO8601Time_1.ISO8601Time();
|
|
17
|
+
expect(time).toBeDefined();
|
|
18
|
+
});
|
|
19
|
+
it("Should construct with now time when receiving no arguments.", () => {
|
|
20
|
+
const time = new ISO8601Time_1.ISO8601Time();
|
|
21
|
+
expect(time.value).toBe("23:00:00");
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe("ISO8601Time.getNow()", () => {
|
|
25
|
+
it("Should get now time.", () => {
|
|
26
|
+
expect(ISO8601Time_1.ISO8601Time.getNow()).toBe("23:00:00");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe("ISO8601Time.getHours()", () => {
|
|
30
|
+
it("Should return hours when valid", () => {
|
|
31
|
+
const time = new ISO8601Time_1.ISO8601Time("00:01");
|
|
32
|
+
expect(time.getHours()).toBe("00");
|
|
33
|
+
const time2 = new ISO8601Time_1.ISO8601Time("00:01:02");
|
|
34
|
+
expect(time2.getHours()).toBe("00");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe("ISO8601Time.getMinutes()", () => {
|
|
38
|
+
it("Should return minutes when valid", () => {
|
|
39
|
+
const time = new ISO8601Time_1.ISO8601Time("00:01");
|
|
40
|
+
expect(time.getMinutes()).toBe("01");
|
|
41
|
+
const time2 = new ISO8601Time_1.ISO8601Time("00:01:02");
|
|
42
|
+
expect(time2.getMinutes()).toBe("01");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe("ISO8601Time.getSeconds()", () => {
|
|
46
|
+
it("Should return seconds when valid", () => {
|
|
47
|
+
const time2 = new ISO8601Time_1.ISO8601Time("00:01:02");
|
|
48
|
+
expect(time2.getSeconds()).toBe("02");
|
|
49
|
+
});
|
|
50
|
+
it("Should return 00 when seconds are not present.", () => {
|
|
51
|
+
const time = new ISO8601Time_1.ISO8601Time("00:01");
|
|
52
|
+
expect(time.getSeconds()).toBe("00");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe("ISO8601Time.getTime()", () => {
|
|
56
|
+
it("Should return time when valid", () => {
|
|
57
|
+
const time = new ISO8601Time_1.ISO8601Time("00:01");
|
|
58
|
+
expect(time.getTime()).toBe("00:01:00");
|
|
59
|
+
const time2 = new ISO8601Time_1.ISO8601Time("00:01:02");
|
|
60
|
+
expect(time2.getTime()).toBe("00:01:02");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ITimeValidator } from "./TimeValidator";
|
|
2
|
+
export interface IISO8601TimeValidator extends ITimeValidator {
|
|
3
|
+
isHHmmSS: (time: string) => boolean;
|
|
4
|
+
isHHmm: (time: string) => boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class ISO8601TimeValidator implements ITimeValidator {
|
|
7
|
+
private hhMMssPattern;
|
|
8
|
+
private hhMMPattern;
|
|
9
|
+
formatIsValid(time: string): boolean;
|
|
10
|
+
isHHmmSS(time: string): boolean;
|
|
11
|
+
isHHmm(time: string): boolean;
|
|
12
|
+
}
|