<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 7.1.05
// Randem Systems: https://randemsystems.support
// BotBanish Date / Time Subroutines
// Date: 02/10/2026
// Usage:
//
///////////////////////////////////////////////////////////////////////////////////////////////////////


function BotBanishGetCorrectDateB() {

	return strtotime(date('Y-m-d', strtotime(BotBanishGetCorrectDateTime())));
}

function BotBanishGetCorrectTimeB() {

	return strtotime(date('H:i:s', strtotime(BotBanishGetCorrectDateTime())));
}

function BotBanishGetCorrectDateTimeB() {

	return strtotime(date('Y-m-d H:i:s', strtotime(BotBanishGetCorrectDateTime())));
}

function BotBanishSetTimeZone($tz = '') {

	return;

	$tz = BotBanishGetTimeZone($tz);
	date_default_timezone_set($tz);
	return $tz;
}

function BotBanishGetCorrectTime($tz = '') {

	$tz = BotBanishGetTimeZone($tz);
	$dateB = date_create(BotBanishGetCorrectDateTime($tz));
	$date = date_format($dateB, 'H:i:s');
	return $date;
}

function BotBanishGetCorrectDateTime($tz = '') {

	$tz = BotBanishGetTimeZone($tz);
	$userTimezone = new DateTimeZone($tz);
	$gmtTimezone = new DateTimeZone('GMT');
	$myDateTime = new DateTime('now', $gmtTimezone);
	$offset = $userTimezone->getOffset($myDateTime);
	$myInterval=DateInterval::createFromDateString((string)$offset . 'seconds');
	$myDateTime->add($myInterval);
	$date = $myDateTime->format('Y-m-d H:i:s');
	return $date;
}

function BotBanishGetTimeZone($tz = '') {
	
	global $BotBanishSettings;
	
	if (empty($tz) && isset($BotBanishSettings['BOTBANISH_TIMEZONE'])) {
		
		$timezone = $BotBanishSettings['BOTBANISH_TIMEZONE'];
	
	}else {
		
		if (defined('SMF')) {

			global $modSettings;
			$timezone = $modSettings['default_timezone'];

		} else {

			$timezone = isset($_SERVER['TZ']) ? $_SERVER['TZ'] : date_default_timezone_get();
		}
	}
	
	return $timezone;
}

function BotBanishElapsedTime($time1 = 0, $time2 = 0) {

	if (empty($time1))
		
		$datetime1 = new DateTime();
	else
		$datetime1 = new DateTime($time1);

	if (empty($time2))
		
		$datetime2 = new DateTime();
	else
		$datetime2 = new DateTime($time2);
	
	$interval = $datetime1->diff($datetime2);
	$elapsed = $interval->format('%y, %m, %a, %h, %i, %s');
	$et = explode(',', $elapsed);
	
	
	return array('years' => $et[0], 'months' => $et[1], 'days' => $et[2], 'hours' => $et[3], 'minutes' => $et[4], 'seconds' => $et[5]);	
}
?>