View Single Post
Author Message
eyal282
Veteran Member
Join Date: Aug 2011
Old 09-19-2020 , 06:10   GetTime offset relative to server's timezone
Reply With Quote #1

This stock allows you to get the amount of seconds the server is before or after unix. I used it to make offsets to use GetTime in a way that works around the end of the day, 00:00. Hopefully it will be useful to you.

Code:
stock int GetTimeOffset()
{
	bool Negate = false;
	char Time[11];

	FormatTime(Time, sizeof(Time), "%A", 86400);
	
	if(StrEqual(Time, "Thursday")) // 86400 in unix is Friday, meaning the timezone brought us back a bit.
		Negate = true;
		
	FormatTime(Time, sizeof(Time), "%H %M", 86400); // Can't use 0 because of negatives I think. I assume.
	
	char sHour[4], sMinute[4];
	
	int pos = BreakString(Time, sHour, sizeof(sHour));
	
	FormatEx(sMinute, sizeof(sMinute), Time[pos]);
	
	int secondstotal = StringToInt(sHour) * 3600 + StringToInt(sMinute) * 60;
	
	if(secondstotal == 0 || !Negate) // Server's time is positive or zero ( unix time )
		return secondstotal;
		
	else 
	{
		/*
		Suppose an hour negative, turns 00:00 into 23:00. The result should be -3600.
		-1 * (86400 - (23 * 3600 + 0 * 60)) = -3600
		*/
		return -1 * (86400 - secondstotal); 
	}
}
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline