@atlantjs/arch 15.6.6 → 15.6.7
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/package.json +3 -2
- package/src/@tool-box/tests/builder.abstract.util.d.ts +1 -0
- package/src/@tool-box/tests/builder.abstract.util.d.ts.map +1 -0
- package/src/@tool-box/tests/builders/datetime/datetime.edge.builder.d.ts +1 -0
- package/src/@tool-box/tests/builders/datetime/datetime.edge.builder.d.ts.map +1 -0
- package/src/@tool-box/tests/builders/failures/dummies/failure.dummy.d.ts +1 -0
- package/src/@tool-box/tests/builders/failures/dummies/failure.dummy.d.ts.map +1 -0
- package/src/@tool-box/tests/builders/failures/failure.builder.d.ts +1 -0
- package/src/@tool-box/tests/builders/failures/failure.builder.d.ts.map +1 -0
- package/src/@tool-box/tests/builders/metadata/metadata-uv.builder.d.ts +1 -0
- package/src/@tool-box/tests/builders/metadata/metadata-uv.builder.d.ts.map +1 -0
- package/src/@tool-box/tests/builders/metadata/metadata.edge.builder.d.ts +1 -0
- package/src/@tool-box/tests/builders/metadata/metadata.edge.builder.d.ts.map +1 -0
- package/src/@tool-box/tests/builders/user/email.edge.builder.d.ts +1 -0
- package/src/@tool-box/tests/builders/user/email.edge.builder.d.ts.map +1 -0
- package/src/@tool-box/tests/builders/user/username.edge.builder.d.ts +1 -0
- package/src/@tool-box/tests/builders/user/username.edge.builder.d.ts.map +1 -0
- package/src/@tool-box/tests/faker/faker.d.ts +1 -0
- package/src/@tool-box/tests/faker/faker.d.ts.map +1 -0
- package/src/@tool-box/utils/convert-units/convert-units.d.ts +1 -0
- package/src/@tool-box/utils/convert-units/convert-units.d.ts.map +1 -0
- package/src/@tool-box/utils/datatypes/boolean-utils.d.ts +1 -0
- package/src/@tool-box/utils/datatypes/boolean-utils.d.ts.map +1 -0
- package/src/@tool-box/utils/datatypes/generic-types.d.ts +1 -0
- package/src/@tool-box/utils/datatypes/generic-types.d.ts.map +1 -0
- package/src/@tool-box/utils/datatypes/plainify.d.ts +1 -0
- package/src/@tool-box/utils/datatypes/plainify.d.ts.map +1 -0
- package/src/@tool-box/utils/datatypes/string-utils.d.ts +1 -0
- package/src/@tool-box/utils/datatypes/string-utils.d.ts.map +1 -0
- package/src/@tool-box/utils/datetime/mappers/month.mapper.d.ts +1 -0
- package/src/@tool-box/utils/datetime/mappers/month.mapper.d.ts.map +1 -0
- package/src/@tool-box/utils/datetime/mappers/points/month-abbreviation.enum.d.ts +1 -0
- package/src/@tool-box/utils/datetime/mappers/points/month-abbreviation.enum.d.ts.map +1 -0
- package/src/@tool-box/utils/datetime/mappers/points/month-number.enum.d.ts +1 -0
- package/src/@tool-box/utils/datetime/mappers/points/month-number.enum.d.ts.map +1 -0
- package/src/@tool-box/utils/ducts/common.d.ts +1 -0
- package/src/@tool-box/utils/ducts/common.d.ts.map +1 -0
- package/src/@tool-box/utils/ducts/optional-type.d.ts +1 -0
- package/src/@tool-box/utils/ducts/optional-type.d.ts.map +1 -0
- package/src/@tool-box/utils/ducts/return-type.d.ts +1 -0
- package/src/@tool-box/utils/ducts/return-type.d.ts.map +1 -0
- package/src/@tool-box/utils/http-provider/http-provider-failure-response.d.ts +1 -0
- package/src/@tool-box/utils/http-provider/http-provider-failure-response.d.ts.map +1 -0
- package/src/@tool-box/utils/http-provider/http-provider-success-response.d.ts +1 -0
- package/src/@tool-box/utils/http-provider/http-provider-success-response.d.ts.map +1 -0
- package/src/@tool-box/utils/http-provider/http-provider.d.ts +1 -0
- package/src/@tool-box/utils/http-provider/http-provider.d.ts.map +1 -0
- package/src/@tool-box/utils/logger/index.d.ts +1 -0
- package/src/@tool-box/utils/logger/index.d.ts.map +1 -0
- package/src/@tool-box/utils/map/map.abstract.d.ts +1 -0
- package/src/@tool-box/utils/map/map.abstract.d.ts.map +1 -0
- package/src/@tool-box/utils/random/random.d.ts +1 -0
- package/src/@tool-box/utils/random/random.d.ts.map +1 -0
- package/src/@tool-box/utils/type-guard/guardian-exception.d.ts +1 -0
- package/src/@tool-box/utils/type-guard/guardian-exception.d.ts.map +1 -0
- package/src/@tool-box/utils/type-guard/guardian.d.ts +1 -0
- package/src/@tool-box/utils/type-guard/guardian.d.ts.map +1 -0
- package/src/@tool-box/utils/type-guard/guardian.type.d.ts +1 -0
- package/src/@tool-box/utils/type-guard/guardian.type.d.ts.map +1 -0
- package/src/@tool-box/utils/validators/is-cron-expression.d.ts +1 -0
- package/src/@tool-box/utils/validators/is-cron-expression.d.ts.map +1 -0
- package/src/@tool-box/utils/validators/is-date-string.d.ts +1 -0
- package/src/@tool-box/utils/validators/is-date-string.d.ts.map +1 -0
- package/src/@tool-box/utils/validators/is-password-match.d.ts +1 -0
- package/src/@tool-box/utils/validators/is-password-match.d.ts.map +1 -0
- package/src/@tool-box/utils/validators/is-password-policy.validator.d.ts +1 -0
- package/src/@tool-box/utils/validators/is-password-policy.validator.d.ts.map +1 -0
- package/src/@tool-box/utils/validators/is-schedule.d.ts +1 -0
- package/src/@tool-box/utils/validators/is-schedule.d.ts.map +1 -0
- package/src/@tool-box/utils/validators/is-time-string.d.ts +1 -0
- package/src/@tool-box/utils/validators/is-time-string.d.ts.map +1 -0
- package/src/@tool-box/utils/validators/is-ulid.d.ts +1 -0
- package/src/@tool-box/utils/validators/is-ulid.d.ts.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -0
- package/src/objects/@common/edges/email.edge.d.ts +1 -0
- package/src/objects/@common/edges/email.edge.d.ts.map +1 -0
- package/src/objects/@common/edges/email.edge.js +0 -1
- package/src/objects/@common/edges/ulid.sketch.edge.d.ts +1 -0
- package/src/objects/@common/edges/ulid.sketch.edge.d.ts.map +1 -0
- package/src/objects/@common/edges/url.edge.d.ts +1 -0
- package/src/objects/@common/edges/url.edge.d.ts.map +1 -0
- package/src/objects/@common/edges/username.edge.d.ts +1 -0
- package/src/objects/@common/edges/username.edge.d.ts.map +1 -0
- package/src/objects/@common/edges/uuid.sketch.edge.d.ts +1 -0
- package/src/objects/@common/edges/uuid.sketch.edge.d.ts.map +1 -0
- package/src/objects/@common/points/environment.point.d.ts +1 -0
- package/src/objects/@common/points/environment.point.d.ts.map +1 -0
- package/src/objects/@common/points/header-token-name.point.d.ts +1 -0
- package/src/objects/@common/points/header-token-name.point.d.ts.map +1 -0
- package/src/objects/@common/points/http-status-codes.point.d.ts +1 -0
- package/src/objects/@common/points/http-status-codes.point.d.ts.map +1 -0
- package/src/objects/amount/amount-value.edge.d.ts +1 -0
- package/src/objects/amount/amount-value.edge.d.ts.map +1 -0
- package/src/objects/amount/amount.edge.d.ts +142 -132
- package/src/objects/amount/amount.edge.d.ts.map +1 -0
- package/src/objects/amount/amount.edge.js +168 -141
- package/src/objects/amount/amount.polygon.d.ts +1 -0
- package/src/objects/amount/amount.polygon.d.ts.map +1 -0
- package/src/objects/amount/amount.uv.d.ts +2 -1
- package/src/objects/amount/amount.uv.d.ts.map +1 -0
- package/src/objects/amount/amount.uv.js +1 -1
- package/src/objects/amount/points/duration-unit.point.d.ts +1 -0
- package/src/objects/amount/points/duration-unit.point.d.ts.map +1 -0
- package/src/objects/amount/points/energy-unit.point.d.ts +1 -0
- package/src/objects/amount/points/energy-unit.point.d.ts.map +1 -0
- package/src/objects/amount/points/length-unit.point.d.ts +1 -0
- package/src/objects/amount/points/length-unit.point.d.ts.map +1 -0
- package/src/objects/amount/points/mass-unit.point.d.ts +1 -0
- package/src/objects/amount/points/mass-unit.point.d.ts.map +1 -0
- package/src/objects/amount/points/month-name.point.d.ts +1 -0
- package/src/objects/amount/points/month-name.point.d.ts.map +1 -0
- package/src/objects/amount/points/object-unit.point.d.ts +1 -0
- package/src/objects/amount/points/object-unit.point.d.ts.map +1 -0
- package/src/objects/amount/points/units.point.d.ts +1 -0
- package/src/objects/amount/points/units.point.d.ts.map +1 -0
- package/src/objects/amount/points/volume-unit.point.d.ts +1 -0
- package/src/objects/amount/points/volume-unit.point.d.ts.map +1 -0
- package/src/objects/amount/points/week-day.point.d.ts +1 -0
- package/src/objects/amount/points/week-day.point.d.ts.map +1 -0
- package/src/objects/datetime/edges/datetime.edge.d.ts +174 -162
- package/src/objects/datetime/edges/datetime.edge.d.ts.map +1 -0
- package/src/objects/datetime/edges/datetime.edge.js +207 -218
- package/src/objects/datetime/edges/locale/day/day-name-to-english.mapper.d.ts +5 -0
- package/src/objects/datetime/edges/locale/day/day-name-to-english.mapper.d.ts.map +1 -0
- package/src/objects/datetime/edges/locale/day/day-name-to-english.mapper.js +19 -0
- package/src/objects/datetime/edges/locale/day/day-name-to-portuguese.mapper.d.ts +5 -0
- package/src/objects/datetime/edges/locale/day/day-name-to-portuguese.mapper.d.ts.map +1 -0
- package/src/objects/datetime/edges/locale/day/day-name-to-portuguese.mapper.js +19 -0
- package/src/objects/datetime/edges/locale/day/today-to-language.mapper.d.ts +6 -0
- package/src/objects/datetime/edges/locale/day/today-to-language.mapper.d.ts.map +1 -0
- package/src/objects/datetime/edges/locale/day/today-to-language.mapper.js +15 -0
- package/src/objects/datetime/edges/locale/holidays-country.type.d.ts +3 -0
- package/src/objects/datetime/edges/locale/holidays-country.type.d.ts.map +1 -0
- package/src/objects/datetime/edges/locale/holidays-country.type.js +2 -0
- package/src/objects/datetime/edges/locale/month/month-to-english.mapper.d.ts +5 -0
- package/src/objects/datetime/edges/locale/month/month-to-english.mapper.d.ts.map +1 -0
- package/src/objects/datetime/edges/locale/month/month-to-english.mapper.js +24 -0
- package/src/objects/datetime/edges/locale/month/month-to-portuguese.mapper.d.ts +5 -0
- package/src/objects/datetime/edges/locale/month/month-to-portuguese.mapper.d.ts.map +1 -0
- package/src/objects/datetime/edges/locale/month/month-to-portuguese.mapper.js +24 -0
- package/src/objects/datetime/points/month-name.enum.d.ts +1 -0
- package/src/objects/datetime/points/month-name.enum.d.ts.map +1 -0
- package/src/objects/datetime/points/week-day.enum.d.ts +1 -0
- package/src/objects/datetime/points/week-day.enum.d.ts.map +1 -0
- package/src/objects/failure/edges/failure.abstract.d.ts +1 -0
- package/src/objects/failure/edges/failure.abstract.d.ts.map +1 -0
- package/src/objects/failure/edges/failure.abstract.polygon.d.ts +1 -0
- package/src/objects/failure/edges/failure.abstract.polygon.d.ts.map +1 -0
- package/src/objects/language/points/language.point.d.ts +1 -0
- package/src/objects/language/points/language.point.d.ts.map +1 -0
- package/src/objects/metadata/metadata.edge.d.ts +1 -0
- package/src/objects/metadata/metadata.edge.d.ts.map +1 -0
- package/src/objects/metadata/metadata.polygon.d.ts +1 -0
- package/src/objects/metadata/metadata.polygon.d.ts.map +1 -0
- package/src/objects/metadata/metadata.uv.d.ts +1 -0
- package/src/objects/metadata/metadata.uv.d.ts.map +1 -0
- package/src/objects/password/password.edge.d.ts +1 -0
- package/src/objects/password/password.edge.d.ts.map +1 -0
- package/src/objects/password/password.polygon.d.ts +1 -0
- package/src/objects/password/password.polygon.d.ts.map +1 -0
- package/src/objects/password/steps/not-allowing-consecutive-chars-step.d.ts +1 -0
- package/src/objects/password/steps/not-allowing-consecutive-chars-step.d.ts.map +1 -0
- package/src/objects/password/steps/not-allowing-date-step.d.ts +1 -0
- package/src/objects/password/steps/not-allowing-date-step.d.ts.map +1 -0
- package/src/objects/password/steps/not-allowing-phone-step.d.ts +1 -0
- package/src/objects/password/steps/not-allowing-phone-step.d.ts.map +1 -0
- package/src/objects/password/steps/not-allowing-repeated-chars-step.d.ts +1 -0
- package/src/objects/password/steps/not-allowing-repeated-chars-step.d.ts.map +1 -0
- package/src/objects/password/steps/not-allowing-string-step.d.ts +1 -0
- package/src/objects/password/steps/not-allowing-string-step.d.ts.map +1 -0
- package/src/objects/password/steps/not-allowing-these-chars-step.d.ts +1 -0
- package/src/objects/password/steps/not-allowing-these-chars-step.d.ts.map +1 -0
- package/src/objects/password/steps/numeric-step.d.ts +1 -0
- package/src/objects/password/steps/numeric-step.d.ts.map +1 -0
- package/src/objects/password/steps/with-at-least-one-letter-step.d.ts +1 -0
- package/src/objects/password/steps/with-at-least-one-letter-step.d.ts.map +1 -0
- package/src/objects/password/steps/with-at-least-one-number-digit-step.d.ts +1 -0
- package/src/objects/password/steps/with-at-least-one-number-digit-step.d.ts.map +1 -0
- package/src/objects/password/steps/with-at-least-one-special-char-step.d.ts +1 -0
- package/src/objects/password/steps/with-at-least-one-special-char-step.d.ts.map +1 -0
- package/src/objects/password/steps/with-length-step.d.ts +1 -0
- package/src/objects/password/steps/with-length-step.d.ts.map +1 -0
- package/src/objects/password/validation-step.d.ts +1 -0
- package/src/objects/password/validation-step.d.ts.map +1 -0
- package/src/objects/password/validation-step.type.d.ts +1 -0
- package/src/objects/password/validation-step.type.d.ts.map +1 -0
- package/src/objects/primitives/boolean.edge.sketch.d.ts +1 -0
- package/src/objects/primitives/boolean.edge.sketch.d.ts.map +1 -0
- package/src/objects/primitives/datetime.edge.sketch.d.ts +1 -0
- package/src/objects/primitives/datetime.edge.sketch.d.ts.map +1 -0
- package/src/objects/primitives/number.edge.sketch.d.ts +1 -0
- package/src/objects/primitives/number.edge.sketch.d.ts.map +1 -0
- package/src/objects/primitives/string.edge.sketch.d.ts +1 -0
- package/src/objects/primitives/string.edge.sketch.d.ts.map +1 -0
- package/src/objects/scheduling/scheduling.edge.d.ts +1 -0
- package/src/objects/scheduling/scheduling.edge.d.ts.map +1 -0
- package/src/objects/scheduling/scheduling.edge.failure.d.ts +1 -0
- package/src/objects/scheduling/scheduling.edge.failure.d.ts.map +1 -0
- package/src/objects/time/time.edge.d.ts +1 -0
- package/src/objects/time/time.edge.d.ts.map +1 -0
- package/src/objects-interface/edges/edge.abstract.d.ts +1 -0
- package/src/objects-interface/edges/edge.abstract.d.ts.map +1 -0
- package/src/objects-interface/face.abstract.d.ts +1 -0
- package/src/objects-interface/face.abstract.d.ts.map +1 -0
- package/src/objects-interface/solid.abstract.d.ts +1 -0
- package/src/objects-interface/solid.abstract.d.ts.map +1 -0
- package/src/objects-interface/uv.abstract.d.ts +1 -0
- package/src/objects-interface/uv.abstract.d.ts.map +1 -0
- package/src/objects-interface/vertices/vertex.abstract.d.ts +1 -0
- package/src/objects-interface/vertices/vertex.abstract.d.ts.map +1 -0
- package/src/shared/payload.abstract.d.ts +1 -0
- package/src/shared/payload.abstract.d.ts.map +1 -0
- package/src/shared/request.abstract.d.ts +1 -0
- package/src/shared/request.abstract.d.ts.map +1 -0
- package/src/shared/response.abstract.d.ts +1 -0
- package/src/shared/response.abstract.d.ts.map +1 -0
- package/tsconfig-lib.json +3 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/types/boolean.d.ts +19 -0
- package/types/string.d.ts +33 -0
|
@@ -7,7 +7,11 @@ exports.DatetimeEdge = void 0;
|
|
|
7
7
|
const date_holidays_1 = __importDefault(require("date-holidays"));
|
|
8
8
|
const moment_1 = __importDefault(require("moment"));
|
|
9
9
|
const index_1 = require("#/index");
|
|
10
|
-
const
|
|
10
|
+
const day_name_to_english_mapper_1 = require("#/objects/datetime/edges/locale/day/day-name-to-english.mapper");
|
|
11
|
+
const day_name_to_portuguese_mapper_1 = require("#/objects/datetime/edges/locale/day/day-name-to-portuguese.mapper");
|
|
12
|
+
const today_to_language_mapper_1 = require("#/objects/datetime/edges/locale/day/today-to-language.mapper");
|
|
13
|
+
const month_to_english_mapper_1 = require("#/objects/datetime/edges/locale/month/month-to-english.mapper");
|
|
14
|
+
const month_to_portuguese_mapper_1 = require("#/objects/datetime/edges/locale/month/month-to-portuguese.mapper");
|
|
11
15
|
const week_day_enum_1 = require("#/objects/datetime/points/week-day.enum");
|
|
12
16
|
class DatetimeEdge {
|
|
13
17
|
constructor(value) {
|
|
@@ -30,75 +34,52 @@ class DatetimeEdge {
|
|
|
30
34
|
this.validate();
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @returns
|
|
37
|
+
* Returns a human-friendly date string in the format "Day, Mon DD".
|
|
38
|
+
* Uses day and month names in the specified locale.
|
|
39
|
+
* @returns A formatted string such as "Sunday, Mar 29" or "Today, Apr 1"
|
|
36
40
|
* @example
|
|
37
|
-
* new DatetimeEdge(new Date("2026-03-29")).toFriendlyString() // "
|
|
38
|
-
* new DatetimeEdge(new Date()).toFriendlyString() // "
|
|
41
|
+
* new DatetimeEdge(new Date("2026-03-29")).toFriendlyString() // "Sunday, Mar 29"
|
|
42
|
+
* new DatetimeEdge(new Date()).toFriendlyString() // "Today, Apr 1"
|
|
39
43
|
*/
|
|
40
44
|
toFriendlyString(language) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"Segunda",
|
|
44
|
-
"Terça",
|
|
45
|
-
"Quarta",
|
|
46
|
-
"Quinta",
|
|
47
|
-
"Sexta",
|
|
48
|
-
"Sábado",
|
|
49
|
-
];
|
|
50
|
-
const monthAbbr = [
|
|
51
|
-
"Jan",
|
|
52
|
-
"Fev",
|
|
53
|
-
"Mar",
|
|
54
|
-
"Abr",
|
|
55
|
-
"Mai",
|
|
56
|
-
"Jun",
|
|
57
|
-
"Jul",
|
|
58
|
-
"Ago",
|
|
59
|
-
"Set",
|
|
60
|
-
"Out",
|
|
61
|
-
"Nov",
|
|
62
|
-
"Dez",
|
|
63
|
-
];
|
|
64
|
-
let dayLabel = dayNames[this.date.day()];
|
|
45
|
+
let dayOfWeekLabel = this.getDayOfWeek(language);
|
|
46
|
+
const monthLabel = this.getNameOfMonth(language);
|
|
65
47
|
if (this.isToday()) {
|
|
66
|
-
|
|
48
|
+
dayOfWeekLabel = new today_to_language_mapper_1.TodayToLanguageMapper().toMap(language);
|
|
67
49
|
}
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
return `${dayLabel}, ${month} ${day}`;
|
|
50
|
+
const dayOfMonth = this.getDayOfMonth();
|
|
51
|
+
return `${dayOfWeekLabel}, ${monthLabel} ${dayOfMonth}`;
|
|
71
52
|
}
|
|
72
53
|
// ==================== Comparações ====================
|
|
73
54
|
/**
|
|
74
|
-
*
|
|
75
|
-
* @param
|
|
76
|
-
* @returns true
|
|
55
|
+
* Checks whether this date is later than another date.
|
|
56
|
+
* @param datetime - Date to compare against.
|
|
57
|
+
* @returns `true` if this date is greater than `datetime`; otherwise, `false`.
|
|
77
58
|
* @example
|
|
78
59
|
* new DatetimeEdge(new Date("2026-12-01")).isAfter(new DatetimeEdge(new Date("2026-01-01"))) // true
|
|
79
60
|
*/
|
|
80
|
-
isAfter(
|
|
81
|
-
return this.date.isAfter(
|
|
61
|
+
isAfter(datetime) {
|
|
62
|
+
return this.date.isAfter(datetime.toDate());
|
|
82
63
|
}
|
|
83
64
|
/**
|
|
84
|
-
*
|
|
85
|
-
* @param
|
|
86
|
-
* @returns true
|
|
65
|
+
* Checks whether this date is earlier than another date.
|
|
66
|
+
* @param datetime - Date to compare against.
|
|
67
|
+
* @returns `true` if this date is less than `datetime`; otherwise, `false`.
|
|
87
68
|
* @example
|
|
88
69
|
* new DatetimeEdge(new Date("2026-01-01")).isBefore(new DatetimeEdge(new Date("2026-12-01"))) // true
|
|
89
70
|
*/
|
|
90
|
-
isBefore(
|
|
91
|
-
return this.date.isBefore(
|
|
71
|
+
isBefore(datetime) {
|
|
72
|
+
return this.date.isBefore(datetime.toDate());
|
|
92
73
|
}
|
|
93
74
|
/**
|
|
94
|
-
*
|
|
95
|
-
* @param
|
|
96
|
-
* @returns true
|
|
75
|
+
* Checks whether this date is equal to another date.
|
|
76
|
+
* @param datetime - Date to compare against.
|
|
77
|
+
* @returns `true` if the dates are equal; otherwise, `false`.
|
|
97
78
|
* @example
|
|
98
79
|
* new DatetimeEdge(new Date("2026-01-01")).isEquals(new DatetimeEdge(new Date("2026-01-01"))) // true
|
|
99
80
|
*/
|
|
100
|
-
isEquals(
|
|
101
|
-
return this.date.isSame(
|
|
81
|
+
isEquals(datetime) {
|
|
82
|
+
return this.date.isSame(datetime.toDate());
|
|
102
83
|
}
|
|
103
84
|
/**
|
|
104
85
|
* Verifica se esta data está entre duas outras datas (exclusivo).
|
|
@@ -116,39 +97,41 @@ class DatetimeEdge {
|
|
|
116
97
|
}
|
|
117
98
|
// ==================== Verificações de Dia ====================
|
|
118
99
|
/**
|
|
119
|
-
*
|
|
120
|
-
* @returns true
|
|
100
|
+
* Checks whether this date falls on a weekend (Saturday or Sunday).
|
|
101
|
+
* @returns `true` if the date is a Saturday or Sunday; otherwise, `false`.
|
|
121
102
|
* @example
|
|
122
|
-
* new DatetimeEdge(new Date("2026-03-14")).isWeekend() // true (
|
|
123
|
-
* new DatetimeEdge(new Date("2026-03-12")).isWeekend() // false (
|
|
103
|
+
* new DatetimeEdge(new Date("2026-03-14")).isWeekend() // true (Saturday)
|
|
104
|
+
* new DatetimeEdge(new Date("2026-03-12")).isWeekend() // false (Thursday)
|
|
124
105
|
*/
|
|
125
106
|
isWeekend() {
|
|
126
|
-
return [week_day_enum_1.WeekDayEnum.saturday, week_day_enum_1.WeekDayEnum.sunday].includes(this.
|
|
107
|
+
return [week_day_enum_1.WeekDayEnum.saturday, week_day_enum_1.WeekDayEnum.sunday].includes(this.getStandardDayOfWeek());
|
|
127
108
|
}
|
|
128
109
|
/**
|
|
129
|
-
*
|
|
130
|
-
* @
|
|
110
|
+
* Checks whether this date is a holiday in the specified country.
|
|
111
|
+
* @param country - The country whose holiday calendar will be used for validation.
|
|
112
|
+
* @returns `true` if the date is a holiday in the specified country; otherwise, `false`.
|
|
131
113
|
* @example
|
|
132
|
-
* new DatetimeEdge(new Date("2026-12-25")).isHoliday() // true (
|
|
133
|
-
* new DatetimeEdge(new Date("2026-03-12")).isHoliday() // false
|
|
114
|
+
* new DatetimeEdge(new Date("2026-12-25")).isHoliday("BR") // true (Christmas Day)
|
|
115
|
+
* new DatetimeEdge(new Date("2026-03-12")).isHoliday("BR") // false
|
|
134
116
|
*/
|
|
135
|
-
isHoliday() {
|
|
136
|
-
const holidays = new date_holidays_1.default(
|
|
117
|
+
isHoliday(country) {
|
|
118
|
+
const holidays = new date_holidays_1.default(country);
|
|
137
119
|
return holidays.isHoliday(this.date.toDate()) !== false;
|
|
138
120
|
}
|
|
139
121
|
/**
|
|
140
|
-
*
|
|
141
|
-
* @
|
|
122
|
+
* Checks whether the date is a business day (not a weekend or a holiday).
|
|
123
|
+
* @param country - The country whose holiday calendar will be used for validation.
|
|
124
|
+
* @returns `true` if the date is a business day; otherwise, `false`.
|
|
142
125
|
* @example
|
|
143
|
-
* new DatetimeEdge(new Date("2026-03-12")).isBusinessDay() // true (
|
|
144
|
-
* new DatetimeEdge(new Date("2026-12-25")).isBusinessDay() // false (
|
|
126
|
+
* new DatetimeEdge(new Date("2026-03-12")).isBusinessDay("BR") // true (Thursday)
|
|
127
|
+
* new DatetimeEdge(new Date("2026-12-25")).isBusinessDay("BR") // false (Christmas Day)
|
|
145
128
|
*/
|
|
146
|
-
isBusinessDay() {
|
|
147
|
-
return !this.isWeekend() && !this.isHoliday();
|
|
129
|
+
isBusinessDay(country) {
|
|
130
|
+
return !this.isWeekend() && !this.isHoliday(country);
|
|
148
131
|
}
|
|
149
132
|
/**
|
|
150
|
-
*
|
|
151
|
-
* @returns true
|
|
133
|
+
* Checks whether the date corresponds to today.
|
|
134
|
+
* @returns `true` if the date is today; otherwise, `false`.
|
|
152
135
|
* @example
|
|
153
136
|
* new DatetimeEdge(new Date()).isToday() // true
|
|
154
137
|
* new DatetimeEdge(new Date("2020-01-01")).isToday() // false
|
|
@@ -157,8 +140,8 @@ class DatetimeEdge {
|
|
|
157
140
|
return this.date.isSame((0, moment_1.default)(), "day");
|
|
158
141
|
}
|
|
159
142
|
/**
|
|
160
|
-
*
|
|
161
|
-
* @returns true
|
|
143
|
+
* Checks whether the date corresponds to yesterday.
|
|
144
|
+
* @returns `true` if the date is yesterday; otherwise, `false`.
|
|
162
145
|
* @example
|
|
163
146
|
* new DatetimeEdge(new Date()).isYesterday() // false
|
|
164
147
|
*/
|
|
@@ -166,8 +149,8 @@ class DatetimeEdge {
|
|
|
166
149
|
return this.date.isSame((0, moment_1.default)().subtract(1, "day"), "day");
|
|
167
150
|
}
|
|
168
151
|
/**
|
|
169
|
-
*
|
|
170
|
-
* @returns true
|
|
152
|
+
* Checks whether the date corresponds to tomorrow.
|
|
153
|
+
* @returns `true` if the date is tomorrow; otherwise, `false`.
|
|
171
154
|
* @example
|
|
172
155
|
* new DatetimeEdge(new Date()).isTomorrow() // false
|
|
173
156
|
*/
|
|
@@ -175,49 +158,65 @@ class DatetimeEdge {
|
|
|
175
158
|
return this.date.isSame((0, moment_1.default)().add(1, "day"), "day");
|
|
176
159
|
}
|
|
177
160
|
/**
|
|
178
|
-
*
|
|
179
|
-
* @param
|
|
180
|
-
* @returns true
|
|
161
|
+
* Checks whether the date is on the same day as another date.
|
|
162
|
+
* @param datetime - Date for comparison
|
|
163
|
+
* @returns `true` if both dates are on the same day, `false` otherwise
|
|
181
164
|
* @example
|
|
182
165
|
* const a = new DatetimeEdge(new Date("2026-03-12T08:00"));
|
|
183
166
|
* const b = new DatetimeEdge(new Date("2026-03-12T22:00"));
|
|
184
167
|
* a.isSameDay(b) // true
|
|
185
168
|
*/
|
|
186
|
-
isSameDay(
|
|
187
|
-
return this.date.isSame(
|
|
169
|
+
isSameDay(datetime) {
|
|
170
|
+
return this.date.isSame(datetime.toDate(), "day");
|
|
188
171
|
}
|
|
189
172
|
/**
|
|
190
|
-
*
|
|
191
|
-
* @param
|
|
192
|
-
* @returns true
|
|
173
|
+
* Checks whether the date is on the same month as another date.
|
|
174
|
+
* @param datetime - Date for comparison
|
|
175
|
+
* @returns `true` if both dates are on the same month and year, `false` otherwise
|
|
193
176
|
* @example
|
|
194
177
|
* const a = new DatetimeEdge(new Date("2026-03-01"));
|
|
195
178
|
* const b = new DatetimeEdge(new Date("2026-03-31"));
|
|
196
179
|
* a.isSameMonth(b) // true
|
|
197
180
|
*/
|
|
198
|
-
isSameMonth(
|
|
199
|
-
return this.date.isSame(
|
|
181
|
+
isSameMonth(datetime) {
|
|
182
|
+
return this.date.isSame(datetime.toDate(), "month");
|
|
200
183
|
}
|
|
201
184
|
/**
|
|
202
|
-
*
|
|
203
|
-
* @param
|
|
204
|
-
* @returns true
|
|
185
|
+
* Checks whether the date is on the same year as another date.
|
|
186
|
+
* @param datetime - Date for comparison
|
|
187
|
+
* @returns `true` if both dates are on the same year, `false` otherwise
|
|
205
188
|
* @example
|
|
206
189
|
* const a = new DatetimeEdge(new Date("2026-01-01"));
|
|
207
190
|
* const b = new DatetimeEdge(new Date("2026-12-31"));
|
|
208
191
|
* a.isSameYear(b) // true
|
|
209
192
|
*/
|
|
210
|
-
isSameYear(
|
|
211
|
-
return this.date.isSame(
|
|
193
|
+
isSameYear(datetime) {
|
|
194
|
+
return this.date.isSame(datetime.toDate(), "year");
|
|
212
195
|
}
|
|
213
196
|
// ==================== Getters ====================
|
|
214
197
|
/**
|
|
215
|
-
*
|
|
216
|
-
* @returns Enum WeekDayEnum
|
|
198
|
+
* Returns the day of the week for the date.
|
|
199
|
+
* @returns Enum WeekDayEnum representing the day of the week
|
|
217
200
|
* @example
|
|
218
201
|
* new DatetimeEdge(new Date("2026-03-12")).getDayOfWeek() // WeekDayEnum.thursday
|
|
219
202
|
*/
|
|
220
|
-
getDayOfWeek() {
|
|
203
|
+
getDayOfWeek(language) {
|
|
204
|
+
let dayOfWeek = new day_name_to_english_mapper_1.DayNameToEnglishMapper().toMap(this.date.day());
|
|
205
|
+
if (index_1._.isEqual(language, index_1.LanguagePoint.portuguese)) {
|
|
206
|
+
dayOfWeek = new day_name_to_portuguese_mapper_1.DayNameToPortugueseMapper().toMap(this.date.day());
|
|
207
|
+
}
|
|
208
|
+
return dayOfWeek;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Returns the standard day of the week as a {@link WeekDayEnum} value.
|
|
212
|
+
* This internal method provides the canonical weekday representation
|
|
213
|
+
* used throughout the class before any localization or formatting is applied.
|
|
214
|
+
*
|
|
215
|
+
* @returns The corresponding {@link WeekDayEnum} for the current date.
|
|
216
|
+
* @example
|
|
217
|
+
* new DatetimeEdge(new Date("2026-03-12")).getStandardDayOfWeek() // WeekDayEnum.thursday
|
|
218
|
+
*/
|
|
219
|
+
getStandardDayOfWeek() {
|
|
221
220
|
const daysOfWeek = [
|
|
222
221
|
week_day_enum_1.WeekDayEnum.sunday,
|
|
223
222
|
week_day_enum_1.WeekDayEnum.monday,
|
|
@@ -230,31 +229,21 @@ class DatetimeEdge {
|
|
|
230
229
|
return daysOfWeek[this.date.day()];
|
|
231
230
|
}
|
|
232
231
|
/**
|
|
233
|
-
*
|
|
234
|
-
* @returns Enum MonthNameEnum
|
|
232
|
+
* Returns the name of the month for the date.
|
|
233
|
+
* @returns Enum MonthNameEnum representing the month
|
|
235
234
|
* @example
|
|
236
235
|
* new DatetimeEdge(new Date("2026-03-12")).getNameOfMonth() // MonthNameEnum.march
|
|
237
236
|
*/
|
|
238
|
-
getNameOfMonth() {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
month_name_enum_1.MonthNameEnum.may,
|
|
245
|
-
month_name_enum_1.MonthNameEnum.june,
|
|
246
|
-
month_name_enum_1.MonthNameEnum.july,
|
|
247
|
-
month_name_enum_1.MonthNameEnum.august,
|
|
248
|
-
month_name_enum_1.MonthNameEnum.september,
|
|
249
|
-
month_name_enum_1.MonthNameEnum.october,
|
|
250
|
-
month_name_enum_1.MonthNameEnum.november,
|
|
251
|
-
month_name_enum_1.MonthNameEnum.december,
|
|
252
|
-
];
|
|
253
|
-
return months[this.date.month()];
|
|
237
|
+
getNameOfMonth(language) {
|
|
238
|
+
let month = new month_to_english_mapper_1.MonthNameToEnglishMapper().toMap(this.date.month());
|
|
239
|
+
if (index_1._.isEqual(language, index_1.LanguagePoint.portuguese)) {
|
|
240
|
+
month = new month_to_portuguese_mapper_1.MonthNameToPortugueseMapper().toMap(this.date.month());
|
|
241
|
+
}
|
|
242
|
+
return month;
|
|
254
243
|
}
|
|
255
244
|
/**
|
|
256
|
-
*
|
|
257
|
-
* @returns
|
|
245
|
+
* Returns the day of the month for the date.
|
|
246
|
+
* @returns NNumber of the day (1-31)
|
|
258
247
|
* @example
|
|
259
248
|
* new DatetimeEdge(new Date("2026-03-12")).getDayOfMonth() // 12
|
|
260
249
|
*/
|
|
@@ -262,8 +251,8 @@ class DatetimeEdge {
|
|
|
262
251
|
return this.date.date();
|
|
263
252
|
}
|
|
264
253
|
/**
|
|
265
|
-
*
|
|
266
|
-
* @returns
|
|
254
|
+
* Returns the month number for the date (0-11).
|
|
255
|
+
* @returns Month number (0=January, 11=December)
|
|
267
256
|
* @example
|
|
268
257
|
* new DatetimeEdge(new Date("2026-03-12")).getNumberOfMonth() // 2
|
|
269
258
|
*/
|
|
@@ -271,8 +260,8 @@ class DatetimeEdge {
|
|
|
271
260
|
return this.date.month();
|
|
272
261
|
}
|
|
273
262
|
/**
|
|
274
|
-
*
|
|
275
|
-
* @returns
|
|
263
|
+
* Returns the year of the date.
|
|
264
|
+
* @returns The year number.
|
|
276
265
|
* @example
|
|
277
266
|
* new DatetimeEdge(new Date("2026-03-12")).getYear() // 2026
|
|
278
267
|
*/
|
|
@@ -280,8 +269,8 @@ class DatetimeEdge {
|
|
|
280
269
|
return this.date.year();
|
|
281
270
|
}
|
|
282
271
|
/**
|
|
283
|
-
*
|
|
284
|
-
* @returns
|
|
272
|
+
* Returns the hours of the date.
|
|
273
|
+
* @returns The hour number (0-23)
|
|
285
274
|
* @example
|
|
286
275
|
* new DatetimeEdge(new Date("2026-03-12T14:30:00")).getHours() // 14
|
|
287
276
|
*/
|
|
@@ -289,8 +278,8 @@ class DatetimeEdge {
|
|
|
289
278
|
return this.date.hours();
|
|
290
279
|
}
|
|
291
280
|
/**
|
|
292
|
-
*
|
|
293
|
-
* @returns
|
|
281
|
+
* Returns the minutes of the date.
|
|
282
|
+
* @returns The minute number (0-59)
|
|
294
283
|
* @example
|
|
295
284
|
* new DatetimeEdge(new Date("2026-03-12T14:30:00")).getMinutes() // 30
|
|
296
285
|
*/
|
|
@@ -298,8 +287,8 @@ class DatetimeEdge {
|
|
|
298
287
|
return this.date.minutes();
|
|
299
288
|
}
|
|
300
289
|
/**
|
|
301
|
-
*
|
|
302
|
-
* @returns
|
|
290
|
+
* Returns the seconds of the date.
|
|
291
|
+
* @returns The second number (0-59)
|
|
303
292
|
* @example
|
|
304
293
|
* new DatetimeEdge(new Date("2026-03-12T14:30:45")).getSeconds() // 45
|
|
305
294
|
*/
|
|
@@ -308,9 +297,9 @@ class DatetimeEdge {
|
|
|
308
297
|
}
|
|
309
298
|
// ==================== Operações Aritméticas ====================
|
|
310
299
|
/**
|
|
311
|
-
*
|
|
312
|
-
* @param days -
|
|
313
|
-
* @returns
|
|
300
|
+
* Adds days to the date and returns a new instance.
|
|
301
|
+
* @param days - NNumber of days to add
|
|
302
|
+
* @returns New instance with the updated date
|
|
314
303
|
* @example
|
|
315
304
|
* new DatetimeEdge(new Date("2026-03-12")).addDays(5) // DatetimeEdge("2026-03-17")
|
|
316
305
|
*/
|
|
@@ -318,9 +307,9 @@ class DatetimeEdge {
|
|
|
318
307
|
return new DatetimeEdge(this.date.clone().add(days, "days").toDate());
|
|
319
308
|
}
|
|
320
309
|
/**
|
|
321
|
-
*
|
|
322
|
-
* @param days -
|
|
323
|
-
* @returns
|
|
310
|
+
* Subtracts days from the date and returns a new instance.
|
|
311
|
+
* @param days - NNumber of days to subtract
|
|
312
|
+
* @returns New instance with the updated date
|
|
324
313
|
* @example
|
|
325
314
|
* new DatetimeEdge(new Date("2026-03-12")).subtractDays(5) // DatetimeEdge("2026-03-07")
|
|
326
315
|
*/
|
|
@@ -328,9 +317,9 @@ class DatetimeEdge {
|
|
|
328
317
|
return new DatetimeEdge(this.date.clone().subtract(days, "days").toDate());
|
|
329
318
|
}
|
|
330
319
|
/**
|
|
331
|
-
*
|
|
332
|
-
* @param months -
|
|
333
|
-
* @returns
|
|
320
|
+
* Adds months to the date and returns a new instance.
|
|
321
|
+
* @param months - NNumber of months to add
|
|
322
|
+
* @returns New instance with the updated date
|
|
334
323
|
* @example
|
|
335
324
|
* new DatetimeEdge(new Date("2026-03-12")).addMonths(2) // DatetimeEdge("2026-05-12")
|
|
336
325
|
*/
|
|
@@ -338,9 +327,9 @@ class DatetimeEdge {
|
|
|
338
327
|
return new DatetimeEdge(this.date.clone().add(months, "months").toDate());
|
|
339
328
|
}
|
|
340
329
|
/**
|
|
341
|
-
*
|
|
342
|
-
* @param months -
|
|
343
|
-
* @returns
|
|
330
|
+
* Subtracts months from the date and returns a new instance.
|
|
331
|
+
* @param months - NNumber of months to subtract
|
|
332
|
+
* @returns New instance with the updated date
|
|
344
333
|
* @example
|
|
345
334
|
* new DatetimeEdge(new Date("2026-03-12")).subtractMonths(2) // DatetimeEdge("2026-01-12")
|
|
346
335
|
*/
|
|
@@ -348,9 +337,9 @@ class DatetimeEdge {
|
|
|
348
337
|
return new DatetimeEdge(this.date.clone().subtract(months, "months").toDate());
|
|
349
338
|
}
|
|
350
339
|
/**
|
|
351
|
-
*
|
|
352
|
-
* @param years -
|
|
353
|
-
* @returns
|
|
340
|
+
* Adds years to the date and returns a new instance.
|
|
341
|
+
* @param years - NNumber of years to add
|
|
342
|
+
* @returns New instance with the updated date
|
|
354
343
|
* @example
|
|
355
344
|
* new DatetimeEdge(new Date("2026-03-12")).addYears(1) // DatetimeEdge("2027-03-12")
|
|
356
345
|
*/
|
|
@@ -358,9 +347,9 @@ class DatetimeEdge {
|
|
|
358
347
|
return new DatetimeEdge(this.date.clone().add(years, "years").toDate());
|
|
359
348
|
}
|
|
360
349
|
/**
|
|
361
|
-
*
|
|
362
|
-
* @param years -
|
|
363
|
-
* @returns
|
|
350
|
+
* Subtracts years from the date and returns a new instance.
|
|
351
|
+
* @param years - NNumber of years to subtract
|
|
352
|
+
* @returns New instance with the updated date
|
|
364
353
|
* @example
|
|
365
354
|
* new DatetimeEdge(new Date("2026-03-12")).subtractYears(1) // DatetimeEdge("2025-03-12")
|
|
366
355
|
*/
|
|
@@ -368,9 +357,9 @@ class DatetimeEdge {
|
|
|
368
357
|
return new DatetimeEdge(this.date.clone().subtract(years, "years").toDate());
|
|
369
358
|
}
|
|
370
359
|
/**
|
|
371
|
-
*
|
|
372
|
-
* @param hours -
|
|
373
|
-
* @returns
|
|
360
|
+
* Adds hours to the date and returns a new instance.
|
|
361
|
+
* @param hours - NNumber of hours to add
|
|
362
|
+
* @returns New instance with the updated date
|
|
374
363
|
* @example
|
|
375
364
|
* new DatetimeEdge(new Date("2026-03-12T08:00")).addHours(3) // DatetimeEdge("2026-03-12T11:00")
|
|
376
365
|
*/
|
|
@@ -378,9 +367,9 @@ class DatetimeEdge {
|
|
|
378
367
|
return new DatetimeEdge(this.date.clone().add(hours, "hours").toDate());
|
|
379
368
|
}
|
|
380
369
|
/**
|
|
381
|
-
*
|
|
382
|
-
* @param minutes -
|
|
383
|
-
* @returns
|
|
370
|
+
* Adds minutes to the date and returns a new instance.
|
|
371
|
+
* @param minutes - NNumber of minutes to add
|
|
372
|
+
* @returns New instance with the updated date
|
|
384
373
|
* @example
|
|
385
374
|
* new DatetimeEdge(new Date("2026-03-12T08:00")).addMinutes(30) // DatetimeEdge("2026-03-12T08:30")
|
|
386
375
|
*/
|
|
@@ -388,60 +377,60 @@ class DatetimeEdge {
|
|
|
388
377
|
return new DatetimeEdge(this.date.clone().add(minutes, "minutes").toDate());
|
|
389
378
|
}
|
|
390
379
|
/**
|
|
391
|
-
*
|
|
392
|
-
* @param
|
|
393
|
-
* @returns
|
|
380
|
+
* Calculates the difference in days between this date and another.
|
|
381
|
+
* @param datetime - Date to calculate the difference from
|
|
382
|
+
* @returns NNumber of days difference (positive if this > datetime)
|
|
394
383
|
* @example
|
|
395
384
|
* new DatetimeEdge(new Date("2026-03-15")).diffInDays(new DatetimeEdge(new Date("2026-03-10"))) // 5
|
|
396
385
|
*/
|
|
397
|
-
diffInDays(
|
|
398
|
-
return this.date.diff(
|
|
386
|
+
diffInDays(datetime) {
|
|
387
|
+
return this.date.diff(datetime.toDate(), "days");
|
|
399
388
|
}
|
|
400
389
|
/**
|
|
401
|
-
*
|
|
402
|
-
* @param
|
|
403
|
-
* @returns
|
|
390
|
+
* Calculates the difference in months between this date and another.
|
|
391
|
+
* @param datetime - Date to calculate the difference from
|
|
392
|
+
* @returns NNumber of months difference (positive if this > datetime)
|
|
404
393
|
* @example
|
|
405
394
|
* new DatetimeEdge(new Date("2026-05-12")).diffInMonths(new DatetimeEdge(new Date("2026-03-12"))) // 2
|
|
406
395
|
*/
|
|
407
|
-
diffInMonths(
|
|
408
|
-
return this.date.diff(
|
|
396
|
+
diffInMonths(datetime) {
|
|
397
|
+
return this.date.diff(datetime.toDate(), "months");
|
|
409
398
|
}
|
|
410
399
|
/**
|
|
411
|
-
*
|
|
412
|
-
* @param
|
|
413
|
-
* @returns
|
|
400
|
+
* Calculates the difference in years between this date and another date.
|
|
401
|
+
* @param datetime - Date to calculate the difference against.
|
|
402
|
+
* @returns The number of years between the dates (positive if this date is later than `datetime`).
|
|
414
403
|
* @example
|
|
415
404
|
* new DatetimeEdge(new Date("2028-03-12")).diffInYears(new DatetimeEdge(new Date("2026-03-12"))) // 2
|
|
416
405
|
*/
|
|
417
|
-
diffInYears(
|
|
418
|
-
return this.date.diff(
|
|
406
|
+
diffInYears(datetime) {
|
|
407
|
+
return this.date.diff(datetime.toDate(), "years");
|
|
419
408
|
}
|
|
420
409
|
/**
|
|
421
410
|
* Calcula a diferença em horas entre esta data e outra.
|
|
422
|
-
* @param
|
|
423
|
-
* @returns Número de horas de diferença (positivo se this >
|
|
411
|
+
* @param datetime - Data para calcular a diferença
|
|
412
|
+
* @returns Número de horas de diferença (positivo se this > datetime)
|
|
424
413
|
* @example
|
|
425
414
|
* new DatetimeEdge(new Date("2026-03-12T14:00")).diffInHours(new DatetimeEdge(new Date("2026-03-12T08:00"))) // 6
|
|
426
415
|
*/
|
|
427
|
-
diffInHours(
|
|
428
|
-
return this.date.diff(
|
|
416
|
+
diffInHours(datetime) {
|
|
417
|
+
return this.date.diff(datetime.toDate(), "hours");
|
|
429
418
|
}
|
|
430
419
|
/**
|
|
431
|
-
*
|
|
432
|
-
* @param
|
|
433
|
-
* @returns
|
|
420
|
+
* Calculates the difference in minutes between this date and another date.
|
|
421
|
+
* @param datetime - Date to calculate the difference against.
|
|
422
|
+
* @returns The number of minutes between the dates (positive if this date is later than `datetime`).
|
|
434
423
|
* @example
|
|
435
424
|
* new DatetimeEdge(new Date("2026-03-12T08:45")).diffInMinutes(new DatetimeEdge(new Date("2026-03-12T08:00"))) // 45
|
|
436
425
|
*/
|
|
437
|
-
diffInMinutes(
|
|
438
|
-
return this.date.diff(
|
|
426
|
+
diffInMinutes(datetime) {
|
|
427
|
+
return this.date.diff(datetime.toDate(), "minutes");
|
|
439
428
|
}
|
|
440
429
|
/**
|
|
441
|
-
*
|
|
442
|
-
* @returns
|
|
430
|
+
* Returns a human-readable difference between this date and the current moment.
|
|
431
|
+
* @returns A descriptive string such as "3 days ago.", "2 hours ago.", etc.
|
|
443
432
|
* @example
|
|
444
|
-
* new DatetimeEdge(new Date("2025-03-12")).diffFromNow() // "
|
|
433
|
+
* new DatetimeEdge(new Date("2025-03-12")).diffFromNow() // "1 year ago."
|
|
445
434
|
*/
|
|
446
435
|
diffFromNow() {
|
|
447
436
|
const now = (0, moment_1.default)();
|
|
@@ -470,8 +459,8 @@ class DatetimeEdge {
|
|
|
470
459
|
}
|
|
471
460
|
// ==================== Início e Fim de Período ====================
|
|
472
461
|
/**
|
|
473
|
-
*
|
|
474
|
-
* @returns
|
|
462
|
+
* Returns the start of the day (00:00:00.000) as a new instance.
|
|
463
|
+
* @returns A new instance with the time set to the beginning of the day
|
|
475
464
|
* @example
|
|
476
465
|
* new DatetimeEdge(new Date("2026-03-12T14:30")).startOfDay()
|
|
477
466
|
* // DatetimeEdge("2026-03-12T00:00:00.000")
|
|
@@ -480,8 +469,8 @@ class DatetimeEdge {
|
|
|
480
469
|
return new DatetimeEdge(this.date.clone().startOf("day").toDate());
|
|
481
470
|
}
|
|
482
471
|
/**
|
|
483
|
-
*
|
|
484
|
-
* @returns
|
|
472
|
+
* Returns the end of the day (23:59:59.999) as a new instance.
|
|
473
|
+
* @returns A new instance with the time set to the end of the day
|
|
485
474
|
* @example
|
|
486
475
|
* new DatetimeEdge(new Date("2026-03-12T08:00")).endOfDay()
|
|
487
476
|
* // DatetimeEdge("2026-03-12T23:59:59.999")
|
|
@@ -490,8 +479,8 @@ class DatetimeEdge {
|
|
|
490
479
|
return new DatetimeEdge(this.date.clone().endOf("day").toDate());
|
|
491
480
|
}
|
|
492
481
|
/**
|
|
493
|
-
*
|
|
494
|
-
* @returns
|
|
482
|
+
* Returns the start of the month as a new instance.
|
|
483
|
+
* @returns A new instance pointing to the first day of the month at midnight
|
|
495
484
|
* @example
|
|
496
485
|
* new DatetimeEdge(new Date("2026-03-12")).startOfMonth()
|
|
497
486
|
* // DatetimeEdge("2026-03-01T00:00:00.000")
|
|
@@ -500,8 +489,8 @@ class DatetimeEdge {
|
|
|
500
489
|
return new DatetimeEdge(this.date.clone().startOf("month").toDate());
|
|
501
490
|
}
|
|
502
491
|
/**
|
|
503
|
-
*
|
|
504
|
-
* @returns
|
|
492
|
+
* Returns the end of the month as a new instance.
|
|
493
|
+
* @returns A new instance pointing to the last day of the month at the end of the day
|
|
505
494
|
* @example
|
|
506
495
|
* new DatetimeEdge(new Date("2026-03-12")).endOfMonth()
|
|
507
496
|
* // DatetimeEdge("2026-03-31T23:59:59.999")
|
|
@@ -510,8 +499,8 @@ class DatetimeEdge {
|
|
|
510
499
|
return new DatetimeEdge(this.date.clone().endOf("month").toDate());
|
|
511
500
|
}
|
|
512
501
|
/**
|
|
513
|
-
*
|
|
514
|
-
* @returns
|
|
502
|
+
* Returns the start of the year as a new instance.
|
|
503
|
+
* @returns A new instance pointing to the first day of the year at midnight
|
|
515
504
|
* @example
|
|
516
505
|
* new DatetimeEdge(new Date("2026-03-12")).startOfYear()
|
|
517
506
|
* // DatetimeEdge("2026-01-01T00:00:00.000")
|
|
@@ -520,8 +509,8 @@ class DatetimeEdge {
|
|
|
520
509
|
return new DatetimeEdge(this.date.clone().startOf("year").toDate());
|
|
521
510
|
}
|
|
522
511
|
/**
|
|
523
|
-
*
|
|
524
|
-
* @returns
|
|
512
|
+
* Returns the end of the year as a new instance.
|
|
513
|
+
* @returns A new instance pointing to the last day of the year at the end of the day
|
|
525
514
|
* @example
|
|
526
515
|
* new DatetimeEdge(new Date("2026-03-12")).endOfYear()
|
|
527
516
|
* // DatetimeEdge("2026-12-31T23:59:59.999")
|
|
@@ -531,19 +520,19 @@ class DatetimeEdge {
|
|
|
531
520
|
}
|
|
532
521
|
// ==================== Clonagem e Imutabilidade ====================
|
|
533
522
|
/**
|
|
534
|
-
*
|
|
535
|
-
* @returns
|
|
523
|
+
* Creates an independent copy of this DatetimeEdge instance.
|
|
524
|
+
* @returns A new instance with the same date value
|
|
536
525
|
* @example
|
|
537
526
|
* const dt1 = new DatetimeEdge(new Date("2026-03-12"));
|
|
538
|
-
* const dt2 = dt1.clone(); //
|
|
527
|
+
* const dt2 = dt1.clone(); // independent instance
|
|
539
528
|
*/
|
|
540
529
|
clone() {
|
|
541
530
|
return new DatetimeEdge(this.date.toDate());
|
|
542
531
|
}
|
|
543
532
|
/**
|
|
544
|
-
*
|
|
545
|
-
* @param date -
|
|
546
|
-
* @returns
|
|
533
|
+
* Returns a new instance with the date changed, keeping the time.
|
|
534
|
+
* @param date - New Date object
|
|
535
|
+
* @returns New instance with the provided value
|
|
547
536
|
* @example
|
|
548
537
|
* new DatetimeEdge(new Date("2026-03-12")).withDate(new Date("2026-12-25"))
|
|
549
538
|
* // DatetimeEdge("2026-12-25")
|
|
@@ -553,8 +542,8 @@ class DatetimeEdge {
|
|
|
553
542
|
}
|
|
554
543
|
// ==================== Formatação ====================
|
|
555
544
|
/**
|
|
556
|
-
*
|
|
557
|
-
* @returns String
|
|
545
|
+
* Returns the date in ISO 8601 format.
|
|
546
|
+
* @returns String in the format "YYYY-MM-DDTHH:mm:ss.sssZ"
|
|
558
547
|
* @example
|
|
559
548
|
* new DatetimeEdge(new Date("2026-03-12")).toISOString() // "2026-03-12T00:00:00.000Z"
|
|
560
549
|
*/
|
|
@@ -562,8 +551,8 @@ class DatetimeEdge {
|
|
|
562
551
|
return this.date.toISOString();
|
|
563
552
|
}
|
|
564
553
|
/**
|
|
565
|
-
*
|
|
566
|
-
* @returns
|
|
554
|
+
* Returns the date as a native Date object.
|
|
555
|
+
* @returns Date object representing this date
|
|
567
556
|
* @example
|
|
568
557
|
* new DatetimeEdge(new Date("2026-03-12")).toDate() // Date object
|
|
569
558
|
*/
|
|
@@ -571,8 +560,8 @@ class DatetimeEdge {
|
|
|
571
560
|
return this.date.toDate();
|
|
572
561
|
}
|
|
573
562
|
/**
|
|
574
|
-
*
|
|
575
|
-
* @returns String
|
|
563
|
+
* Returns the date in YYYY-MM-DD format.
|
|
564
|
+
* @returns String in the format "YYYY-MM-DD"
|
|
576
565
|
* @example
|
|
577
566
|
* new DatetimeEdge(new Date("2026-03-12")).toYYYYMMDD() // "2026-03-12"
|
|
578
567
|
*/
|
|
@@ -580,7 +569,7 @@ class DatetimeEdge {
|
|
|
580
569
|
return this.date.format("YYYY-MM-DD");
|
|
581
570
|
}
|
|
582
571
|
/**
|
|
583
|
-
*
|
|
572
|
+
* Returns the date in DD/MM/YYYY format (Brazilian standard).
|
|
584
573
|
* @returns String no formato "DD/MM/YYYY"
|
|
585
574
|
* @example
|
|
586
575
|
* new DatetimeEdge(new Date("2026-03-12")).toDDMMYYYY() // "12/03/2026"
|
|
@@ -589,8 +578,8 @@ class DatetimeEdge {
|
|
|
589
578
|
return this.date.format("DD/MM/YYYY");
|
|
590
579
|
}
|
|
591
580
|
/**
|
|
592
|
-
*
|
|
593
|
-
* @returns
|
|
581
|
+
* Returns the date and time in the format DD/MM/YYYY HH:mm.
|
|
582
|
+
* @returns A string in the format "DD/MM/YYYY HH:mm".
|
|
594
583
|
* @example
|
|
595
584
|
* new DatetimeEdge(new Date("2026-03-12T14:30")).toDDMMYYYYHHmm() // "12/03/2026 14:30"
|
|
596
585
|
*/
|
|
@@ -598,9 +587,9 @@ class DatetimeEdge {
|
|
|
598
587
|
return this.date.format("DD/MM/YYYY HH:mm");
|
|
599
588
|
}
|
|
600
589
|
/**
|
|
601
|
-
*
|
|
602
|
-
* @param format -
|
|
603
|
-
* @returns
|
|
590
|
+
* Returns the date formatted with a custom pattern from moment.js.
|
|
591
|
+
* @param format - Formatting pattern (e.g., "YYYY-MM-DD HH:mm:ss")
|
|
592
|
+
* @returns Formatted string according to the provided pattern
|
|
604
593
|
* @example
|
|
605
594
|
* new DatetimeEdge(new Date("2026-03-12T14:30")).format("MMMM Do YYYY") // "March 12th 2026"
|
|
606
595
|
*/
|
|
@@ -608,8 +597,8 @@ class DatetimeEdge {
|
|
|
608
597
|
return this.date.format(format);
|
|
609
598
|
}
|
|
610
599
|
/**
|
|
611
|
-
*
|
|
612
|
-
* @returns
|
|
600
|
+
* Returns the timestamp in milliseconds of the date.
|
|
601
|
+
* @returns NNumber of milliseconds since 01/01/1970 UTC
|
|
613
602
|
* @example
|
|
614
603
|
* new DatetimeEdge(new Date("2026-03-12")).timestamp() // 1773273600000
|
|
615
604
|
*/
|
|
@@ -617,8 +606,8 @@ class DatetimeEdge {
|
|
|
617
606
|
return this.date.valueOf();
|
|
618
607
|
}
|
|
619
608
|
/**
|
|
620
|
-
*
|
|
621
|
-
* @returns
|
|
609
|
+
* Returns the Unix timestamp in seconds of the date.
|
|
610
|
+
* @returns NNumber of seconds since 01/01/1970 UTC
|
|
622
611
|
* @example
|
|
623
612
|
* new DatetimeEdge(new Date("2026-03-12")).unix() // 1773273600
|
|
624
613
|
*/
|
|
@@ -627,19 +616,19 @@ class DatetimeEdge {
|
|
|
627
616
|
}
|
|
628
617
|
// ==================== Métodos Estáticos ====================
|
|
629
618
|
/**
|
|
630
|
-
*
|
|
631
|
-
* @returns
|
|
619
|
+
* Creates a new DatetimeEdge representing the current moment.
|
|
620
|
+
* @returns New instance with the current date and time
|
|
632
621
|
* @example
|
|
633
|
-
* DatetimeEdge.now() // DatetimeEdge
|
|
622
|
+
* DatetimeEdge.now() // DatetimeEdge with the current date and time
|
|
634
623
|
*/
|
|
635
624
|
static now() {
|
|
636
625
|
return new DatetimeEdge(new Date());
|
|
637
626
|
}
|
|
638
627
|
/**
|
|
639
|
-
*
|
|
640
|
-
* @param dates - Array
|
|
641
|
-
* @returns
|
|
642
|
-
* @throws {Error}
|
|
628
|
+
* Returns the latest (most recent) date from an array.
|
|
629
|
+
* @param dates - Array of DatetimeEdge instances to compare
|
|
630
|
+
* @returns The instance with the latest date
|
|
631
|
+
* @throws {Error} If the array is empty
|
|
643
632
|
* @example
|
|
644
633
|
* DatetimeEdge.max([
|
|
645
634
|
* new DatetimeEdge(new Date("2026-01-01")),
|
|
@@ -653,10 +642,10 @@ class DatetimeEdge {
|
|
|
653
642
|
return dates.reduce((max, date) => (date.isAfter(max) ? date : max));
|
|
654
643
|
}
|
|
655
644
|
/**
|
|
656
|
-
*
|
|
657
|
-
* @param dates - Array
|
|
658
|
-
* @returns
|
|
659
|
-
* @throws {Error}
|
|
645
|
+
* Returns the earliest (oldest) date from an array.
|
|
646
|
+
* @param dates - Array of DatetimeEdge instances to compare
|
|
647
|
+
* @returns The instance with the earliest date
|
|
648
|
+
* @throws {Error} If the array is empty
|
|
660
649
|
* @example
|
|
661
650
|
* DatetimeEdge.min([
|
|
662
651
|
* new DatetimeEdge(new Date("2026-01-01")),
|
|
@@ -671,8 +660,8 @@ class DatetimeEdge {
|
|
|
671
660
|
}
|
|
672
661
|
// ==================== Privados ====================
|
|
673
662
|
/**
|
|
674
|
-
*
|
|
675
|
-
* @throws {Error}
|
|
663
|
+
* Validates whether the date provided to the constructor is a valid date.
|
|
664
|
+
* @throws {Error} If the date is invalid.
|
|
676
665
|
*/
|
|
677
666
|
validate() {
|
|
678
667
|
if (!(0, moment_1.default)(this.date).isValid()) {
|