07.11.2011, 12:43
Код:
#define MINUTE 60 #define HOUR 3600 #define DAY 86400 #define WEEK 604800 #define MONTH 2629743 ftime(time) // Переводим секунды в нормальное время { new r[max_line],M, w, d, h, m; if(!time) { r = "[нет]"; return r; } M = time / MONTH; time %= MONTH; w = time / WEEK; time %= WEEK; d = time / DAY; time %= DAY; h = time / HOUR; time %= HOUR; m = time / MINUTE; time %= MINUTE; r = " "; if(M) format(r,max_line,"%s %s",r,nformat(M,"месяц","месяца","месяцев")); if(w) format(r,max_line,"%s %s",r,nformat(w,"неделю","недели","недель")); if(d) format(r,max_line,"%s %s",r,nformat(d,"день","дня","дней")); if(h) format(r,max_line,"%s %s",r,nformat(h,"час","часа","часов")); if(m) format(r,max_line,"%s %s",r,nformat(m,"минуту","минуты","минут")); strdel(r,0,1); return r; nformat(n,f1[],f2[],f5[],nospace=0) // Правильное склонение числа { new r[max_line]; new fgg = n%100; if(fgg > 5 && fgg < 21) { if(nospace) format(r,max_line,"%i%s",n,f5); else format(r,max_line,"%i %s",n,f5); } else { new fg = n%10; if(fg < 1 || fg > 4) { if(nospace) format(r,max_line,"%i%s",n,f5); else format(r,max_line,"%i %s",n,f5); } else if(fg == 1) { if(nospace) format(r,max_line,"%i%s",n,f1); else format(r,max_line,"%i %s",n,f1); } else { if(nospace) format(r,max_line,"%i%s",n,f2); else format(r,max_line,"%i %s",n,f2); } } return r; } }