@eliasrrosa/tutorhub-public-assets 0.0.2 → 0.0.4
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/index.cjs +341 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +21 -0
- package/package.json +14 -4
- package/dist/entities/AsaasCustomer.d.ts +0 -14
- package/dist/entities/AsaasCustomer.js +0 -13
- package/dist/entities/Class.d.ts +0 -79
- package/dist/entities/Class.js +0 -30
- package/dist/entities/ClassRequest.d.ts +0 -15
- package/dist/entities/ClassRequest.js +0 -2
- package/dist/entities/Contract.d.ts +0 -40
- package/dist/entities/Contract.js +0 -2
- package/dist/entities/Course.d.ts +0 -34
- package/dist/entities/Course.js +0 -2
- package/dist/entities/CourseToSchoolConnectionRequest.d.ts +0 -10
- package/dist/entities/CourseToSchoolConnectionRequest.js +0 -2
- package/dist/entities/Date.d.ts +0 -56
- package/dist/entities/Date.js +0 -2
- package/dist/entities/Date.test.d.ts +0 -0
- package/dist/entities/Date.test.js +0 -23
- package/dist/entities/DateTimeSlot.d.ts +0 -6
- package/dist/entities/DateTimeSlot.js +0 -2
- package/dist/entities/DateValidator.d.ts +0 -3
- package/dist/entities/DateValidator.js +0 -2
- package/dist/entities/File.d.ts +0 -23
- package/dist/entities/File.js +0 -2
- package/dist/entities/FreeTimeSlot.d.ts +0 -19
- package/dist/entities/FreeTimeSlot.js +0 -12
- package/dist/entities/GenericNotification.d.ts +0 -11
- package/dist/entities/GenericNotification.js +0 -2
- package/dist/entities/GoogleAuth.d.ts +0 -8
- package/dist/entities/GoogleAuth.js +0 -2
- package/dist/entities/GoogleCalendar.d.ts +0 -10
- package/dist/entities/GoogleCalendar.js +0 -2
- package/dist/entities/GoogleCalendarEvent.d.ts +0 -10
- package/dist/entities/GoogleCalendarEvent.js +0 -2
- package/dist/entities/ISO8601Date.d.ts +0 -35
- package/dist/entities/ISO8601Date.js +0 -86
- package/dist/entities/ISO8601Date.test.d.ts +0 -1
- package/dist/entities/ISO8601Date.test.js +0 -210
- package/dist/entities/ISO8601DateTime.d.ts +0 -41
- package/dist/entities/ISO8601DateTime.js +0 -44
- package/dist/entities/ISO8601DateTime.test.d.ts +0 -1
- package/dist/entities/ISO8601DateTime.test.js +0 -146
- package/dist/entities/ISO8601DateValidator.d.ts +0 -13
- package/dist/entities/ISO8601DateValidator.js +0 -20
- package/dist/entities/ISO8601DateValidator.test.d.ts +0 -1
- package/dist/entities/ISO8601DateValidator.test.js +0 -15
- package/dist/entities/ISO8601Time.d.ts +0 -25
- package/dist/entities/ISO8601Time.js +0 -57
- package/dist/entities/ISO8601Time.test.d.ts +0 -1
- package/dist/entities/ISO8601Time.test.js +0 -63
- package/dist/entities/ISO8601TimeValidator.d.ts +0 -12
- package/dist/entities/ISO8601TimeValidator.js +0 -19
- package/dist/entities/ISO8601TimeValidator.test.d.ts +0 -1
- package/dist/entities/ISO8601TimeValidator.test.js +0 -42
- package/dist/entities/PasswordRecovery.d.ts +0 -6
- package/dist/entities/PasswordRecovery.js +0 -2
- package/dist/entities/Payment.d.ts +0 -42
- package/dist/entities/Payment.js +0 -2
- package/dist/entities/PaymentRecognitionRequest.d.ts +0 -12
- package/dist/entities/PaymentRecognitionRequest.js +0 -2
- package/dist/entities/PreApprovedUser.d.ts +0 -12
- package/dist/entities/PreApprovedUser.js +0 -2
- package/dist/entities/RescheduleRequest.d.ts +0 -16
- package/dist/entities/RescheduleRequest.js +0 -2
- package/dist/entities/School.d.ts +0 -31
- package/dist/entities/School.js +0 -2
- package/dist/entities/SchoolConnection.d.ts +0 -10
- package/dist/entities/SchoolConnection.js +0 -2
- package/dist/entities/SchoolConnectionRequest.d.ts +0 -7
- package/dist/entities/SchoolConnectionRequest.js +0 -2
- package/dist/entities/SchoolStudent.d.ts +0 -14
- package/dist/entities/SchoolStudent.js +0 -2
- package/dist/entities/SchoolTeacher.d.ts +0 -14
- package/dist/entities/SchoolTeacher.js +0 -2
- package/dist/entities/Time.d.ts +0 -9
- package/dist/entities/Time.js +0 -2
- package/dist/entities/TimeSlot.d.ts +0 -4
- package/dist/entities/TimeSlot.js +0 -2
- package/dist/entities/TimeValidator.d.ts +0 -3
- package/dist/entities/TimeValidator.js +0 -2
- package/dist/entities/UnauthorizedUser.d.ts +0 -16
- package/dist/entities/UnauthorizedUser.js +0 -2
- package/dist/entities/UserAuth.d.ts +0 -72
- package/dist/entities/UserAuth.js +0 -2
- package/dist/entities/UserConnection.d.ts +0 -8
- package/dist/entities/UserConnection.js +0 -2
- package/dist/entities/UserConnectionRequest.d.ts +0 -9
- package/dist/entities/UserConnectionRequest.js +0 -2
- package/dist/entities/UserCredentials.d.ts +0 -16
- package/dist/entities/UserCredentials.js +0 -11
- package/dist/entities/UserNavigation.d.ts +0 -8
- package/dist/entities/UserNavigation.js +0 -2
- package/dist/entities/UserPreferences.d.ts +0 -6
- package/dist/entities/UserPreferences.js +0 -2
- package/dist/entities/UserPremium.d.ts +0 -13
- package/dist/entities/UserPremium.js +0 -2
- package/dist/entities/UserProfile.d.ts +0 -9
- package/dist/entities/UserProfile.js +0 -2
- package/dist/entities/UserRoles.d.ts +0 -11
- package/dist/entities/UserRoles.js +0 -2
- package/dist/entities/UserSharedFileTimestamps.d.ts +0 -9
- package/dist/entities/UserSharedFileTimestamps.js +0 -2
- package/dist/entities/UserUnavailableTime.d.ts +0 -49
- package/dist/entities/UserUnavailableTime.js +0 -32
- package/dist/entities/UserUnavailableTime.test.d.ts +0 -1
- package/dist/entities/UserUnavailableTime.test.js +0 -22
- package/dist/repositories/UnavailableTimeRepository.d.ts +0 -20
- package/dist/repositories/UnavailableTimeRepository.js +0 -2
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { IClass } from "./Class";
|
|
2
|
-
import { IClassRequest } from "./ClassRequest";
|
|
3
|
-
import { IContract } from "./Contract";
|
|
4
|
-
import { ICourseToSchoolConnectionRequest } from "./CourseToSchoolConnectionRequest";
|
|
5
|
-
import { IFile } from "./File";
|
|
6
|
-
import { IPayment } from "./Payment";
|
|
7
|
-
import { IPreApprovedUser } from "./PreApprovedUser";
|
|
8
|
-
import { ISchool } from "./School";
|
|
9
|
-
import { IUserAuth } from "./UserAuth";
|
|
10
|
-
import { IUserUnavailableTime } from "./UserUnavailableTime";
|
|
11
|
-
export interface ICourse {
|
|
12
|
-
id: string;
|
|
13
|
-
title: string;
|
|
14
|
-
description: string;
|
|
15
|
-
createdAt: Date | null;
|
|
16
|
-
updatedAt: Date | null;
|
|
17
|
-
isActive: boolean;
|
|
18
|
-
ownerId: string;
|
|
19
|
-
schoolId: string | null;
|
|
20
|
-
responsibleTeacherId: string | null;
|
|
21
|
-
owner?: IUserAuth;
|
|
22
|
-
students?: IUserAuth[];
|
|
23
|
-
preApprovedUserStudents?: IPreApprovedUser[];
|
|
24
|
-
classes?: IClass[];
|
|
25
|
-
payments?: IPayment[];
|
|
26
|
-
files?: IFile[];
|
|
27
|
-
availableTimes?: IUserUnavailableTime[];
|
|
28
|
-
classRequests?: IClassRequest[];
|
|
29
|
-
meetingLink: string | null;
|
|
30
|
-
contracts?: IContract[];
|
|
31
|
-
schools?: ISchool;
|
|
32
|
-
courseToSchoolConnectionRequests?: ICourseToSchoolConnectionRequest[];
|
|
33
|
-
responsibleTeacher?: IUserAuth;
|
|
34
|
-
}
|
package/dist/entities/Course.js
DELETED
package/dist/entities/Date.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**An utility to separate dates from times. Operate on dates
|
|
2
|
-
* by clearly chosing between local time and utc, and without the nuances
|
|
3
|
-
* of hours, minutes and seconds.
|
|
4
|
-
*/
|
|
5
|
-
export interface IDate {
|
|
6
|
-
/**
|
|
7
|
-
* a string like formatted like YYYY-MM-DD (eg. '1920-01-02', '2025-12-30') representing a date.
|
|
8
|
-
*/
|
|
9
|
-
value: string;
|
|
10
|
-
/**
|
|
11
|
-
* @returns a string like formatted like DD (eg. '03', '21') representing the day.
|
|
12
|
-
*/
|
|
13
|
-
getDay: () => string;
|
|
14
|
-
/**
|
|
15
|
-
* @returns a string like formatted like MM (eg. '03', '12') representing the month.
|
|
16
|
-
*/
|
|
17
|
-
getMonth: () => string;
|
|
18
|
-
/**
|
|
19
|
-
* @returns a string like formatted like YYYY (eg. '1920', '2025') representing the year.
|
|
20
|
-
*/
|
|
21
|
-
getYear: () => string;
|
|
22
|
-
/**
|
|
23
|
-
* @returns a string like formatted like YYYY-MM-DD (eg. '1920-01-02', '2025-12-30') representing the today's date,
|
|
24
|
-
* in the system's timezone.
|
|
25
|
-
*/
|
|
26
|
-
getToday: () => string;
|
|
27
|
-
/**
|
|
28
|
-
* Returns a new instance of IDate with the days added.
|
|
29
|
-
* Counts for added months and years.
|
|
30
|
-
*/
|
|
31
|
-
addDays: (daysToAdd: number) => IDate;
|
|
32
|
-
/**
|
|
33
|
-
* Converts a Javascript Date instance into an IDate instance. Uses local timezone as default.
|
|
34
|
-
* @param useUtc set to true to consider UTC when extracting year, month and date
|
|
35
|
-
* @returns a new IDate instance.
|
|
36
|
-
*/
|
|
37
|
-
jsDateTimeToDate: (dateTime: Date, opts?: {
|
|
38
|
-
useUtc?: boolean;
|
|
39
|
-
}) => IDate;
|
|
40
|
-
/**
|
|
41
|
-
* Returns `date` or `this.date` as a Javascript Date object.
|
|
42
|
-
* Considers `date` or `this.date` as local time, with hours, minutes
|
|
43
|
-
* and seconds set to 0.
|
|
44
|
-
*/
|
|
45
|
-
toLocalJsDateTime: (date?: IDate) => Date;
|
|
46
|
-
/**
|
|
47
|
-
* Returns `date` or `this.date` as a Javascript Date object.
|
|
48
|
-
* Considers `date` or `this.date` as utc time, with hours, minutes
|
|
49
|
-
* and seconds set to 0.
|
|
50
|
-
*/
|
|
51
|
-
readonly toUtcJsDateTime: (date?: IDate) => Date;
|
|
52
|
-
/**Returns the time elapsed in days since the epoch (1970-01-01 00:00:00 UTC)
|
|
53
|
-
* up to `this.value` or `date` param if specified. */
|
|
54
|
-
readonly getDaysSinceEpoch: (date?: IDate) => number;
|
|
55
|
-
readonly getDayOfTheWeek: (date?: IDate) => number;
|
|
56
|
-
}
|
package/dist/entities/Date.js
DELETED
|
File without changes
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
describe("Date", () => {
|
|
3
|
-
describe("Date.getDate()", () => {
|
|
4
|
-
it("Should return the same date if instantiated with timezone.", () => {
|
|
5
|
-
const date = new Date("2025-01-01T00:00:00-03:00");
|
|
6
|
-
expect(date.getDate()).toBe(1);
|
|
7
|
-
});
|
|
8
|
-
it("Should return same date if instantiated with numbers", () => {
|
|
9
|
-
const date = new Date(2025, 1, 1);
|
|
10
|
-
expect(date.getDate()).toBe(1);
|
|
11
|
-
});
|
|
12
|
-
it("Should return incorrect date if instantiated with string.", () => {
|
|
13
|
-
const date = new Date("2025-01-01");
|
|
14
|
-
expect(date.getDate()).toBe(31);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
describe("Date.getTimezoneOffset().toLocaleString()", () => {
|
|
18
|
-
it("Should return brazilian timezone offset.", () => {
|
|
19
|
-
const date = new Date("2025-01-01");
|
|
20
|
-
expect(date.getTimezoneOffset()).toBe(180);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
package/dist/entities/File.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { IClass } from "./Class";
|
|
2
|
-
import { IContract } from "./Contract";
|
|
3
|
-
import { ICourse } from "./Course";
|
|
4
|
-
import { IPayment } from "./Payment";
|
|
5
|
-
import { IUserAuth } from "./UserAuth";
|
|
6
|
-
import { IUserSharedFileTimestamps } from "./UserSharedFileTimestamps";
|
|
7
|
-
export interface IFile {
|
|
8
|
-
id: string;
|
|
9
|
-
name: string;
|
|
10
|
-
type: string;
|
|
11
|
-
ownerId: string;
|
|
12
|
-
privacy: string;
|
|
13
|
-
createdAt: Date | null;
|
|
14
|
-
updatedAt: Date | null;
|
|
15
|
-
downloadCount: number;
|
|
16
|
-
owner?: IUserAuth;
|
|
17
|
-
viewers?: IUserAuth[];
|
|
18
|
-
courses?: ICourse[];
|
|
19
|
-
classes?: IClass[];
|
|
20
|
-
payments?: IPayment[];
|
|
21
|
-
userSharedFileTimestamps?: IUserSharedFileTimestamps[];
|
|
22
|
-
contract?: IContract;
|
|
23
|
-
}
|
package/dist/entities/File.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { IDate } from "./Date";
|
|
2
|
-
export interface IFreeDateTimeSlot {
|
|
3
|
-
date: IDate;
|
|
4
|
-
startTime: string;
|
|
5
|
-
endTime: string;
|
|
6
|
-
userId: string;
|
|
7
|
-
}
|
|
8
|
-
export declare class FreeDateTimeSlot implements IFreeDateTimeSlot {
|
|
9
|
-
date: IDate;
|
|
10
|
-
startTime: string;
|
|
11
|
-
endTime: string;
|
|
12
|
-
userId: string;
|
|
13
|
-
constructor(opts: {
|
|
14
|
-
date: IDate;
|
|
15
|
-
startTime: string;
|
|
16
|
-
endTime: string;
|
|
17
|
-
userId: string;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FreeDateTimeSlot = void 0;
|
|
4
|
-
class FreeDateTimeSlot {
|
|
5
|
-
constructor(opts) {
|
|
6
|
-
this.date = opts.date;
|
|
7
|
-
this.startTime = opts.startTime;
|
|
8
|
-
this.endTime = opts.endTime;
|
|
9
|
-
this.userId = opts.userId;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.FreeDateTimeSlot = FreeDateTimeSlot;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IUserAuth } from "./UserAuth";
|
|
2
|
-
export interface IGenericNotification {
|
|
3
|
-
id: string;
|
|
4
|
-
text: string;
|
|
5
|
-
senderId: string | null;
|
|
6
|
-
sender?: IUserAuth | null;
|
|
7
|
-
receivers?: IUserAuth[];
|
|
8
|
-
createdAt: Date | null;
|
|
9
|
-
usersThatSeen?: IUserAuth[];
|
|
10
|
-
link: string | null;
|
|
11
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IUserAuth } from "./UserAuth";
|
|
2
|
-
import { IGoogleCalendarEvent } from "./GoogleCalendarEvent";
|
|
3
|
-
export interface IGoogleCalendar {
|
|
4
|
-
userId: string;
|
|
5
|
-
calendarId: string;
|
|
6
|
-
createdAt: Date;
|
|
7
|
-
isSynched: boolean;
|
|
8
|
-
user?: IUserAuth;
|
|
9
|
-
events?: IGoogleCalendarEvent[];
|
|
10
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IClass } from "./Class";
|
|
2
|
-
import { IGoogleCalendar } from "./GoogleCalendar";
|
|
3
|
-
export interface IGoogleCalendarEvent {
|
|
4
|
-
calendarId: string;
|
|
5
|
-
classId: string;
|
|
6
|
-
eventId: string;
|
|
7
|
-
updatedAt: Date;
|
|
8
|
-
calendar?: IGoogleCalendar;
|
|
9
|
-
class?: IClass;
|
|
10
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { IDate } from "./Date";
|
|
2
|
-
import { IDateValidator } from "./DateValidator";
|
|
3
|
-
export declare class ISO8601Date implements IDate {
|
|
4
|
-
readonly value: string;
|
|
5
|
-
validator: IDateValidator;
|
|
6
|
-
constructor(value?: string);
|
|
7
|
-
private throwIfFormatIsNotValid;
|
|
8
|
-
getDay: () => string;
|
|
9
|
-
getMonth: () => string;
|
|
10
|
-
getYear: () => string;
|
|
11
|
-
/**
|
|
12
|
-
* @returns today's date as a string, in local time, formatted like YYYY-MM-DD.
|
|
13
|
-
*/
|
|
14
|
-
static getToday(): string;
|
|
15
|
-
/**
|
|
16
|
-
* @returns today's date as a srting, in local time, formatted like YYYY-MM-DD.
|
|
17
|
-
*/
|
|
18
|
-
getToday: typeof ISO8601Date.getToday;
|
|
19
|
-
addDays: (x: number) => IDate;
|
|
20
|
-
/**
|
|
21
|
-
* Converts a Javascript Date instance into an IDate instance. Uses local timezone as default.
|
|
22
|
-
* @param useUtc set to `true` to consider UTC when extracting year, month and date
|
|
23
|
-
* @returns a new `ISO8601Date` instance.
|
|
24
|
-
*/
|
|
25
|
-
static jsDateTimeToDate: (dateTime: Date, opts?: {
|
|
26
|
-
useUtc?: boolean;
|
|
27
|
-
}) => IDate;
|
|
28
|
-
jsDateTimeToDate: (dateTime: Date, opts?: {
|
|
29
|
-
useUtc?: boolean;
|
|
30
|
-
}) => IDate;
|
|
31
|
-
toLocalJsDateTime: (date?: IDate) => Date;
|
|
32
|
-
getDaysSinceEpoch: (date?: IDate) => number;
|
|
33
|
-
readonly toUtcJsDateTime: (date?: IDate) => Date;
|
|
34
|
-
readonly getDayOfTheWeek: (date?: IDate) => number;
|
|
35
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ISO8601Date = void 0;
|
|
4
|
-
const ISO8601DateValidator_1 = require("./ISO8601DateValidator");
|
|
5
|
-
class ISO8601Date {
|
|
6
|
-
constructor(value) {
|
|
7
|
-
this.validator = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
8
|
-
this.getDay = () => {
|
|
9
|
-
this.throwIfFormatIsNotValid();
|
|
10
|
-
return this.value.split("-")[2];
|
|
11
|
-
};
|
|
12
|
-
this.getMonth = () => {
|
|
13
|
-
this.throwIfFormatIsNotValid();
|
|
14
|
-
return this.value.split("-")[1];
|
|
15
|
-
};
|
|
16
|
-
this.getYear = () => {
|
|
17
|
-
this.throwIfFormatIsNotValid();
|
|
18
|
-
return this.value.split("-")[0];
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* @returns today's date as a srting, in local time, formatted like YYYY-MM-DD.
|
|
22
|
-
*/
|
|
23
|
-
this.getToday = ISO8601Date.getToday;
|
|
24
|
-
this.addDays = (x) => {
|
|
25
|
-
const now = new Date(parseInt(this.getYear()), parseInt(this.getMonth()) - 1, parseInt(this.getDay()));
|
|
26
|
-
const day = now.getDate() + x;
|
|
27
|
-
const newDate = new Date(now.getFullYear(), now.getMonth(), day);
|
|
28
|
-
return new ISO8601Date(this.jsDateTimeToDate(newDate).value);
|
|
29
|
-
};
|
|
30
|
-
this.jsDateTimeToDate = ISO8601Date.jsDateTimeToDate;
|
|
31
|
-
this.toLocalJsDateTime = (date) => {
|
|
32
|
-
const targetDate = date ? date : this;
|
|
33
|
-
return new Date(parseInt(targetDate.getYear()), parseInt(targetDate.getMonth()) - 1, parseInt(targetDate.getDay()));
|
|
34
|
-
};
|
|
35
|
-
this.getDaysSinceEpoch = (date) => {
|
|
36
|
-
const targetDate = date || this;
|
|
37
|
-
const differenceInDays = Math.floor(targetDate.toLocalJsDateTime(targetDate).getTime() / 1000 / 60 / 60 / 24);
|
|
38
|
-
return differenceInDays;
|
|
39
|
-
};
|
|
40
|
-
this.toUtcJsDateTime = (date) => {
|
|
41
|
-
const targetDate = date ? date : this;
|
|
42
|
-
const year = targetDate.getYear();
|
|
43
|
-
const month = targetDate.getMonth();
|
|
44
|
-
const day = targetDate.getDay();
|
|
45
|
-
const dateString = `${year}-${month}-${day}T00:00:00.000Z`;
|
|
46
|
-
return new Date(dateString);
|
|
47
|
-
};
|
|
48
|
-
this.getDayOfTheWeek = (date) => {
|
|
49
|
-
const targetDate = date || this;
|
|
50
|
-
return targetDate.toUtcJsDateTime().getUTCDay();
|
|
51
|
-
};
|
|
52
|
-
this.value = value ? value : this.getToday();
|
|
53
|
-
this.throwIfFormatIsNotValid();
|
|
54
|
-
}
|
|
55
|
-
throwIfFormatIsNotValid() {
|
|
56
|
-
if (!this.validator.formatIsValid(this.value)) {
|
|
57
|
-
throw new Error("Date format must be YYYY-MM-DD.");
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @returns today's date as a string, in local time, formatted like YYYY-MM-DD.
|
|
62
|
-
*/
|
|
63
|
-
static getToday() {
|
|
64
|
-
const now = new Date();
|
|
65
|
-
const day = now.getDate().toString().padStart(2, "0");
|
|
66
|
-
const month = (now.getMonth() + 1).toString().padStart(2, "0");
|
|
67
|
-
const year = now.getFullYear().toString();
|
|
68
|
-
return `${year}-${month}-${day}`;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.ISO8601Date = ISO8601Date;
|
|
72
|
-
/**
|
|
73
|
-
* Converts a Javascript Date instance into an IDate instance. Uses local timezone as default.
|
|
74
|
-
* @param useUtc set to `true` to consider UTC when extracting year, month and date
|
|
75
|
-
* @returns a new `ISO8601Date` instance.
|
|
76
|
-
*/
|
|
77
|
-
ISO8601Date.jsDateTimeToDate = (dateTime, opts) => {
|
|
78
|
-
const day = ((opts === null || opts === void 0 ? void 0 : opts.useUtc) ? dateTime.getUTCDate() : dateTime.getDate())
|
|
79
|
-
.toString()
|
|
80
|
-
.padStart(2, "0");
|
|
81
|
-
const month = ((opts === null || opts === void 0 ? void 0 : opts.useUtc) ? dateTime.getUTCMonth() + 1 : dateTime.getMonth() + 1)
|
|
82
|
-
.toString()
|
|
83
|
-
.padStart(2, "0");
|
|
84
|
-
const year = ((opts === null || opts === void 0 ? void 0 : opts.useUtc) ? dateTime.getUTCFullYear() : dateTime.getFullYear()).toString();
|
|
85
|
-
return new ISO8601Date(`${year}-${month}-${day}`);
|
|
86
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,210 +0,0 @@
|
|
|
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
|
-
});
|