Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stock dateFromTimestamp( timestamp, _form=0 )
- {
- /*
- ~ convert a Timestamp to a Date. (unknown source)
- ~ 10.07.2009
- date( 1247182451 ) will print >> 09.07.2009-23:34:11
- date( 1247182451, 1) will print >> 09/07/2009, 23:34:11
- date( 1247182451, 2) will print >> July 09, 2009, 23:34:11
- date( 1247182451, 3) will print >> 9 Jul 2009, 23:34
- */
- new year=1970, day=0, month=0, hour=0, mins=0, sec=0;
- new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
- new names_of_month[12][10] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
- new returnstring[32];
- while(timestamp>31622400){
- timestamp -= 31536000;
- if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp -= 86400;
- year++;
- }
- if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )
- days_of_month[1] = 29;
- else
- days_of_month[1] = 28;
- while(timestamp>86400){
- timestamp -= 86400, day++;
- if(day==days_of_month[month]) day=0, month++;
- }
- while(timestamp>60){
- timestamp -= 60, mins++;
- if( mins == 60) mins=0, hour++;
- }
- sec=timestamp;
- switch( _form ){
- case 1: format(returnstring, 31, "%02d/%02d/%d %02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
- case 2: format(returnstring, 31, "%s %02d, %d, %02d:%02d:%02d", names_of_month[month],day+1,year, hour, mins, sec);
- case 3: format(returnstring, 31, "%d %c%c%c %d, %02d:%02d", day+1,names_of_month[month][0],names_of_month[month][1],names_of_month[month][2], year,hour,mins);
- default: format(returnstring, 31, "%02d.%02d.%d-%02d:%02d:%02d", day+1, month+1, year, hour, mins, sec);
- }
- return returnstring;
- }
- stock unixTimeConvert(timestamp, compare = -1) {
- // Made by Blacklite, fixed to work in Pawn by Calgon
- if (compare == -1) {
- compare = gettime();
- }
- new
- n,
- Float:d = (timestamp > compare) ? timestamp - compare : compare - timestamp,
- returnstr[32];
- if (d < 60) {
- format(returnstr, sizeof(returnstr), "< 1 minute");
- return returnstr;
- } else if (d < 3600) { // 3600 = 1 hour
- n = floatround(floatdiv(d, 60.0), floatround_floor);
- format(returnstr, sizeof(returnstr), "minute");
- } else if (d < 86400) { // 86400 = 1 day
- n = floatround(floatdiv(d, 3600.0), floatround_floor);
- format(returnstr, sizeof(returnstr), "hour");
- } else if (d < 2592000) { // 2592000 = 1 month
- n = floatround(floatdiv(d, 86400.0), floatround_floor);
- format(returnstr, sizeof(returnstr), "day");
- } else if (d < 31536000) { // 31536000 = 1 year
- n = floatround(floatdiv(d, 2592000.0), floatround_floor);
- format(returnstr, sizeof(returnstr), "month");
- } else {
- n = floatround(floatdiv(d, 31536000.0), floatround_floor);
- format(returnstr, sizeof(returnstr), "year");
- }
- if (n == 1) {
- format(returnstr, sizeof(returnstr), "1 %s", returnstr);
- } else {
- format(returnstr, sizeof(returnstr), "%d %ss", n, returnstr);
- }
- return returnstr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement