Originally Posted by SickAttack
Uso:
pawn Код:
new second = 37272, minute, hour, day, week, month, year; format(string, sizeof(string), "37272 en tiempo ---> %s.", ConvertToTime(second, minute, hour, day, week, month, year)); SendClientMessage(playerid, -1, string);
Lo que hace el trabajo:
pawn Код:
ConvertToTime(&cts, &ctm=-1, &cth=-1, &ctd=-1, &ctw=-1, &ctmo=-1, &cty=-1) { #define PLUR(%0,%1,%2) (%0),((%0) == 1)?((#%1)):((#%2)) #define CTM_cty 31536000 #define CTM_ctmo 2628000 #define CTM_ctw 604800 #define CTM_ctd 86400 #define CTM_cth 3600 #define CTM_ctm 60 #define CT(%0) %0 = cts / CTM_%0; cts %= CTM_%0
new string[128]; if(cty != -1 && (cts / CTM_cty)) { CT(cty); CT(ctmo); CT(ctw); CT(ctd); CT(cth); CT(ctm); format(string, sizeof(string), "%d %s, %d %s, %d %s, %d %s, %d %s, %d %s, and %d %s", PLUR(cty, "year", "years"), PLUR(ctmo, "month", "months"), PLUR(ctw, "week", "weeks"), \ PLUR(ctd, "day", "days"), PLUR(cth, "hour", "hours"), PLUR(ctm, "minute", "minutes"), PLUR(cts, "second", "seconds")); return string; } if(ctmo != -1 && (cts / CTM_ctmo)) { cty = 0; CT(ctmo); CT(ctw); CT(ctd); CT(cth); CT(ctm); format(string, sizeof(string), "%d %s, %d %s, %d %s, %d %s, %d %s, and %d %s", PLUR(ctmo, "month", "months"), PLUR(ctw, "week", "weeks"), PLUR(ctd, "day", "days"), PLUR(cth, "hour", \ "hours"), PLUR(ctm, "minute", "minutes"), PLUR(cts, "second", "seconds")); return string; } if(ctw != -1 && (cts / CTM_ctw)) { cty = 0; ctmo = 0; CT(ctw); CT(ctd); CT(cth); CT(ctm); format(string, sizeof(string), "%d %s, %d %s, %d %s, %d %s, and %d %s", PLUR(ctw, "week", "weeks"), PLUR(ctd, "day", "days"), PLUR(cth, "hour", "hours"), PLUR(ctm, "minute", \ "minutes"), PLUR(cts, "second", "seconds")); return string; } if(ctd != -1 && (cts / CTM_ctd)) { cty = 0; ctmo = 0; ctw = 0; CT(ctd); CT(cth); CT(ctm); format(string, sizeof(string), "%d %s, %d %s, %d %s, and %d %s", PLUR(ctd, "day", "days"), PLUR(cth, "hour", "hours"), PLUR(ctm, "minute", "minutes"), PLUR(cts, "second", "seconds")); return string; } if(cth != -1 && (cts / CTM_cth)) { cty = 0; ctmo = 0; ctw = 0; ctd = 0; CT(cth); CT(ctm); format(string, sizeof(string), "%d %s, %d %s, and %d %s", PLUR(cth, "hour", "hours"), PLUR(ctm, "minute", "minutes"), PLUR(cts, "second", "seconds")); return string; } if(ctm != -1 && (cts / CTM_ctm)) { cty = 0; ctmo = 0; ctw = 0; ctd = 0; cth = 0; CT(ctm); format(string, sizeof(string), "%d %s, and %d %s", PLUR(ctm, "minute", "minutes"), PLUR(cts, "second", "seconds")); return string; }
cty = 0; ctmo = 0; ctw = 0; ctd = 0; cth = 0; ctm = 0; format(string, sizeof(string), "%d %s", PLUR(cts, "second", "seconds")); return string; }
|