MyBB Community Forums

Full Version: Need Help To Automate Time Calculation For Delayed Moderation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
		case "do_delayedmoderation":
			case "delayedmoderation":
				// Verify incoming POST request
				verify_post_check($mybb->get_input('my_post_key'));
				
				$localized_time_offset = $mybb->user['timezone']*3600 + $mybb->user['dst']*3600;
		
				if(!$mybb->get_input('date_day', MyBB::INPUT_INT))
				{
					$mybb->input['date_day'] = gmdate('d', TIME_NOW + $localized_time_offset);
				}
				if(!$mybb->get_input('date_month', MyBB::INPUT_INT))
				{
					$mybb->input['date_month'] = gmdate('m', TIME_NOW + $localized_time_offset);
				}
		
				// Assume in-line moderation if TID is not set
				if(!empty($mybb->input['tid']))
				{
					$mybb->input['tids'] = $tid;
				}
				else
				{
					if($mybb->get_input('inlinetype') == 'search')
					{
						$tids = getids($mybb->get_input('searchid'), 'search');
					}
					else
					{
						$fid = $mybb->get_input('fid', MyBB::INPUT_INT);
						$tids = getids($fid, "forum");
					}
					if(count($tids) < 1)
					{
						error($lang->error_inline_nothreadsselected, $lang->error);
					}
		
					$mybb->input['tids'] = $tids;
				}
				 // Assuming $thread contains thread information with creation time
				 $creation_time = $thread['dateline']; // Get the creation time of the thread
				 $moderation_time = $creation_time + 24 * 60 * 60; // Add 24 hours to the creation time
			 
				 // Convert moderation time to date and time format
				 $moderation_date = gmdate('d', $moderation_time); // Day of the month (01 to 31)
				 $moderation_month = gmdate('m', $moderation_time); // Month (01 to 12)
				 $moderation_year = gmdate('Y', $moderation_time); // Year (e.g., 2024)
				 $moderation_hour = gmdate('H', $moderation_time); // Hour (00 to 23)
				 $moderation_minute = gmdate('i', $moderation_time); // Minute (00 to 59)
			 
				 // Set the moderation date and time inputs
				 $mybb->input['date_day'] = $moderation_date;
				 $mybb->input['date_month'] = $moderation_month;
				 $mybb->input['date_year'] = $moderation_year;
				 $mybb->input['date_time'] = $moderation_hour . ':' . $moderation_minute;
				add_breadcrumb($lang->delayed_moderation);



Here's how i want:

1. Thread A Creation Time: February 10, 2024, at 10:00 AM
2. Thread B Creation Time: February 10, 2024, at 12:00 PM
Now, let's calculate the time difference between Thread B and Thread A:

Time Difference = Thread B Creation Time - Thread A Creation Time
Time Difference = 12:00 PM - 10:00 AM = 2 hours
Since the time difference is less than 24 hours, we subtract it from 24 hours:

Remaining Time = 24 hours - 2 hours = 22 hours
Now, we add this remaining time to the creation time of Thread B to schedule the moderation action:

Moderation Time for Thread B = Thread B Creation Time + Remaining Time
Moderation Time for Thread B = 12:00 PM + 22 hours = 10:00 AM on February 11, 2024
So, the moderation action for both Thread A and Thread B will be scheduled for February 11, 2024, at 10:00 AM.