[Problem] Day calculation
#1

I have a problem with day calculation of my ban sistem , There are months with 29 day , 30 and 31 .


Код:
while(hour > 24)
	{
		day++;
		hour -= 24;
	}
	while(day > 30)
	{
		 month++;
		 day -= 30;
	}
	while(month > 12)
	{
		year++;
		month -= 12;
	}
Reply
#2

Try this:

pawn Код:
new LastDays2012[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 }; // lookin the calender of 2012

if(hour > 24)
{
    day++;
    hour -= 24;
}
if(day > LastDays2012[month])
{
    month++;
    day -= LastDays2012[month];
}
if(month > 12)
{
    year++;
    month -= 12;
}
Reply
#3

That is a good system DarkScripter shows, but you could create a better system using GetTime and GetDate.
Reply
#4

Quote:
Originally Posted by Deduction
Посмотреть сообщение
That is a good system DarkScripter shows, but you could create a better system using GetTime and GetDate.
the gettime and getdate don't get last days of month...
Reply
#5

Thanks , but better use while it's repeating untill the condition is false
Reply
#6

It's not working so good
Reply
#7

Use timestamps!

Gettime returns a Unix Timestamp, which is the seconds past since 1 January 1970. If you want to give a two-days ban, you can do it this way:

pawn Код:
unbantime = gettime() + (60 * 60 * 24 * DAYS); // returns the timestamp which the player should be unbanned
Then create a simple one-day-timer which loops through a file with banned IPs and their unban-timestamp. If the timestamp matches the current timestamp or if it's lower, unban!
Reply
#8

No , it's not good with time stamp And I have an ideea how to make , thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)