@atlantjs/arch 13.3.0 → 14.0.1

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 (50) hide show
  1. package/@tool-box/utils/datatypes/boolean-utils.d.ts +7 -0
  2. package/@tool-box/utils/datatypes/boolean-utils.js +146 -4
  3. package/@tool-box/utils/datatypes/string-utils.d.ts +32 -4
  4. package/@tool-box/utils/datatypes/string-utils.js +303 -14
  5. package/@tool-box/utils/ducts/common.d.ts +49 -0
  6. package/@tool-box/utils/ducts/common.js +36 -3
  7. package/@tool-box/utils/ducts/optional-type.d.ts +85 -0
  8. package/@tool-box/utils/ducts/optional-type.js +79 -0
  9. package/@tool-box/utils/ducts/return-type.d.ts +17 -17
  10. package/@tool-box/utils/ducts/return-type.js +14 -4
  11. package/@tool-box/utils/http-provider/http-provider.d.ts +6 -0
  12. package/@tool-box/utils/http-provider/http-provider.js +43 -14
  13. package/@tool-box/utils/map/map.abstract.d.ts +39 -0
  14. package/@tool-box/utils/map/map.abstract.js +70 -6
  15. package/@tool-box/utils/random/random.d.ts +168 -0
  16. package/@tool-box/utils/random/random.js +235 -0
  17. package/@tool-box/utils/type-guard/guardian.d.ts +450 -7
  18. package/@tool-box/utils/type-guard/guardian.js +539 -35
  19. package/objects/@common/edges/cron-expression.edge.d.ts +30 -2
  20. package/objects/@common/edges/cron-expression.edge.js +77 -5
  21. package/objects/@common/edges/email.edge.d.ts +39 -1
  22. package/objects/@common/edges/email.edge.js +80 -2
  23. package/objects/@common/edges/ulid.sketch.edge.d.ts +48 -1
  24. package/objects/@common/edges/ulid.sketch.edge.js +75 -4
  25. package/objects/@common/edges/url.edge.d.ts +182 -0
  26. package/objects/@common/edges/url.edge.js +249 -0
  27. package/objects/@common/edges/username.edge.d.ts +9 -0
  28. package/objects/@common/edges/username.edge.js +34 -0
  29. package/objects/@common/edges/uuid.sketch.edge.d.ts +97 -1
  30. package/objects/@common/edges/uuid.sketch.edge.js +127 -6
  31. package/objects/amount/amount-value.edge.d.ts +39 -0
  32. package/objects/amount/amount-value.edge.js +69 -0
  33. package/objects/amount/amount.edge.d.ts +378 -2
  34. package/objects/amount/amount.edge.js +493 -4
  35. package/objects/datetime/edges/datetime.edge.d.ts +422 -4
  36. package/objects/datetime/edges/datetime.edge.js +538 -33
  37. package/objects/password/password.edge.d.ts +90 -0
  38. package/objects/password/password.edge.js +140 -6
  39. package/objects/primitives/boolean.edge.sketch.d.ts +105 -3
  40. package/objects/primitives/boolean.edge.sketch.js +132 -6
  41. package/objects/primitives/number.edge.sketch.d.ts +236 -0
  42. package/objects/primitives/number.edge.sketch.js +310 -24
  43. package/objects/primitives/string.edge.sketch.d.ts +148 -0
  44. package/objects/primitives/string.edge.sketch.js +191 -7
  45. package/objects/schedule/schedule.edge.d.ts +194 -0
  46. package/objects/schedule/schedule.edge.js +269 -2
  47. package/objects/time/time.edge.d.ts +285 -2
  48. package/objects/time/time.edge.js +385 -6
  49. package/package.json +1 -1
  50. package/tsconfig.tsbuildinfo +1 -1
@@ -29,53 +29,154 @@ class DatetimeEdge {
29
29
  this.date = (0, moment_1.default)(dateValue);
30
30
  this.validate();
31
31
  }
32
+ // ==================== Comparações ====================
33
+ /**
34
+ * Verifica se esta data é posterior a outra.
35
+ * @param other - Data para comparação
36
+ * @returns true se this > other, false caso contrário
37
+ * @example
38
+ * new DatetimeEdge(new Date("2026-12-01")).isAfter(new DatetimeEdge(new Date("2026-01-01"))) // true
39
+ */
32
40
  isAfter(other) {
33
41
  return this.date.isAfter(other.toDate());
34
42
  }
35
- diffFromNow() {
36
- const now = (0, moment_1.default)();
37
- const diffInSeconds = now.diff(this.date, "seconds");
38
- const diffInMinutes = now.diff(this.date, "minutes");
39
- const diffInHours = now.diff(this.date, "hours");
40
- const diffInDays = now.diff(this.date, "days");
41
- const diffInMonths = now.diff(this.date, "months");
42
- const diffInYears = now.diff(this.date, "years");
43
- if (diffInSeconds < 60) {
44
- return `Há ${diffInSeconds} segundo${diffInSeconds === 1 ? "" : "s"}.`;
45
- }
46
- if (diffInMinutes < 60) {
47
- return `Há ${diffInMinutes} minuto${diffInMinutes === 1 ? "" : "s"}.`;
48
- }
49
- if (diffInHours < 24) {
50
- return `Há ${diffInHours} hora${diffInHours === 1 ? "" : "s"}.`;
51
- }
52
- if (diffInDays < 30) {
53
- return `Há ${diffInDays} dia${diffInDays === 1 ? "" : "s"}.`;
54
- }
55
- if (diffInMonths < 12) {
56
- return `Há ${diffInMonths} mês${diffInMonths === 1 ? "" : "es"}.`;
57
- }
58
- return `Há ${diffInYears} ano${diffInYears === 1 ? "" : "s"}.`;
43
+ /**
44
+ * Verifica se esta data é anterior a outra.
45
+ * @param other - Data para comparação
46
+ * @returns true se this < other, false caso contrário
47
+ * @example
48
+ * new DatetimeEdge(new Date("2026-01-01")).isBefore(new DatetimeEdge(new Date("2026-12-01"))) // true
49
+ */
50
+ isBefore(other) {
51
+ return this.date.isBefore(other.toDate());
59
52
  }
53
+ /**
54
+ * Verifica se esta data é igual a outra.
55
+ * @param other - Data para comparação
56
+ * @returns true se as datas são iguais, false caso contrário
57
+ * @example
58
+ * new DatetimeEdge(new Date("2026-01-01")).isEquals(new DatetimeEdge(new Date("2026-01-01"))) // true
59
+ */
60
60
  isEquals(other) {
61
61
  return this.date.isSame(other.toDate());
62
62
  }
63
- isBefore(other) {
64
- return this.date.isBefore(other.toDate());
65
- }
63
+ /**
64
+ * Verifica se esta data está entre duas outras datas (exclusivo).
65
+ * @param initialDate - Data inicial do intervalo
66
+ * @param finalDate - Data final do intervalo
67
+ * @returns true se this está entre initialDate e finalDate, false caso contrário
68
+ * @example
69
+ * new DatetimeEdge(new Date("2026-06-15")).isBetween(
70
+ * new DatetimeEdge(new Date("2026-01-01")),
71
+ * new DatetimeEdge(new Date("2026-12-31"))
72
+ * ) // true
73
+ */
66
74
  isBetween(initialDate, finalDate) {
67
75
  return this.date.isBetween(initialDate.toDate(), finalDate.toDate());
68
76
  }
77
+ // ==================== Verificações de Dia ====================
78
+ /**
79
+ * Verifica se a data cai em um fim de semana (sábado ou domingo).
80
+ * @returns true se a data é sábado ou domingo, false caso contrário
81
+ * @example
82
+ * new DatetimeEdge(new Date("2026-03-14")).isWeekend() // true (sábado)
83
+ * new DatetimeEdge(new Date("2026-03-12")).isWeekend() // false (quinta-feira)
84
+ */
69
85
  isWeekend() {
70
- return [week_day_enum_1.WeekDayEnum.sunday, week_day_enum_1.WeekDayEnum.monday].includes(this.getDayOfWeek());
86
+ return [week_day_enum_1.WeekDayEnum.saturday, week_day_enum_1.WeekDayEnum.sunday].includes(this.getDayOfWeek());
71
87
  }
88
+ /**
89
+ * Verifica se a data é um feriado no Brasil.
90
+ * @returns true se a data é um feriado nacional, false caso contrário
91
+ * @example
92
+ * new DatetimeEdge(new Date("2026-12-25")).isHoliday() // true (Natal)
93
+ * new DatetimeEdge(new Date("2026-03-12")).isHoliday() // false
94
+ */
72
95
  isHoliday() {
73
96
  const holidays = new date_holidays_1.default("BR");
74
97
  return holidays.isHoliday(this.date.toDate()) !== false;
75
98
  }
99
+ /**
100
+ * Verifica se a data é um dia útil (não é fim de semana nem feriado).
101
+ * @returns true se a data é um dia útil, false caso contrário
102
+ * @example
103
+ * new DatetimeEdge(new Date("2026-03-12")).isBusinessDay() // true (quinta-feira)
104
+ * new DatetimeEdge(new Date("2026-12-25")).isBusinessDay() // false (Natal)
105
+ */
76
106
  isBusinessDay() {
77
107
  return !this.isWeekend() && !this.isHoliday();
78
108
  }
109
+ /**
110
+ * Verifica se a data corresponde ao dia de hoje.
111
+ * @returns true se a data é hoje, false caso contrário
112
+ * @example
113
+ * new DatetimeEdge(new Date()).isToday() // true
114
+ * new DatetimeEdge(new Date("2020-01-01")).isToday() // false
115
+ */
116
+ isToday() {
117
+ return this.date.isSame((0, moment_1.default)(), "day");
118
+ }
119
+ /**
120
+ * Verifica se a data corresponde a ontem.
121
+ * @returns true se a data é ontem, false caso contrário
122
+ * @example
123
+ * new DatetimeEdge(new Date()).isYesterday() // false
124
+ */
125
+ isYesterday() {
126
+ return this.date.isSame((0, moment_1.default)().subtract(1, "day"), "day");
127
+ }
128
+ /**
129
+ * Verifica se a data corresponde a amanhã.
130
+ * @returns true se a data é amanhã, false caso contrário
131
+ * @example
132
+ * new DatetimeEdge(new Date()).isTomorrow() // false
133
+ */
134
+ isTomorrow() {
135
+ return this.date.isSame((0, moment_1.default)().add(1, "day"), "day");
136
+ }
137
+ /**
138
+ * Verifica se a data está no mesmo dia que outra.
139
+ * @param other - Data para comparação
140
+ * @returns true se ambas as datas estão no mesmo dia, false caso contrário
141
+ * @example
142
+ * const a = new DatetimeEdge(new Date("2026-03-12T08:00"));
143
+ * const b = new DatetimeEdge(new Date("2026-03-12T22:00"));
144
+ * a.isSameDay(b) // true
145
+ */
146
+ isSameDay(other) {
147
+ return this.date.isSame(other.toDate(), "day");
148
+ }
149
+ /**
150
+ * Verifica se a data está no mesmo mês que outra.
151
+ * @param other - Data para comparação
152
+ * @returns true se ambas as datas estão no mesmo mês e ano, false caso contrário
153
+ * @example
154
+ * const a = new DatetimeEdge(new Date("2026-03-01"));
155
+ * const b = new DatetimeEdge(new Date("2026-03-31"));
156
+ * a.isSameMonth(b) // true
157
+ */
158
+ isSameMonth(other) {
159
+ return this.date.isSame(other.toDate(), "month");
160
+ }
161
+ /**
162
+ * Verifica se a data está no mesmo ano que outra.
163
+ * @param other - Data para comparação
164
+ * @returns true se ambas as datas estão no mesmo ano, false caso contrário
165
+ * @example
166
+ * const a = new DatetimeEdge(new Date("2026-01-01"));
167
+ * const b = new DatetimeEdge(new Date("2026-12-31"));
168
+ * a.isSameYear(b) // true
169
+ */
170
+ isSameYear(other) {
171
+ return this.date.isSame(other.toDate(), "year");
172
+ }
173
+ // ==================== Getters ====================
174
+ /**
175
+ * Retorna o dia da semana da data.
176
+ * @returns Enum WeekDayEnum representando o dia da semana
177
+ * @example
178
+ * new DatetimeEdge(new Date("2026-03-12")).getDayOfWeek() // WeekDayEnum.thursday
179
+ */
79
180
  getDayOfWeek() {
80
181
  const daysOfWeek = [
81
182
  week_day_enum_1.WeekDayEnum.sunday,
@@ -86,8 +187,14 @@ class DatetimeEdge {
86
187
  week_day_enum_1.WeekDayEnum.friday,
87
188
  week_day_enum_1.WeekDayEnum.saturday,
88
189
  ];
89
- return daysOfWeek[this.date.days()];
190
+ return daysOfWeek[this.date.day()];
90
191
  }
192
+ /**
193
+ * Retorna o nome do mês da data.
194
+ * @returns Enum MonthNameEnum representando o mês
195
+ * @example
196
+ * new DatetimeEdge(new Date("2026-03-12")).getNameOfMonth() // MonthNameEnum.march
197
+ */
91
198
  getNameOfMonth() {
92
199
  const months = [
93
200
  month_name_enum_1.MonthNameEnum.january,
@@ -105,30 +212,428 @@ class DatetimeEdge {
105
212
  ];
106
213
  return months[this.date.month()];
107
214
  }
215
+ /**
216
+ * Retorna o número do dia no mês.
217
+ * @returns Número do dia (1-31)
218
+ * @example
219
+ * new DatetimeEdge(new Date("2026-03-12")).getDayOfMonth() // 12
220
+ */
108
221
  getDayOfMonth() {
109
222
  return this.date.date();
110
223
  }
224
+ /**
225
+ * Retorna o número do mês (base 0).
226
+ * @returns Número do mês (0=janeiro, 11=dezembro)
227
+ * @example
228
+ * new DatetimeEdge(new Date("2026-03-12")).getNumberOfMonth() // 2
229
+ */
111
230
  getNumberOfMonth() {
112
231
  return this.date.month();
113
232
  }
233
+ /**
234
+ * Retorna o ano da data.
235
+ * @returns Número do ano
236
+ * @example
237
+ * new DatetimeEdge(new Date("2026-03-12")).getYear() // 2026
238
+ */
114
239
  getYear() {
115
240
  return this.date.year();
116
241
  }
242
+ /**
243
+ * Retorna as horas da data.
244
+ * @returns Número da hora (0-23)
245
+ * @example
246
+ * new DatetimeEdge(new Date("2026-03-12T14:30:00")).getHours() // 14
247
+ */
248
+ getHours() {
249
+ return this.date.hours();
250
+ }
251
+ /**
252
+ * Retorna os minutos da data.
253
+ * @returns Número dos minutos (0-59)
254
+ * @example
255
+ * new DatetimeEdge(new Date("2026-03-12T14:30:00")).getMinutes() // 30
256
+ */
257
+ getMinutes() {
258
+ return this.date.minutes();
259
+ }
260
+ /**
261
+ * Retorna os segundos da data.
262
+ * @returns Número dos segundos (0-59)
263
+ * @example
264
+ * new DatetimeEdge(new Date("2026-03-12T14:30:45")).getSeconds() // 45
265
+ */
266
+ getSeconds() {
267
+ return this.date.seconds();
268
+ }
269
+ // ==================== Operações Aritméticas ====================
270
+ /**
271
+ * Adiciona dias à data e retorna uma nova instância.
272
+ * @param days - Número de dias a adicionar
273
+ * @returns Nova instância com a data atualizada
274
+ * @example
275
+ * new DatetimeEdge(new Date("2026-03-12")).addDays(5) // DatetimeEdge("2026-03-17")
276
+ */
277
+ addDays(days) {
278
+ return new DatetimeEdge(this.date.clone().add(days, "days").toDate());
279
+ }
280
+ /**
281
+ * Subtrai dias da data e retorna uma nova instância.
282
+ * @param days - Número de dias a subtrair
283
+ * @returns Nova instância com a data atualizada
284
+ * @example
285
+ * new DatetimeEdge(new Date("2026-03-12")).subtractDays(5) // DatetimeEdge("2026-03-07")
286
+ */
287
+ subtractDays(days) {
288
+ return new DatetimeEdge(this.date.clone().subtract(days, "days").toDate());
289
+ }
290
+ /**
291
+ * Adiciona meses à data e retorna uma nova instância.
292
+ * @param months - Número de meses a adicionar
293
+ * @returns Nova instância com a data atualizada
294
+ * @example
295
+ * new DatetimeEdge(new Date("2026-03-12")).addMonths(2) // DatetimeEdge("2026-05-12")
296
+ */
297
+ addMonths(months) {
298
+ return new DatetimeEdge(this.date.clone().add(months, "months").toDate());
299
+ }
300
+ /**
301
+ * Subtrai meses da data e retorna uma nova instância.
302
+ * @param months - Número de meses a subtrair
303
+ * @returns Nova instância com a data atualizada
304
+ * @example
305
+ * new DatetimeEdge(new Date("2026-03-12")).subtractMonths(2) // DatetimeEdge("2026-01-12")
306
+ */
307
+ subtractMonths(months) {
308
+ return new DatetimeEdge(this.date.clone().subtract(months, "months").toDate());
309
+ }
310
+ /**
311
+ * Adiciona anos à data e retorna uma nova instância.
312
+ * @param years - Número de anos a adicionar
313
+ * @returns Nova instância com a data atualizada
314
+ * @example
315
+ * new DatetimeEdge(new Date("2026-03-12")).addYears(1) // DatetimeEdge("2027-03-12")
316
+ */
317
+ addYears(years) {
318
+ return new DatetimeEdge(this.date.clone().add(years, "years").toDate());
319
+ }
320
+ /**
321
+ * Subtrai anos da data e retorna uma nova instância.
322
+ * @param years - Número de anos a subtrair
323
+ * @returns Nova instância com a data atualizada
324
+ * @example
325
+ * new DatetimeEdge(new Date("2026-03-12")).subtractYears(1) // DatetimeEdge("2025-03-12")
326
+ */
327
+ subtractYears(years) {
328
+ return new DatetimeEdge(this.date.clone().subtract(years, "years").toDate());
329
+ }
330
+ /**
331
+ * Adiciona horas à data e retorna uma nova instância.
332
+ * @param hours - Número de horas a adicionar
333
+ * @returns Nova instância com a data atualizada
334
+ * @example
335
+ * new DatetimeEdge(new Date("2026-03-12T08:00")).addHours(3) // DatetimeEdge("2026-03-12T11:00")
336
+ */
337
+ addHours(hours) {
338
+ return new DatetimeEdge(this.date.clone().add(hours, "hours").toDate());
339
+ }
340
+ /**
341
+ * Adiciona minutos à data e retorna uma nova instância.
342
+ * @param minutes - Número de minutos a adicionar
343
+ * @returns Nova instância com a data atualizada
344
+ * @example
345
+ * new DatetimeEdge(new Date("2026-03-12T08:00")).addMinutes(30) // DatetimeEdge("2026-03-12T08:30")
346
+ */
347
+ addMinutes(minutes) {
348
+ return new DatetimeEdge(this.date.clone().add(minutes, "minutes").toDate());
349
+ }
350
+ /**
351
+ * Calcula a diferença em dias entre esta data e outra.
352
+ * @param other - Data para calcular a diferença
353
+ * @returns Número de dias de diferença (positivo se this > other)
354
+ * @example
355
+ * new DatetimeEdge(new Date("2026-03-15")).diffInDays(new DatetimeEdge(new Date("2026-03-10"))) // 5
356
+ */
357
+ diffInDays(other) {
358
+ return this.date.diff(other.toDate(), "days");
359
+ }
360
+ /**
361
+ * Calcula a diferença em meses entre esta data e outra.
362
+ * @param other - Data para calcular a diferença
363
+ * @returns Número de meses de diferença (positivo se this > other)
364
+ * @example
365
+ * new DatetimeEdge(new Date("2026-05-12")).diffInMonths(new DatetimeEdge(new Date("2026-03-12"))) // 2
366
+ */
367
+ diffInMonths(other) {
368
+ return this.date.diff(other.toDate(), "months");
369
+ }
370
+ /**
371
+ * Calcula a diferença em anos entre esta data e outra.
372
+ * @param other - Data para calcular a diferença
373
+ * @returns Número de anos de diferença (positivo se this > other)
374
+ * @example
375
+ * new DatetimeEdge(new Date("2028-03-12")).diffInYears(new DatetimeEdge(new Date("2026-03-12"))) // 2
376
+ */
377
+ diffInYears(other) {
378
+ return this.date.diff(other.toDate(), "years");
379
+ }
380
+ /**
381
+ * Calcula a diferença em horas entre esta data e outra.
382
+ * @param other - Data para calcular a diferença
383
+ * @returns Número de horas de diferença (positivo se this > other)
384
+ * @example
385
+ * new DatetimeEdge(new Date("2026-03-12T14:00")).diffInHours(new DatetimeEdge(new Date("2026-03-12T08:00"))) // 6
386
+ */
387
+ diffInHours(other) {
388
+ return this.date.diff(other.toDate(), "hours");
389
+ }
390
+ /**
391
+ * Calcula a diferença em minutos entre esta data e outra.
392
+ * @param other - Data para calcular a diferença
393
+ * @returns Número de minutos de diferença (positivo se this > other)
394
+ * @example
395
+ * new DatetimeEdge(new Date("2026-03-12T08:45")).diffInMinutes(new DatetimeEdge(new Date("2026-03-12T08:00"))) // 45
396
+ */
397
+ diffInMinutes(other) {
398
+ return this.date.diff(other.toDate(), "minutes");
399
+ }
400
+ /**
401
+ * Retorna a diferença legível entre esta data e o momento atual.
402
+ * @returns String descritiva como "Há 3 dias.", "Há 2 horas.", etc.
403
+ * @example
404
+ * new DatetimeEdge(new Date("2025-03-12")).diffFromNow() // "Há 1 ano."
405
+ */
406
+ diffFromNow() {
407
+ const now = (0, moment_1.default)();
408
+ const diffInSeconds = now.diff(this.date, "seconds");
409
+ const diffInMinutes = now.diff(this.date, "minutes");
410
+ const diffInHours = now.diff(this.date, "hours");
411
+ const diffInDays = now.diff(this.date, "days");
412
+ const diffInMonths = now.diff(this.date, "months");
413
+ const diffInYears = now.diff(this.date, "years");
414
+ if (diffInSeconds < 60) {
415
+ return `Há ${diffInSeconds} segundo${diffInSeconds === 1 ? "" : "s"}.`;
416
+ }
417
+ if (diffInMinutes < 60) {
418
+ return `Há ${diffInMinutes} minuto${diffInMinutes === 1 ? "" : "s"}.`;
419
+ }
420
+ if (diffInHours < 24) {
421
+ return `Há ${diffInHours} hora${diffInHours === 1 ? "" : "s"}.`;
422
+ }
423
+ if (diffInDays < 30) {
424
+ return `Há ${diffInDays} dia${diffInDays === 1 ? "" : "s"}.`;
425
+ }
426
+ if (diffInMonths < 12) {
427
+ return `Há ${diffInMonths} mês${diffInMonths === 1 ? "" : "es"}.`;
428
+ }
429
+ return `Há ${diffInYears} ano${diffInYears === 1 ? "" : "s"}.`;
430
+ }
431
+ // ==================== Início e Fim de Período ====================
432
+ /**
433
+ * Retorna o início do dia (00:00:00.000) como nova instância.
434
+ * @returns Nova instância com o horário zerado para o início do dia
435
+ * @example
436
+ * new DatetimeEdge(new Date("2026-03-12T14:30")).startOfDay()
437
+ * // DatetimeEdge("2026-03-12T00:00:00.000")
438
+ */
439
+ startOfDay() {
440
+ return new DatetimeEdge(this.date.clone().startOf("day").toDate());
441
+ }
442
+ /**
443
+ * Retorna o fim do dia (23:59:59.999) como nova instância.
444
+ * @returns Nova instância com o horário ajustado para o fim do dia
445
+ * @example
446
+ * new DatetimeEdge(new Date("2026-03-12T08:00")).endOfDay()
447
+ * // DatetimeEdge("2026-03-12T23:59:59.999")
448
+ */
449
+ endOfDay() {
450
+ return new DatetimeEdge(this.date.clone().endOf("day").toDate());
451
+ }
452
+ /**
453
+ * Retorna o início do mês como nova instância.
454
+ * @returns Nova instância apontando para o primeiro dia do mês à meia-noite
455
+ * @example
456
+ * new DatetimeEdge(new Date("2026-03-12")).startOfMonth()
457
+ * // DatetimeEdge("2026-03-01T00:00:00.000")
458
+ */
459
+ startOfMonth() {
460
+ return new DatetimeEdge(this.date.clone().startOf("month").toDate());
461
+ }
462
+ /**
463
+ * Retorna o fim do mês como nova instância.
464
+ * @returns Nova instância apontando para o último dia do mês ao fim do dia
465
+ * @example
466
+ * new DatetimeEdge(new Date("2026-03-12")).endOfMonth()
467
+ * // DatetimeEdge("2026-03-31T23:59:59.999")
468
+ */
469
+ endOfMonth() {
470
+ return new DatetimeEdge(this.date.clone().endOf("month").toDate());
471
+ }
472
+ /**
473
+ * Retorna o início do ano como nova instância.
474
+ * @returns Nova instância apontando para o primeiro dia do ano à meia-noite
475
+ * @example
476
+ * new DatetimeEdge(new Date("2026-03-12")).startOfYear()
477
+ * // DatetimeEdge("2026-01-01T00:00:00.000")
478
+ */
479
+ startOfYear() {
480
+ return new DatetimeEdge(this.date.clone().startOf("year").toDate());
481
+ }
482
+ /**
483
+ * Retorna o fim do ano como nova instância.
484
+ * @returns Nova instância apontando para o último dia do ano ao fim do dia
485
+ * @example
486
+ * new DatetimeEdge(new Date("2026-03-12")).endOfYear()
487
+ * // DatetimeEdge("2026-12-31T23:59:59.999")
488
+ */
489
+ endOfYear() {
490
+ return new DatetimeEdge(this.date.clone().endOf("year").toDate());
491
+ }
492
+ // ==================== Clonagem e Imutabilidade ====================
493
+ /**
494
+ * Cria uma cópia independente desta instância de DatetimeEdge.
495
+ * @returns Nova instância com o mesmo valor de data
496
+ * @example
497
+ * const dt1 = new DatetimeEdge(new Date("2026-03-12"));
498
+ * const dt2 = dt1.clone(); // instância independente
499
+ */
500
+ clone() {
501
+ return new DatetimeEdge(this.date.toDate());
502
+ }
503
+ /**
504
+ * Retorna uma nova instância com a data alterada, mantendo o horário.
505
+ * @param date - Novo objeto Date
506
+ * @returns Nova instância com o valor fornecido
507
+ * @example
508
+ * new DatetimeEdge(new Date("2026-03-12")).withDate(new Date("2026-12-25"))
509
+ * // DatetimeEdge("2026-12-25")
510
+ */
511
+ withDate(date) {
512
+ return new DatetimeEdge(date);
513
+ }
514
+ // ==================== Formatação ====================
515
+ /**
516
+ * Retorna a data no formato ISO 8601.
517
+ * @returns String no formato "YYYY-MM-DDTHH:mm:ss.sssZ"
518
+ * @example
519
+ * new DatetimeEdge(new Date("2026-03-12")).toISOString() // "2026-03-12T00:00:00.000Z"
520
+ */
117
521
  toISOString() {
118
522
  return this.date.toISOString();
119
523
  }
524
+ /**
525
+ * Retorna a data como objeto Date nativo.
526
+ * @returns Objeto Date representando esta data
527
+ * @example
528
+ * new DatetimeEdge(new Date("2026-03-12")).toDate() // Date object
529
+ */
530
+ toDate() {
531
+ return this.date.toDate();
532
+ }
533
+ /**
534
+ * Retorna a data no formato YYYY-MM-DD.
535
+ * @returns String no formato "YYYY-MM-DD"
536
+ * @example
537
+ * new DatetimeEdge(new Date("2026-03-12")).toYYYYMMDD() // "2026-03-12"
538
+ */
539
+ toYYYYMMDD() {
540
+ return this.date.format("YYYY-MM-DD");
541
+ }
542
+ /**
543
+ * Retorna a data no formato DD/MM/YYYY (padrão brasileiro).
544
+ * @returns String no formato "DD/MM/YYYY"
545
+ * @example
546
+ * new DatetimeEdge(new Date("2026-03-12")).toDDMMYYYY() // "12/03/2026"
547
+ */
548
+ toDDMMYYYY() {
549
+ return this.date.format("DD/MM/YYYY");
550
+ }
551
+ /**
552
+ * Retorna a data e hora no formato DD/MM/YYYY HH:mm.
553
+ * @returns String no formato "DD/MM/YYYY HH:mm"
554
+ * @example
555
+ * new DatetimeEdge(new Date("2026-03-12T14:30")).toDDMMYYYYHHmm() // "12/03/2026 14:30"
556
+ */
557
+ toDDMMYYYYHHmm() {
558
+ return this.date.format("DD/MM/YYYY HH:mm");
559
+ }
560
+ /**
561
+ * Retorna a data formatada com um padrão customizado do moment.js.
562
+ * @param format - Padrão de formatação (ex: "YYYY-MM-DD HH:mm:ss")
563
+ * @returns String formatada conforme o padrão fornecido
564
+ * @example
565
+ * new DatetimeEdge(new Date("2026-03-12T14:30")).format("MMMM Do YYYY") // "March 12th 2026"
566
+ */
567
+ format(format) {
568
+ return this.date.format(format);
569
+ }
570
+ /**
571
+ * Retorna o timestamp em milissegundos da data.
572
+ * @returns Número de milissegundos desde 01/01/1970 UTC
573
+ * @example
574
+ * new DatetimeEdge(new Date("2026-03-12")).timestamp() // 1773273600000
575
+ */
120
576
  timestamp() {
121
577
  return this.date.valueOf();
122
578
  }
579
+ /**
580
+ * Retorna o timestamp Unix em segundos da data.
581
+ * @returns Número de segundos desde 01/01/1970 UTC
582
+ * @example
583
+ * new DatetimeEdge(new Date("2026-03-12")).unix() // 1773273600
584
+ */
123
585
  unix() {
124
586
  return this.date.unix();
125
587
  }
126
- toDate() {
127
- return this.date.toDate();
588
+ // ==================== Métodos Estáticos ====================
589
+ /**
590
+ * Cria um DatetimeEdge representando o momento atual.
591
+ * @returns Nova instância com a data e hora atuais
592
+ * @example
593
+ * DatetimeEdge.now() // DatetimeEdge com a data e hora do momento da chamada
594
+ */
595
+ static now() {
596
+ return new DatetimeEdge(new Date());
128
597
  }
129
- toYYYYMMDD() {
130
- return this.date.format("YYYY-MM-DD");
598
+ /**
599
+ * Retorna a maior (mais recente) data de uma lista.
600
+ * @param dates - Array de instâncias de DatetimeEdge para comparação
601
+ * @returns A instância com a data mais recente
602
+ * @throws {Error} Se o array estiver vazio
603
+ * @example
604
+ * DatetimeEdge.max([
605
+ * new DatetimeEdge(new Date("2026-01-01")),
606
+ * new DatetimeEdge(new Date("2026-06-15")),
607
+ * ]) // DatetimeEdge("2026-06-15")
608
+ */
609
+ static max(dates) {
610
+ if (dates.length === 0) {
611
+ throw new Error("Cannot find max of an empty array of dates.");
612
+ }
613
+ return dates.reduce((max, date) => (date.isAfter(max) ? date : max));
614
+ }
615
+ /**
616
+ * Retorna a menor (mais antiga) data de uma lista.
617
+ * @param dates - Array de instâncias de DatetimeEdge para comparação
618
+ * @returns A instância com a data mais antiga
619
+ * @throws {Error} Se o array estiver vazio
620
+ * @example
621
+ * DatetimeEdge.min([
622
+ * new DatetimeEdge(new Date("2026-01-01")),
623
+ * new DatetimeEdge(new Date("2026-06-15")),
624
+ * ]) // DatetimeEdge("2026-01-01")
625
+ */
626
+ static min(dates) {
627
+ if (dates.length === 0) {
628
+ throw new Error("Cannot find min of an empty array of dates.");
629
+ }
630
+ return dates.reduce((min, date) => (date.isBefore(min) ? date : min));
131
631
  }
632
+ // ==================== Privados ====================
633
+ /**
634
+ * Valida se a data fornecida no construtor é uma data válida.
635
+ * @throws {Error} Se a data for inválida
636
+ */
132
637
  validate() {
133
638
  if (!(0, moment_1.default)(this.date).isValid()) {
134
639
  throw new Error(`${this.constructor.name} should be valid.`);