07.08.2008, 05:29
That function is very nice, Westie. I may use it in the future.
I'll post a function that calculate time with an offset:
First 6 values are simply integers to get time from. You can put them variables with stored date and time. The other are offset for the time (sy: year offset, smo: month offset, sd: day offset, sh: hour offset, ...)
Offset values can be any integer values including negative values.
That's all.
I'll post a function that calculate time with an offset:
Код:
stock ShiftTime(&y=0,&mo=1,&d=1,&h=0,&m=0,&s=0,sy=0,smo=0,sd=0,sh=0,sm=0,ss=0){ new days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; s+=ss; m+=sm+(s/60); h+=sh+(m/60); d+=-1+sd+(h/24); mo+=smo-1;y+=sy+mo/12;mo%=12; if((!(y%4)&&(y%100))||!(y%400))days[1]=29; for(new i=sign(d);d/days[mo];d-=i*days[mo]){ mo+=i; if(mo>11||mo<0){ y+=i;if((!(y%4)&&(y%100))||!(y%400))days[1]=29;else days[1]=28; }mo%=12; }s%=60;m%=60;h%=24;mo+=1;d+=1; }stock sign({Float,_}:x){if(x>0)return 1;else if(x<0)return -1;return 0;}
Offset values can be any integer values including negative values.
That's all.