SHARE
TWEET

Untitled

a guest Mar 29th, 2016 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define SPLITTER .
  2.  
  3. new MonthTimes[12][4] =
  4. {
  5.         { 31, 31, 2678400, 2678400 },
  6.         { 28, 29, 2419200, 2505600 },
  7.         { 31, 31, 2678400, 2678400 },
  8.         { 30, 30, 2592000, 2592000 },
  9.         { 31, 31, 2678400, 2678400 },
  10.         { 30, 30, 2592000, 2592000 },
  11.         { 31, 31, 2678400, 2678400 },
  12.         { 31, 31, 2678400, 2678400 },
  13.         { 30, 30, 2592000, 2592000 },
  14.         { 31, 31, 2678400, 2678400 },
  15.         { 30, 30, 2592000, 2592000 },
  16.         { 31, 31, 2678400, 2678400 }
  17. };
  18.  
  19. stock IsLeapYear(year)
  20. {
  21.         if(year % 4 == 0) return 1;
  22.         else return 0;
  23. }
  24.  
  25. stock TimestampToDate(Timestamp, &year, &month, &day, &hour, &minute, &second, HourGMT, MinuteGMT = 0)
  26. {
  27.         new tmp = 2;
  28.         year = 1970;
  29.         month = 1;
  30.         Timestamp -= 172800;
  31.         for(;;)
  32.         {
  33.                 if(Timestamp >= 31536000)
  34.                 {
  35.                         year ++;
  36.                         Timestamp -= 31536000;
  37.                         tmp ++;
  38.                         if(tmp == 4)
  39.                         {
  40.                                 if(Timestamp >= 31622400)
  41.                                 {
  42.                                         tmp = 0;
  43.                                         year ++;
  44.                                         Timestamp -= 31622400;
  45.                                 }
  46.                                 else break;
  47.                         }
  48.                 }
  49.                 else break;
  50.         }              
  51.         for(new i = 0; i < 12; i ++)
  52.         {
  53.                 if(Timestamp >= MonthTimes[i][2 + IsLeapYear(year)])
  54.                 {
  55.                         month ++;
  56.                         Timestamp -= MonthTimes[i][2 + IsLeapYear(year)];
  57.                 }
  58.                 else break;
  59.         }
  60.         day = 1 + (Timestamp / 86400);
  61.         Timestamp %= 86400;
  62.         hour = HourGMT + (Timestamp / 3600);
  63.         Timestamp %= 3600;
  64.         minute = MinuteGMT + (Timestamp / 60);
  65.         second = (Timestamp % 60);
  66.         if(minute > 59)
  67.         {
  68.                 minute = 0;
  69.                 hour ++;
  70.         }
  71.         if(hour > 23)
  72.         {
  73.                 hour -= 24;
  74.                 day ++;
  75.         }      
  76.         if(day > MonthTimes[month][IsLeapYear(year)])
  77.         {
  78.                 day = 1;
  79.                 month ++;
  80.         }
  81.         if(month > 12)
  82.         {
  83.                 month = 1;
  84.                 year ++;
  85.         }
  86.         return 1;
  87. }
  88.  
  89. stock DateToTimestamp(str[11])
  90. {
  91.         new date[3];
  92.         if(!sscanf(str,"p<"#SPLITTER">ddd",date[0],date[1],date[2]))
  93.         {
  94.                 new total = 0, tmp = 0;
  95.                 total += date[0] * 86400;
  96.                 if(date[1] == 2 && date[0] < 29) tmp = ((date[2] - 1968) / 4 - 2);
  97.                 else tmp = ((date[2] - 1968) / 4 - 1);
  98.                 total += tmp * 31622400;
  99.                 total += (date[2] - 1970 - tmp) * 31536000;
  100.                 for(new i = 1; i < date[1]; i ++) total += MonthTimes[i][0 + IsLeapYear(date[2])] * 86400;
  101.                 return total;
  102.         }
  103.         else return -1;
  104. }
  105. stock GetFormattedDate(timestamp)
  106. {
  107.     new year, month, day, hour, minute, second, dest[40];
  108.     TimestampToDate(timestamp, year, month, day, hour, minute, second, 1, 0);
  109.     format(dest, sizeof(dest), "%02d.%02d.%d %02d:%02d:%02d", day, month, year, hour, minute, second);
  110.     return dest;
  111. }
  112.  
  113. stock GetRelativeDate(timestamp)
  114. {
  115.     new dest[40];
  116.     if(timestamp == 0) return format(dest, sizeof(dest), "Nigdy"), dest;
  117.     else
  118.     {
  119.         new year, month, day, hour, minute, second, t_year, t_month, t_day, t_hour, t_minute, t_second;
  120.         TimestampToDate(timestamp, t_year, t_month, t_day, t_hour, t_minute, t_second, 1, 0);
  121.         TimestampToDate(gettime(), year, month, day, hour, minute, second, 1, 0);
  122.         if(t_year == year && t_month == month && t_day == day) return format(dest, sizeof(dest), "dziś, %02d:%02d", t_hour, t_minute), dest;
  123.         TimestampToDate(gettime()-86400, year, month, day, hour, minute, second, 1, 0);
  124.         if(t_year == year && t_month == month && t_day == day) return format(dest, sizeof(dest), "wczoraj, %02d:%02d", t_hour, t_minute), dest;
  125.         return format(dest, sizeof(dest), "%02d.%02d.%02d, %02d:%02d", t_day, t_month, t_year, t_hour, t_minute),  dest;
  126.     }
  127. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top