@atlantjs/arch 13.3.0 → 14.0.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.
- package/@tool-box/utils/datatypes/boolean-utils.d.ts +7 -0
- package/@tool-box/utils/datatypes/boolean-utils.js +146 -4
- package/@tool-box/utils/datatypes/string-utils.d.ts +20 -4
- package/@tool-box/utils/datatypes/string-utils.js +300 -14
- package/@tool-box/utils/ducts/common.d.ts +49 -0
- package/@tool-box/utils/ducts/common.js +36 -3
- package/@tool-box/utils/ducts/optional-type.d.ts +85 -0
- package/@tool-box/utils/ducts/optional-type.js +79 -0
- package/@tool-box/utils/ducts/return-type.d.ts +17 -17
- package/@tool-box/utils/ducts/return-type.js +14 -4
- package/@tool-box/utils/http-provider/http-provider.d.ts +6 -0
- package/@tool-box/utils/http-provider/http-provider.js +43 -14
- package/@tool-box/utils/map/map.abstract.d.ts +39 -0
- package/@tool-box/utils/map/map.abstract.js +70 -6
- package/@tool-box/utils/random/random.d.ts +168 -0
- package/@tool-box/utils/random/random.js +235 -0
- package/@tool-box/utils/type-guard/guardian.d.ts +450 -7
- package/@tool-box/utils/type-guard/guardian.js +539 -35
- package/objects/@common/edges/cron-expression.edge.d.ts +30 -2
- package/objects/@common/edges/cron-expression.edge.js +77 -5
- package/objects/@common/edges/email.edge.d.ts +39 -1
- package/objects/@common/edges/email.edge.js +80 -2
- package/objects/@common/edges/ulid.sketch.edge.d.ts +48 -1
- package/objects/@common/edges/ulid.sketch.edge.js +75 -4
- package/objects/@common/edges/url.edge.d.ts +182 -0
- package/objects/@common/edges/url.edge.js +249 -0
- package/objects/@common/edges/username.edge.d.ts +9 -0
- package/objects/@common/edges/username.edge.js +34 -0
- package/objects/@common/edges/uuid.sketch.edge.d.ts +97 -1
- package/objects/@common/edges/uuid.sketch.edge.js +127 -6
- package/objects/amount/amount-value.edge.d.ts +39 -0
- package/objects/amount/amount-value.edge.js +69 -0
- package/objects/amount/amount.edge.d.ts +378 -2
- package/objects/amount/amount.edge.js +493 -4
- package/objects/datetime/edges/datetime.edge.d.ts +422 -4
- package/objects/datetime/edges/datetime.edge.js +538 -33
- package/objects/password/password.edge.d.ts +90 -0
- package/objects/password/password.edge.js +140 -6
- package/objects/primitives/boolean.edge.sketch.d.ts +105 -3
- package/objects/primitives/boolean.edge.sketch.js +132 -6
- package/objects/primitives/number.edge.sketch.d.ts +236 -0
- package/objects/primitives/number.edge.sketch.js +310 -24
- package/objects/primitives/string.edge.sketch.d.ts +148 -0
- package/objects/primitives/string.edge.sketch.js +191 -7
- package/objects/schedule/schedule.edge.d.ts +194 -0
- package/objects/schedule/schedule.edge.js +269 -2
- package/objects/time/time.edge.d.ts +285 -2
- package/objects/time/time.edge.js +385 -6
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -11,12 +11,76 @@ class ScheduleEdge {
|
|
|
11
11
|
constructor(_moment) {
|
|
12
12
|
this._moment = _moment;
|
|
13
13
|
}
|
|
14
|
+
// ==================== Verificações ====================
|
|
15
|
+
/**
|
|
16
|
+
* Verifica se o agendamento é recorrente (baseado em expressão cron).
|
|
17
|
+
* @returns true se o agendamento é recorrente, false se é um datetime fixo
|
|
18
|
+
* @example
|
|
19
|
+
* new ScheduleEdge(new CronExpressionEdge("0 8 * * *")).isRecurrent() // true
|
|
20
|
+
* new ScheduleEdge(new DatetimeEdge(new Date())).isRecurrent() // false
|
|
21
|
+
*/
|
|
14
22
|
isRecurrent() {
|
|
15
|
-
|
|
23
|
+
return this._moment instanceof cron_expression_edge_1.CronExpressionEdge;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Verifica se o agendamento é um evento único (baseado em DatetimeEdge).
|
|
27
|
+
* @returns true se o agendamento é um evento único, false se é recorrente
|
|
28
|
+
* @example
|
|
29
|
+
* new ScheduleEdge(new DatetimeEdge(new Date())).isOneTime() // true
|
|
30
|
+
* new ScheduleEdge(new CronExpressionEdge("0 8 * * *")).isOneTime() // false
|
|
31
|
+
*/
|
|
32
|
+
isOneTime() {
|
|
33
|
+
return this._moment instanceof datetime_edge_1.DatetimeEdge;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Verifica se o agendamento já passou em relação à data/hora atual.
|
|
37
|
+
* Para agendamentos recorrentes, sempre retorna false.
|
|
38
|
+
* @returns true se a data do agendamento é anterior ao momento atual
|
|
39
|
+
* @example
|
|
40
|
+
* new ScheduleEdge(new DatetimeEdge(new Date("2020-01-01"))).isPast() // true
|
|
41
|
+
* new ScheduleEdge(new DatetimeEdge(new Date("2099-01-01"))).isPast() // false
|
|
42
|
+
*/
|
|
43
|
+
isPast() {
|
|
44
|
+
if (this._moment instanceof cron_expression_edge_1.CronExpressionEdge)
|
|
45
|
+
return false;
|
|
46
|
+
return this._moment.isBefore(new datetime_edge_1.DatetimeEdge(new Date()));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Verifica se o agendamento ainda está no futuro em relação à data/hora atual.
|
|
50
|
+
* Para agendamentos recorrentes, sempre retorna true.
|
|
51
|
+
* @returns true se a data do agendamento é posterior ao momento atual
|
|
52
|
+
* @example
|
|
53
|
+
* new ScheduleEdge(new DatetimeEdge(new Date("2099-01-01"))).isFuture() // true
|
|
54
|
+
* new ScheduleEdge(new DatetimeEdge(new Date("2020-01-01"))).isFuture() // false
|
|
55
|
+
*/
|
|
56
|
+
isFuture() {
|
|
57
|
+
if (this._moment instanceof cron_expression_edge_1.CronExpressionEdge)
|
|
16
58
|
return true;
|
|
59
|
+
return this._moment.isAfter(new datetime_edge_1.DatetimeEdge(new Date()));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Verifica se o agendamento ocorre hoje.
|
|
63
|
+
* Para agendamentos recorrentes, verifica se há uma ocorrência hoje.
|
|
64
|
+
* @returns true se há uma ocorrência hoje, false caso contrário
|
|
65
|
+
* @example
|
|
66
|
+
* new ScheduleEdge(new DatetimeEdge(new Date())).isToday() // true
|
|
67
|
+
*/
|
|
68
|
+
isToday() {
|
|
69
|
+
if (this._moment instanceof datetime_edge_1.DatetimeEdge) {
|
|
70
|
+
return this._moment.isToday();
|
|
17
71
|
}
|
|
18
|
-
|
|
72
|
+
const next = cron_parser_1.CronExpressionParser.parse(this._moment.toString()).next();
|
|
73
|
+
const nextDatetime = new datetime_edge_1.DatetimeEdge(next.toDate());
|
|
74
|
+
return nextDatetime.isToday();
|
|
19
75
|
}
|
|
76
|
+
// ==================== Ocorrências ====================
|
|
77
|
+
/**
|
|
78
|
+
* Retorna a próxima ocorrência de um agendamento recorrente.
|
|
79
|
+
* @returns Success com a próxima ocorrência ou Failure se o agendamento não for recorrente
|
|
80
|
+
* @example
|
|
81
|
+
* const schedule = new ScheduleEdge(new CronExpressionEdge("0 8 * * *"));
|
|
82
|
+
* schedule.nextOccurrence() // Success(DatetimeEdge com a próxima ocorrência às 8h)
|
|
83
|
+
*/
|
|
20
84
|
nextOccurrence() {
|
|
21
85
|
if (this._moment instanceof datetime_edge_1.DatetimeEdge) {
|
|
22
86
|
return (0, return_type_1.Failure)(new schedule_edge_failure_1.RecurringScheduleEdgeFailure(this._moment.toISOString()));
|
|
@@ -24,6 +88,14 @@ class ScheduleEdge {
|
|
|
24
88
|
const cronDate = cron_parser_1.CronExpressionParser.parse(this._moment.toString()).next();
|
|
25
89
|
return (0, return_type_1.Success)(new datetime_edge_1.DatetimeEdge(cronDate.toDate()));
|
|
26
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Retorna as próximas N ocorrências de um agendamento recorrente.
|
|
93
|
+
* @param quantity - Número de ocorrências a retornar
|
|
94
|
+
* @returns Success com array das próximas ocorrências ou Failure se não for recorrente
|
|
95
|
+
* @example
|
|
96
|
+
* const schedule = new ScheduleEdge(new CronExpressionEdge("0 8 * * *"));
|
|
97
|
+
* schedule.nextOccurrences(3) // Success([DatetimeEdge, DatetimeEdge, DatetimeEdge])
|
|
98
|
+
*/
|
|
27
99
|
nextOccurrences(quantity) {
|
|
28
100
|
if (this._moment instanceof datetime_edge_1.DatetimeEdge) {
|
|
29
101
|
return (0, return_type_1.Failure)(new schedule_edge_failure_1.RecurringScheduleEdgeFailure(this._moment.toISOString()));
|
|
@@ -31,6 +103,13 @@ class ScheduleEdge {
|
|
|
31
103
|
const cronDates = cron_parser_1.CronExpressionParser.parse(this._moment.toString()).take(quantity);
|
|
32
104
|
return (0, return_type_1.Success)(cronDates.map((cronDate) => new datetime_edge_1.DatetimeEdge(cronDate.toDate())));
|
|
33
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Retorna a ocorrência anterior de um agendamento recorrente.
|
|
108
|
+
* @returns Success com a ocorrência anterior ou Failure se o agendamento não for recorrente
|
|
109
|
+
* @example
|
|
110
|
+
* const schedule = new ScheduleEdge(new CronExpressionEdge("0 8 * * *"));
|
|
111
|
+
* schedule.previousOccurrence() // Success(DatetimeEdge com a última ocorrência às 8h)
|
|
112
|
+
*/
|
|
34
113
|
previousOccurrence() {
|
|
35
114
|
if (this._moment instanceof datetime_edge_1.DatetimeEdge) {
|
|
36
115
|
return (0, return_type_1.Failure)(new schedule_edge_failure_1.RecurringScheduleEdgeFailure(this._moment.toISOString()));
|
|
@@ -38,6 +117,14 @@ class ScheduleEdge {
|
|
|
38
117
|
const cronDate = cron_parser_1.CronExpressionParser.parse(this._moment.toString()).prev();
|
|
39
118
|
return (0, return_type_1.Success)(new datetime_edge_1.DatetimeEdge(cronDate.toDate()));
|
|
40
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Retorna as N ocorrências anteriores de um agendamento recorrente.
|
|
122
|
+
* @param quantity - Número de ocorrências a retornar
|
|
123
|
+
* @returns Success com array das ocorrências anteriores ou Failure se não for recorrente
|
|
124
|
+
* @example
|
|
125
|
+
* const schedule = new ScheduleEdge(new CronExpressionEdge("0 8 * * *"));
|
|
126
|
+
* schedule.previousOccurrences(3) // Success([DatetimeEdge, DatetimeEdge, DatetimeEdge])
|
|
127
|
+
*/
|
|
41
128
|
previousOccurrences(quantity) {
|
|
42
129
|
if (this._moment instanceof datetime_edge_1.DatetimeEdge) {
|
|
43
130
|
return (0, return_type_1.Failure)(new schedule_edge_failure_1.RecurringScheduleEdgeFailure(this._moment.toISOString()));
|
|
@@ -45,14 +132,194 @@ class ScheduleEdge {
|
|
|
45
132
|
const cronDates = cron_parser_1.CronExpressionParser.parse(this._moment.toString()).take(-quantity);
|
|
46
133
|
return (0, return_type_1.Success)(cronDates.map((cronDate) => new datetime_edge_1.DatetimeEdge(cronDate.toDate())));
|
|
47
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Retorna todas as ocorrências dentro de um intervalo de datas.
|
|
137
|
+
* @param start - Data de início do intervalo
|
|
138
|
+
* @param end - Data de fim do intervalo
|
|
139
|
+
* @returns Success com array das ocorrências no intervalo ou Failure se não for recorrente
|
|
140
|
+
* @example
|
|
141
|
+
* const schedule = new ScheduleEdge(new CronExpressionEdge("0 8 * * *"));
|
|
142
|
+
* schedule.occurrencesBetween(startDate, endDate)
|
|
143
|
+
* // Success([DatetimeEdge, DatetimeEdge, ...])
|
|
144
|
+
*/
|
|
145
|
+
occurrencesBetween(start, end) {
|
|
146
|
+
if (this._moment instanceof datetime_edge_1.DatetimeEdge) {
|
|
147
|
+
return (0, return_type_1.Failure)(new schedule_edge_failure_1.RecurringScheduleEdgeFailure(this._moment.toISOString()));
|
|
148
|
+
}
|
|
149
|
+
const interval = cron_parser_1.CronExpressionParser.parse(this._moment.toString(), {
|
|
150
|
+
currentDate: start.toDate(),
|
|
151
|
+
endDate: end.toDate(),
|
|
152
|
+
});
|
|
153
|
+
const occurrences = [];
|
|
154
|
+
while (true) {
|
|
155
|
+
try {
|
|
156
|
+
const next = interval.next();
|
|
157
|
+
occurrences.push(new datetime_edge_1.DatetimeEdge(next.toDate()));
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return (0, return_type_1.Success)(occurrences);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Conta quantas ocorrências existem dentro de um intervalo de datas.
|
|
167
|
+
* @param start - Data de início do intervalo
|
|
168
|
+
* @param end - Data de fim do intervalo
|
|
169
|
+
* @returns Success com o número de ocorrências ou Failure se não for recorrente
|
|
170
|
+
* @example
|
|
171
|
+
* const schedule = new ScheduleEdge(new CronExpressionEdge("0 8 * * 1-5"));
|
|
172
|
+
* schedule.countOccurrencesBetween(startDate, endDate) // Success(5) em uma semana
|
|
173
|
+
*/
|
|
174
|
+
countOccurrencesBetween(start, end) {
|
|
175
|
+
const resultWrapped = this.occurrencesBetween(start, end);
|
|
176
|
+
if (!resultWrapped.hasSuccess)
|
|
177
|
+
return resultWrapped;
|
|
178
|
+
return (0, return_type_1.Success)(resultWrapped.unwrap().values.length);
|
|
179
|
+
}
|
|
180
|
+
// ==================== Getters ====================
|
|
181
|
+
/**
|
|
182
|
+
* Retorna o horário do agendamento como um TimeEdge.
|
|
183
|
+
* @returns TimeEdge com hora e minuto do agendamento
|
|
184
|
+
* @example
|
|
185
|
+
* new ScheduleEdge(new CronExpressionEdge("0 8 * * *")).getTime()
|
|
186
|
+
* // TimeEdge("08:00")
|
|
187
|
+
*/
|
|
48
188
|
getTime() {
|
|
49
189
|
const interval = cron_parser_1.CronExpressionParser.parse(this._moment.toString()).fields;
|
|
50
190
|
const hour = String(interval.hour.values.toString()).padStart(2, "0");
|
|
51
191
|
const minute = String(interval.minute.values.toString()).padStart(2, "0");
|
|
52
192
|
return new time_edge_1.TimeEdge(`${hour}:${minute}`);
|
|
53
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Retorna o momento interno do agendamento (CronExpressionEdge ou DatetimeEdge).
|
|
196
|
+
* @returns Instância de CronExpressionEdge ou DatetimeEdge
|
|
197
|
+
* @example
|
|
198
|
+
* new ScheduleEdge(new CronExpressionEdge("0 8 * * *")).getMoment()
|
|
199
|
+
* // CronExpressionEdge("0 8 * * *")
|
|
200
|
+
*/
|
|
201
|
+
getMoment() {
|
|
202
|
+
return this._moment;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Retorna o DatetimeEdge do agendamento se for um evento único.
|
|
206
|
+
* @returns Success com o DatetimeEdge ou Failure se o agendamento for recorrente
|
|
207
|
+
* @example
|
|
208
|
+
* const date = new DatetimeEdge(new Date());
|
|
209
|
+
* new ScheduleEdge(date).getDatetime() // Success(DatetimeEdge)
|
|
210
|
+
*/
|
|
211
|
+
getDatetime() {
|
|
212
|
+
if (this._moment instanceof cron_expression_edge_1.CronExpressionEdge) {
|
|
213
|
+
return (0, return_type_1.Failure)(new schedule_edge_failure_1.RecurringScheduleEdgeFailure(this._moment.toString()));
|
|
214
|
+
}
|
|
215
|
+
return (0, return_type_1.Success)(this._moment);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Retorna a CronExpressionEdge do agendamento se for recorrente.
|
|
219
|
+
* @returns Success com a CronExpressionEdge ou Failure se for evento único
|
|
220
|
+
* @example
|
|
221
|
+
* const cron = new CronExpressionEdge("0 8 * * *");
|
|
222
|
+
* new ScheduleEdge(cron).getCronExpression() // Success(CronExpressionEdge)
|
|
223
|
+
*/
|
|
224
|
+
getCronExpression() {
|
|
225
|
+
if (this._moment instanceof datetime_edge_1.DatetimeEdge) {
|
|
226
|
+
return (0, return_type_1.Failure)(new schedule_edge_failure_1.RecurringScheduleEdgeFailure(this._moment.toISOString()));
|
|
227
|
+
}
|
|
228
|
+
return (0, return_type_1.Success)(this._moment);
|
|
229
|
+
}
|
|
230
|
+
// ==================== Clonagem e Imutabilidade ====================
|
|
231
|
+
/**
|
|
232
|
+
* Cria uma cópia independente desta instância de ScheduleEdge.
|
|
233
|
+
* @returns Nova instância com o mesmo momento interno
|
|
234
|
+
* @example
|
|
235
|
+
* const schedule = new ScheduleEdge(new CronExpressionEdge("0 8 * * *"));
|
|
236
|
+
* const clone = schedule.clone(); // instância independente
|
|
237
|
+
*/
|
|
238
|
+
clone() {
|
|
239
|
+
return new ScheduleEdge(this._moment);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Retorna uma nova instância com o momento alterado.
|
|
243
|
+
* @param moment - Novo momento (CronExpressionEdge ou DatetimeEdge)
|
|
244
|
+
* @returns Nova instância com o momento alterado
|
|
245
|
+
* @example
|
|
246
|
+
* const schedule = new ScheduleEdge(new CronExpressionEdge("0 8 * * *"));
|
|
247
|
+
* const updated = schedule.withMoment(new CronExpressionEdge("0 10 * * *"));
|
|
248
|
+
*/
|
|
249
|
+
withMoment(moment) {
|
|
250
|
+
return new ScheduleEdge(moment);
|
|
251
|
+
}
|
|
252
|
+
// ==================== Formatação ====================
|
|
253
|
+
/**
|
|
254
|
+
* Retorna a representação em string do momento do agendamento.
|
|
255
|
+
* Para cron, retorna a expressão cron. Para datetime, retorna a ISO string.
|
|
256
|
+
* @returns String representando o agendamento
|
|
257
|
+
* @example
|
|
258
|
+
* new ScheduleEdge(new CronExpressionEdge("0 8 * * *")).toString() // "0 8 * * *"
|
|
259
|
+
* new ScheduleEdge(new DatetimeEdge(new Date())).toString() // "2026-03-12T14:00:00.000Z"
|
|
260
|
+
*/
|
|
54
261
|
toString() {
|
|
55
262
|
return this._moment.toString();
|
|
56
263
|
}
|
|
264
|
+
// ==================== Métodos Estáticos ====================
|
|
265
|
+
/**
|
|
266
|
+
* Cria um ScheduleEdge recorrente a partir de uma expressão cron.
|
|
267
|
+
* @param expression - Expressão cron válida
|
|
268
|
+
* @returns Nova instância de ScheduleEdge recorrente
|
|
269
|
+
* @example
|
|
270
|
+
* ScheduleEdge.fromCron("0 8 * * *") // agendamento diário às 8h
|
|
271
|
+
* ScheduleEdge.fromCron("0 8 * * 1-5") // agendamento de segunda a sexta às 8h
|
|
272
|
+
*/
|
|
273
|
+
static fromCron(expression) {
|
|
274
|
+
return new ScheduleEdge(new cron_expression_edge_1.CronExpressionEdge(expression));
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Cria um ScheduleEdge de evento único a partir de um objeto Date.
|
|
278
|
+
* @param date - Data e hora do evento único
|
|
279
|
+
* @returns Nova instância de ScheduleEdge para evento único
|
|
280
|
+
* @example
|
|
281
|
+
* ScheduleEdge.fromDate(new Date("2026-12-25T08:00:00"))
|
|
282
|
+
* // agendamento para o Natal de 2026 às 8h
|
|
283
|
+
*/
|
|
284
|
+
static fromDate(date) {
|
|
285
|
+
return new ScheduleEdge(new datetime_edge_1.DatetimeEdge(date));
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Cria um ScheduleEdge para agendamentos diários em um horário específico.
|
|
289
|
+
* @param time - Horário do agendamento no formato TimeEdge
|
|
290
|
+
* @returns Nova instância de ScheduleEdge com recorrência diária
|
|
291
|
+
* @example
|
|
292
|
+
* ScheduleEdge.daily(new TimeEdge("08:00")) // todos os dias às 8h -> "0 8 * * *"
|
|
293
|
+
*/
|
|
294
|
+
static daily(time) {
|
|
295
|
+
const expression = `${time.getMinutes()} ${time.getHours()} * * *`;
|
|
296
|
+
return ScheduleEdge.fromCron(expression);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Cria um ScheduleEdge para agendamentos semanais em um dia e horário específico.
|
|
300
|
+
* @param dayOfWeek - Dia da semana (0=domingo, 1=segunda, ..., 6=sábado)
|
|
301
|
+
* @param time - Horário do agendamento no formato TimeEdge
|
|
302
|
+
* @returns Nova instância de ScheduleEdge com recorrência semanal
|
|
303
|
+
* @example
|
|
304
|
+
* ScheduleEdge.weekly(1, new TimeEdge("08:00"))
|
|
305
|
+
* // toda segunda-feira às 8h -> "0 8 * * 1"
|
|
306
|
+
*/
|
|
307
|
+
static weekly(dayOfWeek, time) {
|
|
308
|
+
const expression = `${time.getMinutes()} ${time.getHours()} * * ${dayOfWeek}`;
|
|
309
|
+
return ScheduleEdge.fromCron(expression);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Cria um ScheduleEdge para agendamentos mensais em um dia e horário específico.
|
|
313
|
+
* @param dayOfMonth - Dia do mês (1-31)
|
|
314
|
+
* @param time - Horário do agendamento no formato TimeEdge
|
|
315
|
+
* @returns Nova instância de ScheduleEdge com recorrência mensal
|
|
316
|
+
* @example
|
|
317
|
+
* ScheduleEdge.monthly(15, new TimeEdge("08:00"))
|
|
318
|
+
* // todo dia 15 de cada mês às 8h -> "0 8 15 * *"
|
|
319
|
+
*/
|
|
320
|
+
static monthly(dayOfMonth, time) {
|
|
321
|
+
const expression = `${time.getMinutes()} ${time.getHours()} ${dayOfMonth} * *`;
|
|
322
|
+
return ScheduleEdge.fromCron(expression);
|
|
323
|
+
}
|
|
57
324
|
}
|
|
58
325
|
exports.ScheduleEdge = ScheduleEdge;
|
|
@@ -1,11 +1,294 @@
|
|
|
1
1
|
export declare class TimeEdge {
|
|
2
2
|
private readonly value;
|
|
3
3
|
constructor(value: string);
|
|
4
|
+
/**
|
|
5
|
+
* Retorna as horas do tempo como número inteiro.
|
|
6
|
+
* @returns Número inteiro representando as horas (0-23)
|
|
7
|
+
* @example
|
|
8
|
+
* new TimeEdge("14:30").getHours() // 14
|
|
9
|
+
* new TimeEdge("08:00").getHours() // 8
|
|
10
|
+
*/
|
|
11
|
+
getHours(): number;
|
|
12
|
+
/**
|
|
13
|
+
* Retorna os minutos do tempo como número inteiro.
|
|
14
|
+
* @returns Número inteiro representando os minutos (0-59)
|
|
15
|
+
* @example
|
|
16
|
+
* new TimeEdge("14:30").getMinutes() // 30
|
|
17
|
+
* new TimeEdge("08:05").getMinutes() // 5
|
|
18
|
+
*/
|
|
19
|
+
getMinutes(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Retorna o tempo total convertido em minutos.
|
|
22
|
+
* @returns Total de minutos representados pelo tempo
|
|
23
|
+
* @example
|
|
24
|
+
* new TimeEdge("01:30").toTotalMinutes() // 90
|
|
25
|
+
* new TimeEdge("02:00").toTotalMinutes() // 120
|
|
26
|
+
*/
|
|
27
|
+
toTotalMinutes(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Retorna o tempo total convertido em segundos.
|
|
30
|
+
* @returns Total de segundos representados pelo tempo
|
|
31
|
+
* @example
|
|
32
|
+
* new TimeEdge("00:01").toTotalSeconds() // 60
|
|
33
|
+
* new TimeEdge("01:00").toTotalSeconds() // 3600
|
|
34
|
+
*/
|
|
35
|
+
toTotalSeconds(): number;
|
|
36
|
+
/**
|
|
37
|
+
* Subtrai um tempo de outro e retorna uma nova instância.
|
|
38
|
+
* @param time - Tempo a ser subtraído do valor atual
|
|
39
|
+
* @returns Nova instância de TimeEdge com o resultado da subtração
|
|
40
|
+
* @example
|
|
41
|
+
* new TimeEdge("10:30").subtract(new TimeEdge("01:00")) // TimeEdge("09:30")
|
|
42
|
+
* new TimeEdge("08:15").subtract(new TimeEdge("00:30")) // TimeEdge("07:45")
|
|
43
|
+
*/
|
|
4
44
|
subtract(time: TimeEdge): TimeEdge;
|
|
45
|
+
/**
|
|
46
|
+
* Soma um tempo ao valor atual e retorna uma nova instância.
|
|
47
|
+
* @param time - Tempo a ser somado ao valor atual
|
|
48
|
+
* @returns Nova instância de TimeEdge com o resultado da soma
|
|
49
|
+
* @example
|
|
50
|
+
* new TimeEdge("08:30").add(new TimeEdge("01:00")) // TimeEdge("09:30")
|
|
51
|
+
* new TimeEdge("23:30").add(new TimeEdge("01:00")) // TimeEdge("00:30")
|
|
52
|
+
*/
|
|
5
53
|
add(time: TimeEdge): TimeEdge;
|
|
54
|
+
/**
|
|
55
|
+
* Calcula a diferença absoluta entre dois tempos.
|
|
56
|
+
* @param time - Tempo para calcular a diferença
|
|
57
|
+
* @returns Nova instância de TimeEdge com a diferença absoluta
|
|
58
|
+
* @example
|
|
59
|
+
* new TimeEdge("10:00").difference(new TimeEdge("08:30")) // TimeEdge("01:30")
|
|
60
|
+
* new TimeEdge("08:30").difference(new TimeEdge("10:00")) // TimeEdge("01:30")
|
|
61
|
+
*/
|
|
62
|
+
difference(time: TimeEdge): TimeEdge;
|
|
63
|
+
/**
|
|
64
|
+
* Multiplica o tempo por um fator numérico e retorna uma nova instância.
|
|
65
|
+
* @param factor - Fator de multiplicação
|
|
66
|
+
* @returns Nova instância de TimeEdge com o tempo multiplicado
|
|
67
|
+
* @example
|
|
68
|
+
* new TimeEdge("01:30").multiply(2) // TimeEdge("03:00")
|
|
69
|
+
* new TimeEdge("00:20").multiply(3) // TimeEdge("01:00")
|
|
70
|
+
*/
|
|
71
|
+
multiply(factor: number): TimeEdge;
|
|
72
|
+
/**
|
|
73
|
+
* Verifica se este tempo é igual a outro.
|
|
74
|
+
* @param time - Tempo para comparação
|
|
75
|
+
* @returns true se os tempos são iguais, false caso contrário
|
|
76
|
+
* @example
|
|
77
|
+
* new TimeEdge("10:30").isEqual(new TimeEdge("10:30")) // true
|
|
78
|
+
* new TimeEdge("10:30").isEqual(new TimeEdge("10:00")) // false
|
|
79
|
+
*/
|
|
80
|
+
isEqual(time: TimeEdge): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Verifica se este tempo é diferente de outro.
|
|
83
|
+
* @param time - Tempo para comparação
|
|
84
|
+
* @returns true se os tempos são diferentes, false caso contrário
|
|
85
|
+
* @example
|
|
86
|
+
* new TimeEdge("10:30").isDifferent(new TimeEdge("09:00")) // true
|
|
87
|
+
* new TimeEdge("10:30").isDifferent(new TimeEdge("10:30")) // false
|
|
88
|
+
*/
|
|
89
|
+
isDifferent(time: TimeEdge): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Verifica se este tempo é maior que outro.
|
|
92
|
+
* @param time - Tempo para comparação
|
|
93
|
+
* @returns true se this > time, false caso contrário
|
|
94
|
+
* @example
|
|
95
|
+
* new TimeEdge("10:30").isGreaterThan(new TimeEdge("09:00")) // true
|
|
96
|
+
* new TimeEdge("08:00").isGreaterThan(new TimeEdge("10:00")) // false
|
|
97
|
+
*/
|
|
98
|
+
isGreaterThan(time: TimeEdge): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Verifica se este tempo é menor que outro.
|
|
101
|
+
* @param time - Tempo para comparação
|
|
102
|
+
* @returns true se this < time, false caso contrário
|
|
103
|
+
* @example
|
|
104
|
+
* new TimeEdge("08:00").isLessThan(new TimeEdge("10:00")) // true
|
|
105
|
+
* new TimeEdge("10:30").isLessThan(new TimeEdge("09:00")) // false
|
|
106
|
+
*/
|
|
107
|
+
isLessThan(time: TimeEdge): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Verifica se este tempo é maior ou igual a outro.
|
|
110
|
+
* @param time - Tempo para comparação
|
|
111
|
+
* @returns true se this >= time, false caso contrário
|
|
112
|
+
* @example
|
|
113
|
+
* new TimeEdge("10:30").isGreaterThanOrEqual(new TimeEdge("10:30")) // true
|
|
114
|
+
* new TimeEdge("10:30").isGreaterThanOrEqual(new TimeEdge("09:00")) // true
|
|
115
|
+
*/
|
|
116
|
+
isGreaterThanOrEqual(time: TimeEdge): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Verifica se este tempo é menor ou igual a outro.
|
|
119
|
+
* @param time - Tempo para comparação
|
|
120
|
+
* @returns true se this <= time, false caso contrário
|
|
121
|
+
* @example
|
|
122
|
+
* new TimeEdge("08:00").isLessThanOrEqual(new TimeEdge("08:00")) // true
|
|
123
|
+
* new TimeEdge("08:00").isLessThanOrEqual(new TimeEdge("10:00")) // true
|
|
124
|
+
*/
|
|
125
|
+
isLessThanOrEqual(time: TimeEdge): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Verifica se este tempo está entre dois limites (inclusive).
|
|
128
|
+
* @param start - Tempo mínimo do intervalo
|
|
129
|
+
* @param end - Tempo máximo do intervalo
|
|
130
|
+
* @returns true se o tempo está entre start e end, false caso contrário
|
|
131
|
+
* @example
|
|
132
|
+
* new TimeEdge("10:00").isBetween(new TimeEdge("08:00"), new TimeEdge("12:00")) // true
|
|
133
|
+
* new TimeEdge("14:00").isBetween(new TimeEdge("08:00"), new TimeEdge("12:00")) // false
|
|
134
|
+
*/
|
|
135
|
+
isBetween(start: TimeEdge, end: TimeEdge): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Verifica se o tempo representa meia-noite (00:00).
|
|
138
|
+
* @returns true se o tempo é 00:00, false caso contrário
|
|
139
|
+
* @example
|
|
140
|
+
* new TimeEdge("00:00").isMidnight() // true
|
|
141
|
+
* new TimeEdge("12:00").isMidnight() // false
|
|
142
|
+
*/
|
|
143
|
+
isMidnight(): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Verifica se o tempo representa o meio-dia (12:00).
|
|
146
|
+
* @returns true se o tempo é 12:00, false caso contrário
|
|
147
|
+
* @example
|
|
148
|
+
* new TimeEdge("12:00").isNoon() // true
|
|
149
|
+
* new TimeEdge("00:00").isNoon() // false
|
|
150
|
+
*/
|
|
151
|
+
isNoon(): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Verifica se o tempo está no período da manhã (00:00 até 11:59).
|
|
154
|
+
* @returns true se o tempo é anterior às 12:00, false caso contrário
|
|
155
|
+
* @example
|
|
156
|
+
* new TimeEdge("09:00").isMorning() // true
|
|
157
|
+
* new TimeEdge("13:00").isMorning() // false
|
|
158
|
+
*/
|
|
159
|
+
isMorning(): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Verifica se o tempo está no período da tarde (12:00 até 17:59).
|
|
162
|
+
* @returns true se o tempo está entre 12:00 e 17:59, false caso contrário
|
|
163
|
+
* @example
|
|
164
|
+
* new TimeEdge("14:00").isAfternoon() // true
|
|
165
|
+
* new TimeEdge("20:00").isAfternoon() // false
|
|
166
|
+
*/
|
|
167
|
+
isAfternoon(): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Verifica se o tempo está no período da noite (18:00 até 23:59).
|
|
170
|
+
* @returns true se o tempo é a partir das 18:00, false caso contrário
|
|
171
|
+
* @example
|
|
172
|
+
* new TimeEdge("20:00").isEvening() // true
|
|
173
|
+
* new TimeEdge("14:00").isEvening() // false
|
|
174
|
+
*/
|
|
175
|
+
isEvening(): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Cria uma cópia independente desta instância de TimeEdge.
|
|
178
|
+
* @returns Nova instância com o mesmo valor de tempo
|
|
179
|
+
* @example
|
|
180
|
+
* const time1 = new TimeEdge("10:30");
|
|
181
|
+
* const time2 = time1.clone(); // instância independente com "10:30"
|
|
182
|
+
*/
|
|
183
|
+
clone(): TimeEdge;
|
|
184
|
+
/**
|
|
185
|
+
* Retorna uma nova instância com as horas alteradas.
|
|
186
|
+
* @param hours - Novo valor de horas (0-23)
|
|
187
|
+
* @returns Nova instância com as horas alteradas
|
|
188
|
+
* @example
|
|
189
|
+
* new TimeEdge("10:30").withHours(15) // TimeEdge("15:30")
|
|
190
|
+
*/
|
|
191
|
+
withHours(hours: number): TimeEdge;
|
|
192
|
+
/**
|
|
193
|
+
* Retorna uma nova instância com os minutos alterados.
|
|
194
|
+
* @param minutes - Novo valor de minutos (0-59)
|
|
195
|
+
* @returns Nova instância com os minutos alterados
|
|
196
|
+
* @example
|
|
197
|
+
* new TimeEdge("10:30").withMinutes(45) // TimeEdge("10:45")
|
|
198
|
+
*/
|
|
199
|
+
withMinutes(minutes: number): TimeEdge;
|
|
200
|
+
/**
|
|
201
|
+
* Retorna o tempo como string no formato HH:mm.
|
|
202
|
+
* @returns String no formato "HH:mm"
|
|
203
|
+
* @example
|
|
204
|
+
* new TimeEdge("14:30").toString() // "14:30"
|
|
205
|
+
*/
|
|
6
206
|
toString(): string;
|
|
207
|
+
/**
|
|
208
|
+
* Retorna o tempo no formato de 12 horas com AM/PM.
|
|
209
|
+
* @returns String no formato "hh:mm AM/PM"
|
|
210
|
+
* @example
|
|
211
|
+
* new TimeEdge("14:30").toFormat12h() // "02:30 PM"
|
|
212
|
+
* new TimeEdge("08:00").toFormat12h() // "08:00 AM"
|
|
213
|
+
*/
|
|
214
|
+
toFormat12h(): string;
|
|
215
|
+
/**
|
|
216
|
+
* Retorna uma representação legível do tempo em horas e minutos por extenso.
|
|
217
|
+
* @returns String descritiva no formato "Xh Ym"
|
|
218
|
+
* @example
|
|
219
|
+
* new TimeEdge("14:30").toReadableString() // "14h 30m"
|
|
220
|
+
* new TimeEdge("08:05").toReadableString() // "8h 5m"
|
|
221
|
+
*/
|
|
222
|
+
toReadableString(): string;
|
|
223
|
+
/**
|
|
224
|
+
* Cria um TimeEdge representando a hora atual do sistema.
|
|
225
|
+
* @returns Nova instância com o horário atual no formato HH:mm
|
|
226
|
+
* @example
|
|
227
|
+
* TimeEdge.now() // pode retornar TimeEdge("14:35") dependendo da hora atual
|
|
228
|
+
*/
|
|
229
|
+
static now(): TimeEdge;
|
|
230
|
+
/**
|
|
231
|
+
* Cria um TimeEdge representando a meia-noite (00:00).
|
|
232
|
+
* @returns Nova instância com o valor "00:00"
|
|
233
|
+
* @example
|
|
234
|
+
* TimeEdge.midnight() // TimeEdge("00:00")
|
|
235
|
+
*/
|
|
236
|
+
static midnight(): TimeEdge;
|
|
237
|
+
/**
|
|
238
|
+
* Cria um TimeEdge representando o meio-dia (12:00).
|
|
239
|
+
* @returns Nova instância com o valor "12:00"
|
|
240
|
+
* @example
|
|
241
|
+
* TimeEdge.noon() // TimeEdge("12:00")
|
|
242
|
+
*/
|
|
243
|
+
static noon(): TimeEdge;
|
|
244
|
+
/**
|
|
245
|
+
* Cria um TimeEdge a partir de um total de minutos.
|
|
246
|
+
* @param totalMinutes - Total de minutos a converter para HH:mm
|
|
247
|
+
* @returns Nova instância com o tempo correspondente ao total de minutos
|
|
248
|
+
* @example
|
|
249
|
+
* TimeEdge.fromMinutes(90) // TimeEdge("01:30")
|
|
250
|
+
* TimeEdge.fromMinutes(125) // TimeEdge("02:05")
|
|
251
|
+
*/
|
|
252
|
+
static fromMinutes(totalMinutes: number): TimeEdge;
|
|
253
|
+
/**
|
|
254
|
+
* Retorna o maior tempo de uma lista.
|
|
255
|
+
* @param times - Array de instâncias de TimeEdge para comparação
|
|
256
|
+
* @returns A instância com o maior valor de tempo
|
|
257
|
+
* @throws {Error} Se o array estiver vazio
|
|
258
|
+
* @example
|
|
259
|
+
* TimeEdge.max([new TimeEdge("08:00"), new TimeEdge("14:30"), new TimeEdge("10:00")])
|
|
260
|
+
* // TimeEdge("14:30")
|
|
261
|
+
*/
|
|
262
|
+
static max(times: TimeEdge[]): TimeEdge;
|
|
263
|
+
/**
|
|
264
|
+
* Retorna o menor tempo de uma lista.
|
|
265
|
+
* @param times - Array de instâncias de TimeEdge para comparação
|
|
266
|
+
* @returns A instância com o menor valor de tempo
|
|
267
|
+
* @throws {Error} Se o array estiver vazio
|
|
268
|
+
* @example
|
|
269
|
+
* TimeEdge.min([new TimeEdge("08:00"), new TimeEdge("14:30"), new TimeEdge("10:00")])
|
|
270
|
+
* // TimeEdge("08:00")
|
|
271
|
+
*/
|
|
272
|
+
static min(times: TimeEdge[]): TimeEdge;
|
|
273
|
+
/**
|
|
274
|
+
* Soma uma lista de tempos e retorna o total.
|
|
275
|
+
* @param times - Array de instâncias de TimeEdge para somar
|
|
276
|
+
* @returns Nova instância com a soma total dos tempos
|
|
277
|
+
* @throws {Error} Se o array estiver vazio
|
|
278
|
+
* @example
|
|
279
|
+
* TimeEdge.sumAll([new TimeEdge("01:00"), new TimeEdge("02:30"), new TimeEdge("00:15")])
|
|
280
|
+
* // TimeEdge("03:45")
|
|
281
|
+
*/
|
|
282
|
+
static sumAll(times: TimeEdge[]): TimeEdge;
|
|
283
|
+
/**
|
|
284
|
+
* Valida o formato do tempo informado no construtor.
|
|
285
|
+
* @throws {Error} Se o formato não for HH:mm válido
|
|
286
|
+
*/
|
|
7
287
|
private validate;
|
|
288
|
+
/**
|
|
289
|
+
* Verifica se uma string está no formato de tempo HH:mm válido.
|
|
290
|
+
* @param value - String a ser validada
|
|
291
|
+
* @returns true se o formato é válido, false caso contrário
|
|
292
|
+
*/
|
|
8
293
|
private isValidTimeFormat;
|
|
9
|
-
getHours(): number;
|
|
10
|
-
private getMinutes;
|
|
11
294
|
}
|