@@ -255,46 +255,39 @@ function generateTimeslotKeys($RAID_SLOTS, $raid) {
255
255
$ directStartMinutes = $ direct_slot ->format ('i ' );
256
256
257
257
// Get first raidslot rounded up to the next 5 minutes
258
- $ five_slot = new DateTimeImmutable ($ raid ['start_time ' ], new DateTimeZone ('UTC ' ));
259
258
$ minute = $ directStartMinutes % 5 ;
260
- $ diff = ($ minute != 0 ) ? 5 - $ minute : 5 ;
261
- $ five_slot = $ five_slot ->add (new DateInterval ('PT ' .$ diff .'M ' ));
259
+ $ diff = ($ minute != 0 ) ? 5 - $ minute : 0 ;
260
+ $ five_slot = $ direct_slot ->add (new DateInterval ('PT ' .$ diff .'M ' ));
261
+
262
+ // Add $config->RAID_FIRST_START minutes to five minutes slot
263
+ $ five_plus_slot = $ five_slot ;
264
+ $ five_plus_slot = $ five_plus_slot ->add (new DateInterval ("PT " .$ config ->RAID_FIRST_START ."M " ));
262
265
263
266
// Get first regular raidslot
264
- $ first_slot =
265
- ($ minute == 0 ) ?
266
- $ direct_slot ->add (new DateInterval ('PT ' .$ RAID_SLOTS .'M ' )) :
267
- $ five_slot ->add (new DateInterval ('PT ' .$ RAID_SLOTS .'M ' )
268
- );
267
+ $ firstSlotMinute = $ directStartMinutes % $ RAID_SLOTS ;
268
+ $ firstSlotDiff = ($ firstSlotMinute != 0 ) ? $ RAID_SLOTS - ($ firstSlotMinute ) : 0 ;
269
+ $ first_slot = $ direct_slot ->add (new DateInterval ('PT ' .$ firstSlotDiff .'M ' ));
269
270
270
271
// Write slots to log.
271
272
debug_log ($ direct_slot , 'Direct start slot: ' );
272
273
debug_log ($ five_slot , 'Next 5 Minute slot: ' );
273
274
debug_log ($ first_slot , 'First regular slot: ' );
274
275
$ keys_time = [];
275
- // Add button for when raid starts time
276
- if ($ config ->RAID_DIRECT_START && $ direct_slot >= $ dt_now ) {
276
+
277
+ // Add button for direct start if needed
278
+ if ($ config ->RAID_DIRECT_START && $ direct_slot != $ five_slot && $ direct_slot >= $ dt_now ) {
277
279
$ keys_time [] = button (dt2time ($ direct_slot ->format ('Y-m-d H:i:s ' )), ['vote_time ' , 'r ' => $ raid ['id ' ], 't ' => $ direct_slot ->format ('YmdHis ' )]);
278
- $ last_slot = $ direct_slot ;
279
280
}
280
- // Add five minutes slot
281
- if ($ five_slot >= $ dt_now &&
282
- (empty ($ keys_time ) || (!empty ($ keys_time ) && $ direct_slot != $ five_slot )) &&
283
- $ raid ['event_vote_key_mode ' ] !== 0
284
- ) {
281
+
282
+ // Add button for first five minutes if needed
283
+ if ($ five_slot < $ first_slot && $ five_plus_slot <= $ first_slot && $ five_slot >= $ dt_now ) {
285
284
$ keys_time [] = button (dt2time ($ five_slot ->format ('Y-m-d H:i:s ' )), ['vote_time ' , 'r ' => $ raid ['id ' ], 't ' => $ five_slot ->format ('YmdHis ' )]);
286
- $ last_slot = $ five_slot ;
287
- }
288
- // Add the first normal slot
289
- if ($ first_slot >= $ dt_now && $ first_slot != $ five_slot ) {
290
- $ keys_time [] = button (dt2time ($ first_slot ->format ('Y-m-d H:i:s ' )), ['vote_time ' , 'r ' => $ raid ['id ' ], 't ' => $ first_slot ->format ('YmdHis ' )]);
291
- $ last_slot = $ first_slot ;
292
285
}
293
286
294
287
// Get regular slots
295
288
// Start with second slot as first slot is already added to keys.
296
289
$ dt_end = new DateTimeImmutable ($ raid ['end_time ' ], new DateTimeZone ('UTC ' ));
297
- $ regular_slots = new DatePeriod ($ first_slot , new DateInterval ('PT ' .$ RAID_SLOTS .'M ' ), $ dt_end ->sub (new DateInterval ('PT ' .$ config ->RAID_LAST_START .'M ' )), DatePeriod:: EXCLUDE_START_DATE );
290
+ $ regular_slots = new DatePeriod ($ first_slot , new DateInterval ('PT ' .$ RAID_SLOTS .'M ' ), $ dt_end ->sub (new DateInterval ('PT ' .$ config ->RAID_LAST_START .'M ' )));
298
291
299
292
// Add regular slots.
300
293
foreach ($ regular_slots as $ slot ){
@@ -309,8 +302,7 @@ function generateTimeslotKeys($RAID_SLOTS, $raid) {
309
302
310
303
// Add raid last start slot
311
304
// Set end_time to last extra slot, subtract $config->RAID_LAST_START minutes and round down to earlier 5 minutes.
312
- $ last_extra_slot = $ dt_end ;
313
- $ last_extra_slot = $ last_extra_slot ->sub (new DateInterval ('PT ' .$ config ->RAID_LAST_START .'M ' ));
305
+ $ last_extra_slot = $ dt_end ->sub (new DateInterval ('PT ' .$ config ->RAID_LAST_START .'M ' ));
314
306
$ s = 5 * 60 ;
315
307
$ last_extra_slot = $ last_extra_slot ->setTimestamp ($ s * floor ($ last_extra_slot ->getTimestamp () / $ s ));
316
308
@@ -319,8 +311,9 @@ function generateTimeslotKeys($RAID_SLOTS, $raid) {
319
311
debug_log ($ last_extra_slot , 'Last extra slot: ' );
320
312
321
313
// Last extra slot not conflicting with last slot
322
- if ((isset ($ last_slot ) && $ last_extra_slot > $ last_slot && $ last_extra_slot != $ last_slot && $ last_extra_slot >= $ dt_now ) ||
323
- (!isset ($ last_slot ) && $ last_extra_slot >= $ dt_now )) {
314
+ if ($ last_extra_slot >= $ dt_now &&
315
+ ((isset ($ last_slot ) && $ last_extra_slot > $ last_slot && $ last_extra_slot != $ last_slot ) ||
316
+ !isset ($ last_slot ))) {
324
317
// Add last extra slot
325
318
$ keys_time [] = button (dt2time ($ last_extra_slot ->format ('Y-m-d H:i:s ' )), ['vote_time ' , 'r ' => $ raid ['id ' ], 't ' => $ last_extra_slot ->format ('YmdHis ' )]);
326
319
}
0 commit comments