Thread: [INC] Unix Time
View Single Post
stupok
Veteran Member
Join Date: Feb 2006
Old 05-12-2009 , 21:56   Re: [INC] Unix Time Conversion
Reply With Quote #6

tyvm for this , you saved me some work

EDIT:
ARGH >_< I found a bug

I'm going to try to squash it, here are the details:

Code:
	new iYear = 0
	new iMonth = 0
	new iDay = 0
	new iHour = 0
	new iMinute = 0
	new iSecond = 0
	new iUnixTime = 123456789
	
	UnixToTime( iUnixTime, iYear, iMonth, iDay, iHour, iMinute, iSecond )
	
	server_print("UnixToTime:(%i)->(%i.%i.%i %i:%i:%i)", iUnixTime, iYear, iMonth, iDay, iHour, iMinute, iSecond )
	
	iUnixTime = TimeToUnix( iYear, iMonth, iDay, iHour, iMinute, iSecond )
	
	server_print("TimeToUnix:(%i.%i.%i %i:%i:%i)->(%i)", iYear, iMonth, iDay, iHour, iMinute, iSecond, iUnixTime )
	
	iYear++; iMonth++; iDay++; iHour++; iMinute++; iSecond++
	
	iUnixTime = TimeToUnix( iYear, iMonth, iDay, iHour, iMinute, iSecond )
	
	server_print("TimeToUnix:(%i.%i.%i %i:%i:%i)->(%i)", iYear, iMonth, iDay, iHour, iMinute, iSecond, iUnixTime )
	
	UnixToTime( iUnixTime, iYear, iMonth, iDay, iHour, iMinute, iSecond )
	
	server_print("UnixToTime:(%i)->(%i.%i.%i %i:%i:%i)", iUnixTime, iYear, iMonth, iDay, iHour, iMinute, iSecond )
Output:

Code:
UnixToTime:(123456789)->(1973.11.29 21:33:9)
TimeToUnix:(1973.11.29 21:33:9)->(123456789)
TimeToUnix:(1974.12.30 22:34:10)->(157674850)
UnixToTime:(157674850)->(1974.12.30 44:34:10)
Basically, the hours are being incremented instead of being replaced.

The fix:

Add the highlighted line.

Code:
stock UnixToTime( iTimeStamp , &iYear , &iMonth , &iDay , &iHour , &iMinute , &iSecond ) {     new iTemp;         iYear = 1970;     iMonth = 1;     iDay = 1;
    iHour = 0;
//...
__________________

Last edited by stupok; 05-13-2009 at 00:38.
stupok is offline