@atlantjs/arch 15.6.7 → 15.7.0

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.
Files changed (106) hide show
  1. package/index.js +60 -0
  2. package/package.json +4 -3
  3. package/{tsconfig.tsbuildinfo → tsconfig.build.tsbuildinfo} +1 -1
  4. package/src/@tool-box/tests/builder.abstract.util.js +0 -39
  5. package/src/@tool-box/tests/builders/datetime/datetime.edge.builder.js +0 -15
  6. package/src/@tool-box/tests/builders/failures/dummies/failure.dummy.js +0 -13
  7. package/src/@tool-box/tests/builders/failures/failure.builder.js +0 -17
  8. package/src/@tool-box/tests/builders/metadata/metadata-uv.builder.js +0 -18
  9. package/src/@tool-box/tests/builders/metadata/metadata.edge.builder.js +0 -15
  10. package/src/@tool-box/tests/builders/user/email.edge.builder.js +0 -15
  11. package/src/@tool-box/tests/builders/user/username.edge.builder.js +0 -15
  12. package/src/@tool-box/tests/faker/faker.js +0 -208
  13. package/src/@tool-box/utils/convert-units/convert-units.js +0 -154
  14. package/src/@tool-box/utils/datatypes/boolean-utils.js +0 -155
  15. package/src/@tool-box/utils/datatypes/generic-types.js +0 -3
  16. package/src/@tool-box/utils/datatypes/plainify.js +0 -2
  17. package/src/@tool-box/utils/datatypes/string-utils.js +0 -292
  18. package/src/@tool-box/utils/datetime/mappers/month.mapper.js +0 -58
  19. package/src/@tool-box/utils/datetime/mappers/points/month-abbreviation.enum.js +0 -18
  20. package/src/@tool-box/utils/datetime/mappers/points/month-number.enum.js +0 -18
  21. package/src/@tool-box/utils/ducts/common.js +0 -47
  22. package/src/@tool-box/utils/ducts/optional-type.js +0 -128
  23. package/src/@tool-box/utils/ducts/return-type.js +0 -67
  24. package/src/@tool-box/utils/http-provider/http-provider-failure-response.js +0 -19
  25. package/src/@tool-box/utils/http-provider/http-provider-success-response.js +0 -20
  26. package/src/@tool-box/utils/http-provider/http-provider.js +0 -85
  27. package/src/@tool-box/utils/logger/index.js +0 -31
  28. package/src/@tool-box/utils/map/map.abstract.js +0 -84
  29. package/src/@tool-box/utils/random/random.js +0 -260
  30. package/src/@tool-box/utils/type-guard/guardian-exception.js +0 -6
  31. package/src/@tool-box/utils/type-guard/guardian.js +0 -625
  32. package/src/@tool-box/utils/type-guard/guardian.type.js +0 -2
  33. package/src/@tool-box/utils/validators/is-cron-expression.js +0 -39
  34. package/src/@tool-box/utils/validators/is-date-string.js +0 -42
  35. package/src/@tool-box/utils/validators/is-password-match.js +0 -27
  36. package/src/@tool-box/utils/validators/is-password-policy.validator.js +0 -30
  37. package/src/@tool-box/utils/validators/is-schedule.js +0 -43
  38. package/src/@tool-box/utils/validators/is-time-string.js +0 -39
  39. package/src/@tool-box/utils/validators/is-ulid.js +0 -39
  40. package/src/index.js +0 -179
  41. package/src/objects/@common/edges/email.edge.js +0 -94
  42. package/src/objects/@common/edges/ulid.sketch.edge.js +0 -91
  43. package/src/objects/@common/edges/url.edge.js +0 -269
  44. package/src/objects/@common/edges/username.edge.js +0 -41
  45. package/src/objects/@common/edges/uuid.sketch.edge.js +0 -145
  46. package/src/objects/@common/points/environment.point.js +0 -10
  47. package/src/objects/@common/points/header-token-name.point.js +0 -10
  48. package/src/objects/@common/points/http-status-codes.point.js +0 -244
  49. package/src/objects/amount/amount-value.edge.js +0 -76
  50. package/src/objects/amount/amount.edge.js +0 -626
  51. package/src/objects/amount/amount.polygon.js +0 -2
  52. package/src/objects/amount/amount.uv.js +0 -29
  53. package/src/objects/amount/points/duration-unit.point.js +0 -15
  54. package/src/objects/amount/points/energy-unit.point.js +0 -10
  55. package/src/objects/amount/points/length-unit.point.js +0 -10
  56. package/src/objects/amount/points/mass-unit.point.js +0 -11
  57. package/src/objects/amount/points/month-name.point.js +0 -18
  58. package/src/objects/amount/points/object-unit.point.js +0 -7
  59. package/src/objects/amount/points/units.point.js +0 -2
  60. package/src/objects/amount/points/volume-unit.point.js +0 -8
  61. package/src/objects/amount/points/week-day.point.js +0 -13
  62. package/src/objects/datetime/edges/datetime.edge.js +0 -672
  63. package/src/objects/datetime/edges/locale/day/day-name-to-english.mapper.js +0 -19
  64. package/src/objects/datetime/edges/locale/day/day-name-to-portuguese.mapper.js +0 -19
  65. package/src/objects/datetime/edges/locale/day/today-to-language.mapper.js +0 -15
  66. package/src/objects/datetime/edges/locale/holidays-country.type.js +0 -2
  67. package/src/objects/datetime/edges/locale/month/month-to-english.mapper.js +0 -24
  68. package/src/objects/datetime/edges/locale/month/month-to-portuguese.mapper.js +0 -24
  69. package/src/objects/datetime/points/month-name.enum.js +0 -18
  70. package/src/objects/datetime/points/week-day.enum.js +0 -13
  71. package/src/objects/failure/edges/failure.abstract.js +0 -24
  72. package/src/objects/failure/edges/failure.abstract.polygon.js +0 -2
  73. package/src/objects/language/points/language.point.js +0 -135
  74. package/src/objects/metadata/metadata.edge.js +0 -25
  75. package/src/objects/metadata/metadata.polygon.js +0 -2
  76. package/src/objects/metadata/metadata.uv.js +0 -29
  77. package/src/objects/password/password.edge.js +0 -175
  78. package/src/objects/password/password.polygon.js +0 -2
  79. package/src/objects/password/steps/not-allowing-consecutive-chars-step.js +0 -34
  80. package/src/objects/password/steps/not-allowing-date-step.js +0 -61
  81. package/src/objects/password/steps/not-allowing-phone-step.js +0 -27
  82. package/src/objects/password/steps/not-allowing-repeated-chars-step.js +0 -34
  83. package/src/objects/password/steps/not-allowing-string-step.js +0 -19
  84. package/src/objects/password/steps/not-allowing-these-chars-step.js +0 -17
  85. package/src/objects/password/steps/numeric-step.js +0 -13
  86. package/src/objects/password/steps/with-at-least-one-letter-step.js +0 -14
  87. package/src/objects/password/steps/with-at-least-one-number-digit-step.js +0 -14
  88. package/src/objects/password/steps/with-at-least-one-special-char-step.js +0 -14
  89. package/src/objects/password/steps/with-length-step.js +0 -18
  90. package/src/objects/password/validation-step.js +0 -9
  91. package/src/objects/password/validation-step.type.js +0 -2
  92. package/src/objects/primitives/boolean.edge.sketch.js +0 -147
  93. package/src/objects/primitives/datetime.edge.sketch.js +0 -7
  94. package/src/objects/primitives/number.edge.sketch.js +0 -346
  95. package/src/objects/primitives/string.edge.sketch.js +0 -218
  96. package/src/objects/scheduling/scheduling.edge.failure.js +0 -14
  97. package/src/objects/scheduling/scheduling.edge.js +0 -280
  98. package/src/objects/time/time.edge.js +0 -447
  99. package/src/objects-interface/edges/edge.abstract.js +0 -6
  100. package/src/objects-interface/face.abstract.js +0 -6
  101. package/src/objects-interface/solid.abstract.js +0 -11
  102. package/src/objects-interface/uv.abstract.js +0 -6
  103. package/src/objects-interface/vertices/vertex.abstract.js +0 -11
  104. package/src/shared/payload.abstract.js +0 -6
  105. package/src/shared/request.abstract.js +0 -3
  106. package/src/shared/response.abstract.js +0 -6
@@ -1,672 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DatetimeEdge = void 0;
7
- const date_holidays_1 = __importDefault(require("date-holidays"));
8
- const moment_1 = __importDefault(require("moment"));
9
- const index_1 = require("#/index");
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");
15
- const week_day_enum_1 = require("#/objects/datetime/points/week-day.enum");
16
- class DatetimeEdge {
17
- constructor(value) {
18
- this.value = value;
19
- let dateValue;
20
- if (index_1._.isUndefined(this.value)) {
21
- dateValue = new Date(Date.now());
22
- }
23
- else if (index_1._.isTypeOf(this.value, "string")) {
24
- const parsedDate = new Date(this.value);
25
- if (Number.isNaN(parsedDate.getTime())) {
26
- throw new Error(`Invalid date string: ${this.value}`);
27
- }
28
- dateValue = parsedDate;
29
- }
30
- else {
31
- dateValue = this.value;
32
- }
33
- this.date = (0, moment_1.default)(dateValue);
34
- this.validate();
35
- }
36
- /**
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"
40
- * @example
41
- * new DatetimeEdge(new Date("2026-03-29")).toFriendlyString() // "Sunday, Mar 29"
42
- * new DatetimeEdge(new Date()).toFriendlyString() // "Today, Apr 1"
43
- */
44
- toFriendlyString(language) {
45
- let dayOfWeekLabel = this.getDayOfWeek(language);
46
- const monthLabel = this.getNameOfMonth(language);
47
- if (this.isToday()) {
48
- dayOfWeekLabel = new today_to_language_mapper_1.TodayToLanguageMapper().toMap(language);
49
- }
50
- const dayOfMonth = this.getDayOfMonth();
51
- return `${dayOfWeekLabel}, ${monthLabel} ${dayOfMonth}`;
52
- }
53
- // ==================== Comparações ====================
54
- /**
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`.
58
- * @example
59
- * new DatetimeEdge(new Date("2026-12-01")).isAfter(new DatetimeEdge(new Date("2026-01-01"))) // true
60
- */
61
- isAfter(datetime) {
62
- return this.date.isAfter(datetime.toDate());
63
- }
64
- /**
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`.
68
- * @example
69
- * new DatetimeEdge(new Date("2026-01-01")).isBefore(new DatetimeEdge(new Date("2026-12-01"))) // true
70
- */
71
- isBefore(datetime) {
72
- return this.date.isBefore(datetime.toDate());
73
- }
74
- /**
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`.
78
- * @example
79
- * new DatetimeEdge(new Date("2026-01-01")).isEquals(new DatetimeEdge(new Date("2026-01-01"))) // true
80
- */
81
- isEquals(datetime) {
82
- return this.date.isSame(datetime.toDate());
83
- }
84
- /**
85
- * Verifica se esta data está entre duas outras datas (exclusivo).
86
- * @param initialDate - Data inicial do intervalo
87
- * @param finalDate - Data final do intervalo
88
- * @returns true se this está entre initialDate e finalDate, false caso contrário
89
- * @example
90
- * new DatetimeEdge(new Date("2026-06-15")).isBetween(
91
- * new DatetimeEdge(new Date("2026-01-01")),
92
- * new DatetimeEdge(new Date("2026-12-31"))
93
- * ) // true
94
- */
95
- isBetween(initialDate, finalDate) {
96
- return this.date.isBetween(initialDate.toDate(), finalDate.toDate());
97
- }
98
- // ==================== Verificações de Dia ====================
99
- /**
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`.
102
- * @example
103
- * new DatetimeEdge(new Date("2026-03-14")).isWeekend() // true (Saturday)
104
- * new DatetimeEdge(new Date("2026-03-12")).isWeekend() // false (Thursday)
105
- */
106
- isWeekend() {
107
- return [week_day_enum_1.WeekDayEnum.saturday, week_day_enum_1.WeekDayEnum.sunday].includes(this.getStandardDayOfWeek());
108
- }
109
- /**
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`.
113
- * @example
114
- * new DatetimeEdge(new Date("2026-12-25")).isHoliday("BR") // true (Christmas Day)
115
- * new DatetimeEdge(new Date("2026-03-12")).isHoliday("BR") // false
116
- */
117
- isHoliday(country) {
118
- const holidays = new date_holidays_1.default(country);
119
- return holidays.isHoliday(this.date.toDate()) !== false;
120
- }
121
- /**
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`.
125
- * @example
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)
128
- */
129
- isBusinessDay(country) {
130
- return !this.isWeekend() && !this.isHoliday(country);
131
- }
132
- /**
133
- * Checks whether the date corresponds to today.
134
- * @returns `true` if the date is today; otherwise, `false`.
135
- * @example
136
- * new DatetimeEdge(new Date()).isToday() // true
137
- * new DatetimeEdge(new Date("2020-01-01")).isToday() // false
138
- */
139
- isToday() {
140
- return this.date.isSame((0, moment_1.default)(), "day");
141
- }
142
- /**
143
- * Checks whether the date corresponds to yesterday.
144
- * @returns `true` if the date is yesterday; otherwise, `false`.
145
- * @example
146
- * new DatetimeEdge(new Date()).isYesterday() // false
147
- */
148
- isYesterday() {
149
- return this.date.isSame((0, moment_1.default)().subtract(1, "day"), "day");
150
- }
151
- /**
152
- * Checks whether the date corresponds to tomorrow.
153
- * @returns `true` if the date is tomorrow; otherwise, `false`.
154
- * @example
155
- * new DatetimeEdge(new Date()).isTomorrow() // false
156
- */
157
- isTomorrow() {
158
- return this.date.isSame((0, moment_1.default)().add(1, "day"), "day");
159
- }
160
- /**
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
164
- * @example
165
- * const a = new DatetimeEdge(new Date("2026-03-12T08:00"));
166
- * const b = new DatetimeEdge(new Date("2026-03-12T22:00"));
167
- * a.isSameDay(b) // true
168
- */
169
- isSameDay(datetime) {
170
- return this.date.isSame(datetime.toDate(), "day");
171
- }
172
- /**
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
176
- * @example
177
- * const a = new DatetimeEdge(new Date("2026-03-01"));
178
- * const b = new DatetimeEdge(new Date("2026-03-31"));
179
- * a.isSameMonth(b) // true
180
- */
181
- isSameMonth(datetime) {
182
- return this.date.isSame(datetime.toDate(), "month");
183
- }
184
- /**
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
188
- * @example
189
- * const a = new DatetimeEdge(new Date("2026-01-01"));
190
- * const b = new DatetimeEdge(new Date("2026-12-31"));
191
- * a.isSameYear(b) // true
192
- */
193
- isSameYear(datetime) {
194
- return this.date.isSame(datetime.toDate(), "year");
195
- }
196
- // ==================== Getters ====================
197
- /**
198
- * Returns the day of the week for the date.
199
- * @returns Enum WeekDayEnum representing the day of the week
200
- * @example
201
- * new DatetimeEdge(new Date("2026-03-12")).getDayOfWeek() // WeekDayEnum.thursday
202
- */
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() {
220
- const daysOfWeek = [
221
- week_day_enum_1.WeekDayEnum.sunday,
222
- week_day_enum_1.WeekDayEnum.monday,
223
- week_day_enum_1.WeekDayEnum.tuesday,
224
- week_day_enum_1.WeekDayEnum.wednesday,
225
- week_day_enum_1.WeekDayEnum.thursday,
226
- week_day_enum_1.WeekDayEnum.friday,
227
- week_day_enum_1.WeekDayEnum.saturday,
228
- ];
229
- return daysOfWeek[this.date.day()];
230
- }
231
- /**
232
- * Returns the name of the month for the date.
233
- * @returns Enum MonthNameEnum representing the month
234
- * @example
235
- * new DatetimeEdge(new Date("2026-03-12")).getNameOfMonth() // MonthNameEnum.march
236
- */
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;
243
- }
244
- /**
245
- * Returns the day of the month for the date.
246
- * @returns NNumber of the day (1-31)
247
- * @example
248
- * new DatetimeEdge(new Date("2026-03-12")).getDayOfMonth() // 12
249
- */
250
- getDayOfMonth() {
251
- return this.date.date();
252
- }
253
- /**
254
- * Returns the month number for the date (0-11).
255
- * @returns Month number (0=January, 11=December)
256
- * @example
257
- * new DatetimeEdge(new Date("2026-03-12")).getNumberOfMonth() // 2
258
- */
259
- getNumberOfMonth() {
260
- return this.date.month();
261
- }
262
- /**
263
- * Returns the year of the date.
264
- * @returns The year number.
265
- * @example
266
- * new DatetimeEdge(new Date("2026-03-12")).getYear() // 2026
267
- */
268
- getYear() {
269
- return this.date.year();
270
- }
271
- /**
272
- * Returns the hours of the date.
273
- * @returns The hour number (0-23)
274
- * @example
275
- * new DatetimeEdge(new Date("2026-03-12T14:30:00")).getHours() // 14
276
- */
277
- getHours() {
278
- return this.date.hours();
279
- }
280
- /**
281
- * Returns the minutes of the date.
282
- * @returns The minute number (0-59)
283
- * @example
284
- * new DatetimeEdge(new Date("2026-03-12T14:30:00")).getMinutes() // 30
285
- */
286
- getMinutes() {
287
- return this.date.minutes();
288
- }
289
- /**
290
- * Returns the seconds of the date.
291
- * @returns The second number (0-59)
292
- * @example
293
- * new DatetimeEdge(new Date("2026-03-12T14:30:45")).getSeconds() // 45
294
- */
295
- getSeconds() {
296
- return this.date.seconds();
297
- }
298
- // ==================== Operações Aritméticas ====================
299
- /**
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
303
- * @example
304
- * new DatetimeEdge(new Date("2026-03-12")).addDays(5) // DatetimeEdge("2026-03-17")
305
- */
306
- addDays(days) {
307
- return new DatetimeEdge(this.date.clone().add(days, "days").toDate());
308
- }
309
- /**
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
313
- * @example
314
- * new DatetimeEdge(new Date("2026-03-12")).subtractDays(5) // DatetimeEdge("2026-03-07")
315
- */
316
- subtractDays(days) {
317
- return new DatetimeEdge(this.date.clone().subtract(days, "days").toDate());
318
- }
319
- /**
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
323
- * @example
324
- * new DatetimeEdge(new Date("2026-03-12")).addMonths(2) // DatetimeEdge("2026-05-12")
325
- */
326
- addMonths(months) {
327
- return new DatetimeEdge(this.date.clone().add(months, "months").toDate());
328
- }
329
- /**
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
333
- * @example
334
- * new DatetimeEdge(new Date("2026-03-12")).subtractMonths(2) // DatetimeEdge("2026-01-12")
335
- */
336
- subtractMonths(months) {
337
- return new DatetimeEdge(this.date.clone().subtract(months, "months").toDate());
338
- }
339
- /**
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
343
- * @example
344
- * new DatetimeEdge(new Date("2026-03-12")).addYears(1) // DatetimeEdge("2027-03-12")
345
- */
346
- addYears(years) {
347
- return new DatetimeEdge(this.date.clone().add(years, "years").toDate());
348
- }
349
- /**
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
353
- * @example
354
- * new DatetimeEdge(new Date("2026-03-12")).subtractYears(1) // DatetimeEdge("2025-03-12")
355
- */
356
- subtractYears(years) {
357
- return new DatetimeEdge(this.date.clone().subtract(years, "years").toDate());
358
- }
359
- /**
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
363
- * @example
364
- * new DatetimeEdge(new Date("2026-03-12T08:00")).addHours(3) // DatetimeEdge("2026-03-12T11:00")
365
- */
366
- addHours(hours) {
367
- return new DatetimeEdge(this.date.clone().add(hours, "hours").toDate());
368
- }
369
- /**
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
373
- * @example
374
- * new DatetimeEdge(new Date("2026-03-12T08:00")).addMinutes(30) // DatetimeEdge("2026-03-12T08:30")
375
- */
376
- addMinutes(minutes) {
377
- return new DatetimeEdge(this.date.clone().add(minutes, "minutes").toDate());
378
- }
379
- /**
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)
383
- * @example
384
- * new DatetimeEdge(new Date("2026-03-15")).diffInDays(new DatetimeEdge(new Date("2026-03-10"))) // 5
385
- */
386
- diffInDays(datetime) {
387
- return this.date.diff(datetime.toDate(), "days");
388
- }
389
- /**
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)
393
- * @example
394
- * new DatetimeEdge(new Date("2026-05-12")).diffInMonths(new DatetimeEdge(new Date("2026-03-12"))) // 2
395
- */
396
- diffInMonths(datetime) {
397
- return this.date.diff(datetime.toDate(), "months");
398
- }
399
- /**
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`).
403
- * @example
404
- * new DatetimeEdge(new Date("2028-03-12")).diffInYears(new DatetimeEdge(new Date("2026-03-12"))) // 2
405
- */
406
- diffInYears(datetime) {
407
- return this.date.diff(datetime.toDate(), "years");
408
- }
409
- /**
410
- * Calcula a diferença em horas entre esta data e outra.
411
- * @param datetime - Data para calcular a diferença
412
- * @returns Número de horas de diferença (positivo se this > datetime)
413
- * @example
414
- * new DatetimeEdge(new Date("2026-03-12T14:00")).diffInHours(new DatetimeEdge(new Date("2026-03-12T08:00"))) // 6
415
- */
416
- diffInHours(datetime) {
417
- return this.date.diff(datetime.toDate(), "hours");
418
- }
419
- /**
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`).
423
- * @example
424
- * new DatetimeEdge(new Date("2026-03-12T08:45")).diffInMinutes(new DatetimeEdge(new Date("2026-03-12T08:00"))) // 45
425
- */
426
- diffInMinutes(datetime) {
427
- return this.date.diff(datetime.toDate(), "minutes");
428
- }
429
- /**
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.
432
- * @example
433
- * new DatetimeEdge(new Date("2025-03-12")).diffFromNow() // "1 year ago."
434
- */
435
- diffFromNow() {
436
- const now = (0, moment_1.default)();
437
- const diffInSeconds = now.diff(this.date, "seconds");
438
- const diffInMinutes = now.diff(this.date, "minutes");
439
- const diffInHours = now.diff(this.date, "hours");
440
- const diffInDays = now.diff(this.date, "days");
441
- const diffInMonths = now.diff(this.date, "months");
442
- const diffInYears = now.diff(this.date, "years");
443
- if (diffInSeconds < 60) {
444
- return `Há ${diffInSeconds} segundo${diffInSeconds === 1 ? "" : "s"}.`;
445
- }
446
- if (diffInMinutes < 60) {
447
- return `Há ${diffInMinutes} minuto${diffInMinutes === 1 ? "" : "s"}.`;
448
- }
449
- if (diffInHours < 24) {
450
- return `Há ${diffInHours} hora${diffInHours === 1 ? "" : "s"}.`;
451
- }
452
- if (diffInDays < 30) {
453
- return `Há ${diffInDays} dia${diffInDays === 1 ? "" : "s"}.`;
454
- }
455
- if (diffInMonths < 12) {
456
- return `Há ${diffInMonths} mês${diffInMonths === 1 ? "" : "es"}.`;
457
- }
458
- return `Há ${diffInYears} ano${diffInYears === 1 ? "" : "s"}.`;
459
- }
460
- // ==================== Início e Fim de Período ====================
461
- /**
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
464
- * @example
465
- * new DatetimeEdge(new Date("2026-03-12T14:30")).startOfDay()
466
- * // DatetimeEdge("2026-03-12T00:00:00.000")
467
- */
468
- startOfDay() {
469
- return new DatetimeEdge(this.date.clone().startOf("day").toDate());
470
- }
471
- /**
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
474
- * @example
475
- * new DatetimeEdge(new Date("2026-03-12T08:00")).endOfDay()
476
- * // DatetimeEdge("2026-03-12T23:59:59.999")
477
- */
478
- endOfDay() {
479
- return new DatetimeEdge(this.date.clone().endOf("day").toDate());
480
- }
481
- /**
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
484
- * @example
485
- * new DatetimeEdge(new Date("2026-03-12")).startOfMonth()
486
- * // DatetimeEdge("2026-03-01T00:00:00.000")
487
- */
488
- startOfMonth() {
489
- return new DatetimeEdge(this.date.clone().startOf("month").toDate());
490
- }
491
- /**
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
494
- * @example
495
- * new DatetimeEdge(new Date("2026-03-12")).endOfMonth()
496
- * // DatetimeEdge("2026-03-31T23:59:59.999")
497
- */
498
- endOfMonth() {
499
- return new DatetimeEdge(this.date.clone().endOf("month").toDate());
500
- }
501
- /**
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
504
- * @example
505
- * new DatetimeEdge(new Date("2026-03-12")).startOfYear()
506
- * // DatetimeEdge("2026-01-01T00:00:00.000")
507
- */
508
- startOfYear() {
509
- return new DatetimeEdge(this.date.clone().startOf("year").toDate());
510
- }
511
- /**
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
514
- * @example
515
- * new DatetimeEdge(new Date("2026-03-12")).endOfYear()
516
- * // DatetimeEdge("2026-12-31T23:59:59.999")
517
- */
518
- endOfYear() {
519
- return new DatetimeEdge(this.date.clone().endOf("year").toDate());
520
- }
521
- // ==================== Clonagem e Imutabilidade ====================
522
- /**
523
- * Creates an independent copy of this DatetimeEdge instance.
524
- * @returns A new instance with the same date value
525
- * @example
526
- * const dt1 = new DatetimeEdge(new Date("2026-03-12"));
527
- * const dt2 = dt1.clone(); // independent instance
528
- */
529
- clone() {
530
- return new DatetimeEdge(this.date.toDate());
531
- }
532
- /**
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
536
- * @example
537
- * new DatetimeEdge(new Date("2026-03-12")).withDate(new Date("2026-12-25"))
538
- * // DatetimeEdge("2026-12-25")
539
- */
540
- withDate(date) {
541
- return new DatetimeEdge(date);
542
- }
543
- // ==================== Formatação ====================
544
- /**
545
- * Returns the date in ISO 8601 format.
546
- * @returns String in the format "YYYY-MM-DDTHH:mm:ss.sssZ"
547
- * @example
548
- * new DatetimeEdge(new Date("2026-03-12")).toISOString() // "2026-03-12T00:00:00.000Z"
549
- */
550
- toISOString() {
551
- return this.date.toISOString();
552
- }
553
- /**
554
- * Returns the date as a native Date object.
555
- * @returns Date object representing this date
556
- * @example
557
- * new DatetimeEdge(new Date("2026-03-12")).toDate() // Date object
558
- */
559
- toDate() {
560
- return this.date.toDate();
561
- }
562
- /**
563
- * Returns the date in YYYY-MM-DD format.
564
- * @returns String in the format "YYYY-MM-DD"
565
- * @example
566
- * new DatetimeEdge(new Date("2026-03-12")).toYYYYMMDD() // "2026-03-12"
567
- */
568
- toYYYYMMDD() {
569
- return this.date.format("YYYY-MM-DD");
570
- }
571
- /**
572
- * Returns the date in DD/MM/YYYY format (Brazilian standard).
573
- * @returns String no formato "DD/MM/YYYY"
574
- * @example
575
- * new DatetimeEdge(new Date("2026-03-12")).toDDMMYYYY() // "12/03/2026"
576
- */
577
- toDDMMYYYY() {
578
- return this.date.format("DD/MM/YYYY");
579
- }
580
- /**
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".
583
- * @example
584
- * new DatetimeEdge(new Date("2026-03-12T14:30")).toDDMMYYYYHHmm() // "12/03/2026 14:30"
585
- */
586
- toDDMMYYYYHHmm() {
587
- return this.date.format("DD/MM/YYYY HH:mm");
588
- }
589
- /**
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
593
- * @example
594
- * new DatetimeEdge(new Date("2026-03-12T14:30")).format("MMMM Do YYYY") // "March 12th 2026"
595
- */
596
- format(format) {
597
- return this.date.format(format);
598
- }
599
- /**
600
- * Returns the timestamp in milliseconds of the date.
601
- * @returns NNumber of milliseconds since 01/01/1970 UTC
602
- * @example
603
- * new DatetimeEdge(new Date("2026-03-12")).timestamp() // 1773273600000
604
- */
605
- timestamp() {
606
- return this.date.valueOf();
607
- }
608
- /**
609
- * Returns the Unix timestamp in seconds of the date.
610
- * @returns NNumber of seconds since 01/01/1970 UTC
611
- * @example
612
- * new DatetimeEdge(new Date("2026-03-12")).unix() // 1773273600
613
- */
614
- unix() {
615
- return this.date.unix();
616
- }
617
- // ==================== Métodos Estáticos ====================
618
- /**
619
- * Creates a new DatetimeEdge representing the current moment.
620
- * @returns New instance with the current date and time
621
- * @example
622
- * DatetimeEdge.now() // DatetimeEdge with the current date and time
623
- */
624
- static now() {
625
- return new DatetimeEdge(new Date());
626
- }
627
- /**
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
632
- * @example
633
- * DatetimeEdge.max([
634
- * new DatetimeEdge(new Date("2026-01-01")),
635
- * new DatetimeEdge(new Date("2026-06-15")),
636
- * ]) // DatetimeEdge("2026-06-15")
637
- */
638
- static max(dates) {
639
- if (dates.length === 0) {
640
- throw new Error("Cannot find max of an empty array of dates.");
641
- }
642
- return dates.reduce((max, date) => (date.isAfter(max) ? date : max));
643
- }
644
- /**
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
649
- * @example
650
- * DatetimeEdge.min([
651
- * new DatetimeEdge(new Date("2026-01-01")),
652
- * new DatetimeEdge(new Date("2026-06-15")),
653
- * ]) // DatetimeEdge("2026-01-01")
654
- */
655
- static min(dates) {
656
- if (dates.length === 0) {
657
- throw new Error("Cannot find min of an empty array of dates.");
658
- }
659
- return dates.reduce((min, date) => (date.isBefore(min) ? date : min));
660
- }
661
- // ==================== Privados ====================
662
- /**
663
- * Validates whether the date provided to the constructor is a valid date.
664
- * @throws {Error} If the date is invalid.
665
- */
666
- validate() {
667
- if (!(0, moment_1.default)(this.date).isValid()) {
668
- throw new Error(`${this.constructor.name} should be valid.`);
669
- }
670
- }
671
- }
672
- exports.DatetimeEdge = DatetimeEdge;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DayNameToEnglishMapper = void 0;
4
- const map_abstract_1 = require("#/@tool-box/utils/map/map.abstract");
5
- class DayNameToEnglishMapper extends map_abstract_1.MapAbstract {
6
- constructor() {
7
- super(...arguments);
8
- this.map = new Map([
9
- [0, "Sunday"],
10
- [1, "Monday"],
11
- [2, "Tuesday"],
12
- [3, "Wednesday"],
13
- [4, "Thursday"],
14
- [5, "Friday"],
15
- [6, "Saturday"],
16
- ]);
17
- }
18
- }
19
- exports.DayNameToEnglishMapper = DayNameToEnglishMapper;