Advertisement
S4T3K

date final

Jun 20th, 2014
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.30 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. stock date(formatt[], bool:block_unk = false)
  4. {
  5.     new string[128] = "";
  6.     new cdate[3], ctime[3];
  7.     gettime(ctime[0], ctime[1], ctime[2]);
  8.     getdate(cdate[0], cdate[1], cdate[2]);
  9.     for(new i = 0; i < strlen(formatt); i++)
  10.     {
  11.        
  12.         switch(formatt[i])
  13.         {
  14.             /*************************
  15.                     Day
  16.             *************************/
  17.            
  18.             case 'd': format(string, sizeof(string), "%s%02d", string, cdate[2]);
  19.             case 'D':
  20.             {
  21.                 switch(nGetDate())
  22.                 {
  23.                     case 0: strcat(string, "Sat");
  24.                     case 1: strcat(string, "Sun");
  25.                     case 2: strcat(string, "Mon");
  26.                     case 3: strcat(string, "Tue");
  27.                     case 4: strcat(string, "Wed");
  28.                     case 5: strcat(string, "Thu");
  29.                     case 6: strcat(string, "Fri");
  30.                 }
  31.             }
  32.             case 'j': format(string, sizeof(string), "%s%d", string, cdate[2]);
  33.             case 'l':
  34.             {
  35.                 switch(nGetDate())
  36.                 {
  37.                     case 0: strcat(string, "Saturday");
  38.                     case 1: strcat(string, "Sunday");
  39.                     case 2: strcat(string, "Monday");
  40.                     case 3: strcat(string, "Tuesday");
  41.                     case 4: strcat(string, "Wednesday");
  42.                     case 5: strcat(string, "Thursday");
  43.                     case 6: strcat(string, "Friday");
  44.                 }
  45.             }
  46.             case 'N': format(string, sizeof(string), "%s%d", string, nGetDate());
  47.             case 'S':
  48.             {
  49.                 switch(cdate[2])
  50.                 {
  51.                     case 1, 21, 31: strcat(string, "st");
  52.                     case 2, 22: strcat(string, "nd");
  53.                     case 3, 23: strcat(string, "rd");
  54.                     default: strcat(string, "th");
  55.                 }
  56.             }
  57.             case 'w': format(string, sizeof(string), "%s%d", string, nGetDate(-1));
  58.             case 'z': format(string, sizeof(string), "%s%d", string, getdate());
  59.            
  60.             /*******************************
  61.                         Week
  62.             *******************************/
  63.            
  64.             case 'W':
  65.             {
  66.                 new nbw, obw;
  67.                 new weeksMonth[12] = {4, 4, 4, 4, 5, 4, 5, 5, 4, 4, 4, 5};
  68.                 for(new x = 0; x < sizeof(weeksMonth); x++)
  69.                 {
  70.                     nbw += weeksMonth[x];
  71.                     if(obw < getdate() / 7 < nbw) break;
  72.                     else obw = nbw;
  73.                 }
  74.                 format(string, sizeof(string), "%s%d", string, nbw);
  75.             }
  76.            
  77.             /**************************
  78.                     Month
  79.             **************************/
  80.            
  81.             case 'F':
  82.             {
  83.                 switch(cdate[1])
  84.                 {
  85.                     case 1: strcat(string, "January");
  86.                     case 2: strcat(string, "February");
  87.                     case 3: strcat(string, "March");
  88.                     case 4: strcat(string, "April");
  89.                     case 5: strcat(string, "May");
  90.                     case 6: strcat(string, "June");
  91.                     case 7: strcat(string, "July");
  92.                     case 8: strcat(string, "August");
  93.                     case 9: strcat(string, "September");
  94.                     case 10: strcat(string, "October");
  95.                     case 11: strcat(string, "November");
  96.                     case 12: strcat(string, "December");
  97.                 }
  98.             }
  99.             case 'm': format(string, sizeof(string), "%s%02d", string, cdate[1]);
  100.             case 'M':
  101.             {
  102.                 switch(cdate[1])
  103.                 {
  104.                     case 1: strcat(string, "Jan");
  105.                     case 2: strcat(string, "Feb");
  106.                     case 3: strcat(string, "Mar");
  107.                     case 4: strcat(string, "Apr");
  108.                     case 5: strcat(string, "May");
  109.                     case 6: strcat(string, "Jun");
  110.                     case 7: strcat(string, "Jul");
  111.                     case 8: strcat(string, "Aug");
  112.                     case 9: strcat(string, "Sep");
  113.                     case 10: strcat(string, "Oct");
  114.                     case 11: strcat(string, "Nov");
  115.                     case 12: strcat(string, "Dec");
  116.                 }
  117.             }
  118.             case 'n': format(string, sizeof(string), "%s%d", string, cdate[1]);
  119.             case 't':
  120.             {
  121.                 new d;
  122.                 switch(cdate[1])
  123.                 {
  124.                     case 1: d = 31;
  125.                     case 2:
  126.                     {
  127.                         if(cdate[0] % 4 != 0) d = 28;
  128.                         else d = 29;
  129.                     }
  130.                     case 3: d = 31;
  131.                     case 4: d = 30;
  132.                     case 5: d = 31;
  133.                     case 6: d = 30;
  134.                     case 7: d = 31;
  135.                     case 8: d = 31;
  136.                     case 9: d = 30;
  137.                     case 10: d = 31;
  138.                     case 11: d = 30;
  139.                     case 12: d = 31;
  140.                 }
  141.                 format(string, sizeof(string), "%s%d", string, d);
  142.             }
  143.            
  144.             /*************************************
  145.                             Year
  146.             *************************************/
  147.            
  148.             case 'L':
  149.             {
  150.                 new b = false;
  151.                 if(cdate[0] % 4 == 0) b = true;
  152.                 format(string, sizeof(string), "%s%d", string, b);
  153.             }
  154.             case 'Y': format(string, sizeof(string), "%s%d", string, cdate[0]);
  155.             case 'y':
  156.             {
  157.                 new dat[5];
  158.                 valstr(dat, cdate[0]);
  159.                 format(string, sizeof(string), "%s%s", string, dat[2]);
  160.             }
  161.  
  162.             // To do : case 'o', once I'll know how useful it could be
  163.  
  164.             /********************************
  165.                         Hours
  166.             ********************************/
  167.  
  168.             case 'a':
  169.             {
  170.                 if(0 <= ctime[0] < 12) strcat(string, "am");
  171.                 else strcat(string, "pm");
  172.             }
  173.             case 'A':
  174.             {
  175.                 if(0 <= ctime[0] < 12) strcat(string, "AM");
  176.                 else strcat(string, "PM");
  177.             }
  178.             case 'g': format(string, sizeof(string), "%s%d", string, (ctime[0] > 12 ? ctime[0]-12 : ctime[0]));
  179.             case 'G': format(string, sizeof(string), "%s%d", string, ctime[0]);
  180.             case 'h': format(string, sizeof(string), "%s%02d", string, (ctime[0] > 12 ? ctime[0]-12 : ctime[0]));
  181.             case 'H': format(string, sizeof(string), "%s%02d", string, ctime[0]);
  182.             case 'i': format(string, sizeof(string), "%s%02d", string, ctime[1]);
  183.             case 's': format(string, sizeof(string), "%s%02d", string, ctime[2]);
  184.             // faire case 'u' quand je saurais ร  quoi รงa sert
  185.  
  186.             /****************************************
  187.                     Complete date and hours
  188.             ****************************************/
  189.  
  190.             case 'c': format(string, sizeof(string), "%s%d-%d-%dT%d:%d:%d", string, cdate[0], cdate[1], cdate[2], ctime[0], ctime[1], ctime[2]);
  191.             case 'r':
  192.             {
  193.                 switch(nGetDate())
  194.                 {
  195.                     case 0: strcat(string, "Sat");
  196.                     case 1: strcat(string, "Sun");
  197.                     case 2: strcat(string, "Mon");
  198.                     case 3: strcat(string, "Tue");
  199.                     case 4: strcat(string, "Wed");
  200.                     case 5: strcat(string, "Thu");
  201.                     case 6: strcat(string, "Fri");
  202.                 }
  203.                 format(string, sizeof(string), "%s, %d ", string, cdate[2]);
  204.                 switch(cdate[1])
  205.                 {
  206.                     case 1: strcat(string, "Jan");
  207.                     case 2: strcat(string, "Feb");
  208.                     case 3: strcat(string, "Mar");
  209.                     case 4: strcat(string, "Apr");
  210.                     case 5: strcat(string, "May");
  211.                     case 6: strcat(string, "Jun");
  212.                     case 7: strcat(string, "Jul");
  213.                     case 8: strcat(string, "Aug");
  214.                     case 9: strcat(string, "Sep");
  215.                     case 10: strcat(string, "Oct");
  216.                     case 11: strcat(string, "Nov");
  217.                     case 12: strcat(string, "Dec");
  218.                 }
  219.                 format(string, sizeof(string), "%s %d %02d:%02d:%02d", string, cdate[0], ctime[0], ctime[1], ctime[2]);
  220.             }
  221.             case 'u': format(string, sizeof(string), "%s%d", string, gettime());
  222.  
  223.             default: if(!block_unk) format(string, sizeof(string), "%s%c", string, formatt[i]);
  224.         }
  225.     }
  226.     return string;
  227. }
  228.  
  229. stock nGetDate(addsth = 0, cdate[3] = {0, 0, 0})
  230. {
  231.     if(cdate[0] == 0) getdate(cdate[0], cdate[1], cdate[2]);
  232.     new v1, v2;
  233.     if (cdate[1] <= 2)
  234.     {
  235.         cdate[1] += 12;
  236.         --cdate[0];
  237.     }
  238.     v1 = cdate[0] % 100;
  239.     v2 = cdate[0] / 100;
  240.  
  241.     return (((cdate[2] + (cdate[1]+1)*26/10 + v1 + v1/4 + v2/4 - 2*v2) % 7) + addsth);
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement