@@ -239,23 +239,7 @@ class Maintenance extends BeanModel {
239
239
this . beanMeta . status = "under-maintenance" ;
240
240
clearTimeout ( this . beanMeta . durationTimeout ) ;
241
241
242
- // Check if duration is still in the window. If not, use the duration from the current time to the end of the window
243
- let duration ;
244
-
245
- if ( customDuration > 0 ) {
246
- duration = customDuration ;
247
- } else if ( this . end_date ) {
248
- let d = dayjs ( this . end_date ) . diff ( dayjs ( ) , "second" ) ;
249
- if ( d < this . duration ) {
250
- duration = d * 1000 ;
251
- }
252
- } else {
253
- duration = this . duration * 1000 ;
254
- }
255
-
256
- if ( duration === undefined && this . strategy === "recurring-interval" ) {
257
- duration = this . duration * 1000 ; // For recurring-interval, the duration needs to be defined
258
- }
242
+ let duration = this . inferDuration ( customDuration ) ;
259
243
260
244
UptimeKumaServer . getInstance ( ) . sendMaintenanceListByUserID ( this . user_id ) ;
261
245
@@ -327,6 +311,24 @@ class Maintenance extends BeanModel {
327
311
}
328
312
}
329
313
314
+ /**
315
+ * Calculate the maintenance duration
316
+ * @returns {number }
317
+ */
318
+
319
+ inferDuration ( customDuration ) {
320
+ // Check if duration is still in the window. If not, use the duration from the current time to the end of the window
321
+ if ( customDuration > 0 ) {
322
+ return customDuration ;
323
+ } else if ( this . end_date ) {
324
+ let d = dayjs ( this . end_date ) . diff ( dayjs ( ) , "second" ) ;
325
+ if ( d < this . duration ) {
326
+ return d * 1000 ;
327
+ }
328
+ }
329
+ return this . duration * 1000 ;
330
+ }
331
+
330
332
/**
331
333
* Stop the maintenance
332
334
* @returns {void }
0 commit comments