Lenin_Daniel

strftime

Dec 10th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 20.64 KB | None | 0 0
  1. #if defined STRFTIME_V1
  2. ********************************************************************************
  3. *            STRFTIME EMULATOR V0.1 BY  DANIEL-92   12/07/2011                 *
  4. *         Copyright © 2011 [Daniel-92 / [92]Daniel / (=Maxell=)]               *
  5. *              This file is provided as is (no warranties).                    *
  6. ********************************************************************************
  7.  
  8. native strftime(format[],dest[],length = sizeof(dest));
  9. native getweek(day,month,year);
  10. native ToString(value);
  11. native yearday(day,month,year);
  12. native IsLeapYear(year);
  13. native weekday(day, month, year);
  14. native AddDay(new_days=1,day=0,month=0,year=0);
  15. native GetDateByYearDay(_yearday,year=0);
  16. native GetDateFormat(pos_1,pos_2 = 0,pos_3 = 0);
  17. native GetTimeFormat(bool:12_hours = false);
  18. #endif
  19.  
  20. #if !defined _samp_included
  21.     #include a_samp
  22. #endif
  23. #if !defined IsLeapYear
  24.     #define IsLeapYear(%1) ((%1 % 4 == 0 && %1 % 100 != 0) || %1 % 400 == 0)
  25. #endif
  26.  
  27. #if defined STRF_TIME_DEBUG
  28.     #define DEBUG printf("CASE = %%%c",formato[i]);
  29. #else
  30.     #define DEBUG
  31. #endif
  32.  
  33. new const month_n[][] = {
  34.     "Ene""Enero",
  35.     "Feb""Febrero",
  36.     "Mar""Marzo",
  37.     "Abr""Abril",
  38.     "May""Mayo",
  39.     "Jun""Junio",
  40.     "Jul""Julio",
  41.     "Ago""Agosto",
  42.     "Sep""Septiembre",
  43.     "Oct""Octubre",
  44.     "Nov""Noviembre",
  45.     "Dic""Diciembre"
  46. };
  47.  
  48. new const days_n[][] = {
  49.     "Sab",  "Sábado",
  50.     "Dom",  "Domingo",
  51.     "Lun",  "Lunes",
  52.     "Mar",  "Martes",
  53.     "Mier", "Miercoles",
  54.     "Juv",  "Jueves",
  55.     "Vier", "Viernes"
  56. };
  57.  
  58. /*------------------------------------------------------------------------------
  59.  * Función strftime(formato[],dest[],length) by Daniel-92 (inspirada en la libreria ctime de c++)
  60.  * Parámetros
  61.  * formato  = Cadena de texto a formatear con los especificadores
  62.  * dest     = Salida de la cadena de texto formateada y procesada
  63.  * length   = Tamaño de la cadena de salida
  64.  */
  65. stock strftime(formato[],dest[],length = sizeof(dest),n_day=0,n_month=0,n_year=0)
  66. {
  67.     new
  68.         len = strlen(formato),
  69.         last_pos = 0,
  70.         time[3],
  71.         date[3];
  72.  
  73.     if(!len || !length) return 0;
  74.  
  75.     gettime(time[0],time[1],time[2]);
  76.     if(n_day==0 || n_month==0 || n_year==0) {
  77.         getdate(date[0],date[1],date[2]);
  78.     }
  79.     else {
  80.         date[2] = n_day;
  81.         date[1] = n_month;
  82.         date[0] = n_year;
  83.     }
  84.     for(new i=0; i < length; i++) {
  85.         dest[i] = EOS;
  86.     }
  87.     for(new i=0; i < len; i++) {
  88.         if(formato[i] == '%') {
  89.             if(formato[++i] == '\0' || formato[i] == '\1' || last_pos >= length) {
  90.                 break;
  91.             }
  92.             switch(formato[i]) {
  93.                 case '%': {//%% Es reemplazado por %
  94.                     strins(dest,"%",last_pos++,length);
  95.                 }
  96.                 case 'a': {// %a Es reemplazado por la abreviatura del nombre del día de la semana de la localidad
  97.                     strins(dest,days_n[weekday(date[2],date[1],date[0])*2],last_pos,length);
  98.                     last_pos = strlen(dest);
  99.                 }
  100.                 case 'A': {//%A Es reemplazado por el nombre completo del día de la semana de la localidad
  101.                     strins(dest,days_n[(weekday(date[2],date[1],date[0])*2)+1],last_pos,length);
  102.                     last_pos = strlen(dest);
  103.                 }
  104.                 case 'b': {//%b Es reemplazado por la abreviatura del nombre del mes de la localidad
  105.                     DEBUG
  106.                     strins(dest,month_n[(date[1]-1)*2],last_pos,length);
  107.                     last_pos  = strlen(dest);
  108.                 }
  109.                 case 'B': {//%B Es reemplazado por el nombre completo del mes de la localidad
  110.                     DEBUG
  111.                     strins(dest,month_n[((date[1]-1)*2)+1],last_pos,length);
  112.                     last_pos = strlen(dest);
  113.                 }
  114.                 case 'c': {//%c Es reemplazado por la fecha apropiada y la representación de la hora de la localidad "10/10/11 10:08:53"
  115.                     DEBUG  //pawn no pude obtener la representación adecuada (se toma por defecto %d/%m/%y %H:%M:%S)
  116.                     new dh_format[32],date_[3];
  117.                     strmid(date_,ToString(date[0],2),2,4);
  118.                     format(dh_format,sizeof(dh_format),"%02d/%02d/%02d %02d:%02d:%02d",date[2],date[1],strval(date_),time[0],time[1],time[2]);
  119.                     strins(dest,dh_format,last_pos,length);
  120.                     last_pos = strlen(dest);
  121.                 }
  122.                 case 'C': {//%C Es remplazado por el siglo como un número decimal
  123.                     DEBUG
  124.                     strins(dest,ToString(floatround(floatdiv(date[0],100)),2),last_pos,length);
  125.                     last_pos = strlen(dest);
  126.  
  127.                 }
  128.                 case 'd': {//%d Es reemplazado por el día del mes como un número decimal (01-31)
  129.                     DEBUG
  130.                     strins(dest,ToString(date[2],2),last_pos,length);
  131.                     last_pos = strlen(dest);
  132.                 }
  133.                 case 'F': {//%x Es reemplazado por la fecha en formato año-mes-dia %Y-%m-%d (normalmente usado en las bases de datos)
  134.                     DEBUG  
  135.                     new d_format[16];
  136.                     format(d_format,sizeof(d_format),"%04d-%02d-%02d",date[0],date[1],date[2]);
  137.                     strins(dest,d_format,last_pos,length);
  138.                     last_pos = strlen(dest);
  139.                 }
  140.                 case 'H': {//%H Es reemplazado por la hora (reloj de 24 horas) como un número decimal (00-23)
  141.                     DEBUG
  142.                     strins(dest,ToString(time[0],2),last_pos,length);
  143.                     last_pos = strlen(dest);
  144.                 }
  145.                 case 'I': {//%I Es reemplazado por la hora (reloj de 12 horas) como un número decimal (01-12)
  146.                     DEBUG
  147.                     strins(dest,ToString(time[0] > 12 ? (time[0]-12):time[0],2),last_pos,length);
  148.                     last_pos = strlen(dest);
  149.                 }
  150.                 case 'j': {//%j Es reemplazado por el día del año como un número decimal (001-366)
  151.                     strins(dest,ToString(yearday(date[2],date[1],date[0]),2),last_pos,length);
  152.                     last_pos = strlen(dest);
  153.                 }
  154.                 case 'm': {//%m Es reemplazado por el mes como un número decimal (01-12)
  155.                     DEBUG
  156.                     strins(dest,ToString(date[1],2),last_pos,length);
  157.                     last_pos = strlen(dest);
  158.                 }
  159.                 case 'M': {//%M Es reemplazado por el minuto como un número decimal (00-59)
  160.                     DEBUG
  161.                     strins(dest,ToString(time[1],2),last_pos,length);
  162.                     last_pos = strlen(dest);
  163.                 }
  164.                 case 'p': {//%p Es reemplazado por el equivalente de la localidad de las designaciones de AM/PM en mayúsculas asociadas con un reloj de 12 horas
  165.                     DEBUG
  166.                     strins(dest,time[0] >= 12 ? ("PM"):("AM"),last_pos,length);
  167.                     last_pos = strlen(dest);
  168.                 }
  169.                 case 'P': {//%p Es reemplazado por el equivalente de la localidad de las designaciones de AM/PM en minúsculas asociadas con un reloj de 12 horas
  170.                     DEBUG
  171.                     strins(dest,time[0] >= 12 ? ("pm"):("am"),last_pos,length);
  172.                     last_pos = strlen(dest);
  173.                 }
  174.                 case 'r': {//%x Es reemplazado por la hora minutos y segundos como un reloj de 12 horas especificando AM/PM, lo mismo que usar (%I:%M:%S %p)
  175.                     DEBUG
  176.                     new h_format[16];
  177.                     format(h_format,sizeof(h_format),"%02d:%02d:%02d %s",time[0] > 12 ? (time[0]-12):(time[0]),time[1],time[2],time[0]<12 ? ("AM"):("PM"));
  178.                     strins(dest,h_format,last_pos,length);
  179.                     last_pos = strlen(dest);
  180.                 }
  181.                 case 'R': {//%r Es reemplazado por la hora minutos y segundos como un reloj de 24 horas sin segundos, lo mismo que usar (%H:%M)
  182.                     DEBUG
  183.                     new h_format[16];
  184.                     format(h_format,sizeof(h_format),"%02d:%02d",time[0],time[1]);
  185.                     strins(dest,h_format,last_pos,length);
  186.                     last_pos = strlen(dest);
  187.                 }
  188.                 case 'S': {//%S Es reemplazado por el segundo como un número decimal (00-61)
  189.                     DEBUG
  190.                     strins(dest,ToString(time[2],2),last_pos,length);
  191.                     last_pos = strlen(dest);
  192.                 }
  193.                 case 'U': {//%W Es reemplazado por el número de la semana del año (el primer Domingo como el primer día de la semana 1) como un número decimal (00-53)
  194.                     DEBUG
  195.                     strins(dest,ToString(getweek(date[2],date[1],date[0],2),2),last_pos,length);
  196.                     last_pos = strlen(dest);
  197.                 }
  198.                 case 'W': {//%W Es reemplazado por el número de la semana del año (el primer Lunes como el primer día de la semana 1) como un número decimal (00-53)
  199.                     DEBUG
  200.                     strins(dest,ToString(getweek(date[2],date[1],date[0],3),2),last_pos,length);
  201.                     last_pos = strlen(dest);
  202.                 }
  203.                 case 'w': {//%w Es reemplazado por el día de la semana como un número decimal (0-6), donde Domingo es 0
  204.                     DEBUG
  205.                     new day = weekday(date[2],date[1],date[0]);
  206.                     strins(dest,ToString(day ? (day-1):(6),2),last_pos,length);
  207.                     last_pos = strlen(dest);
  208.                 }
  209.                 case 'x': {//%x Es reemplazado por la representación apropiada de la fecha de la localidad "10/10/11"
  210.                     DEBUG  //pawn no puede obtener la representación adecuada (se toma por defecto %d/%m/%y)
  211.                     new d_format[16],date_[3];
  212.                     strmid(date_,ToString(date[0],2),2,4);
  213.                     format(d_format,sizeof(d_format),"%02d/%02d/%02d",date[2],date[1],strval(date_));
  214.                     strins(dest,d_format,last_pos,length);
  215.                     last_pos = strlen(dest);
  216.                 }
  217.                 case 'X': {//%X Es reemplazado por la representación apropiada de la hora de la localidad   "10:08:53"
  218.                     DEBUG  //pawn no puede obtener la representación adecuada (se toma por defecto como un reloj de 24 horas lo mismo que usar %H:%M:%S)
  219.                     new h_format[16];
  220.                     format(h_format,sizeof(h_format),"%02d:%02d:%02d",time[0],time[1],time[2]);
  221.                     strins(dest,h_format,last_pos,length);
  222.                     last_pos = strlen(dest);
  223.                 }
  224.                 case 'y': {//%y Es reemplazado por el año sin siglo como un número decimal (00-99)
  225.                     DEBUG
  226.                     new date_[3];
  227.                     strmid(date_,ToString(date[0],2),2,4);
  228.                     strins(dest,date_,last_pos,length);
  229.                     last_pos = strlen(dest);
  230.                 }
  231.                 case 'Y': {//%Y Es reemplazado por el año con siglo como un número decimal (2012)
  232.                     DEBUG
  233.                     strins(dest,ToString(date[0],2),last_pos,length);
  234.                     last_pos = strlen(dest);
  235.                 }
  236.                 case 'Z': {//%Z Es reemplazado por el nombre o la abreviatura del uso horario si el uso horario es determinable
  237.                     DEBUG  //%Z no está soportado en esta versíón. (pawn no puede obtener el uso horario en su versión 3.2.3664)
  238.                     strins(dest,"-6 GTM",last_pos,length);
  239.                     last_pos = strlen(dest);
  240.                 }
  241.                 default: {
  242.                     continue;
  243.                 }
  244.             }
  245.         }
  246.         else {
  247.             dest[last_pos++] = formato[i];
  248.         }
  249.     }
  250.     return last_pos;
  251. }
  252.  
  253. /*------------------------------------------------------------------------------
  254.  *  ISO-8601 Week Number - V 1.1
  255.  *  Processes the week number of a date,
  256.  *
  257.  *  Procedure by Rick McCarty, 1999
  258.  *  Adapted to CVI by R.Bozzolo, 2006
  259.  *  Adapted to AS2/AS3 by A.Colonna, 2008
  260.  *  Adapted to Pawn by Daniel-92 2011
  261.  *
  262.  *  Retorna el número de la semana tomando first_day como el primer dia de la semana*/
  263.  
  264. stock getweek(day,month,year,firts_day)  { //
  265.     #pragma unused firts_day
  266.     new bool:isLeapYear = IsLeapYear(year)?(true):(false);
  267.  
  268.     new month_array[] = {0,31,59,90,120,151,181,212,243,273,304,334};
  269.     new DayOfYearNumber = day + month_array[month];
  270.     if(isLeapYear && month > 2 || month == 2 && day > 28)
  271.         DayOfYearNumber++;
  272.  
  273.     new YY = (year-1) % 100;
  274.     new C = (year-1) - YY;
  275.     new G = YY + YY / 4;
  276.     new Jan1Weekday = floatround(1 + (((((C / 100) % 4) * 5) + G) % 7),floatround_floor);
  277.  
  278.     new H = DayOfYearNumber + (Jan1Weekday - 1);
  279.     new Weekday = floatround(1 + ((H -1) % 7),floatround_floor);
  280.  
  281.     new YearNumber = year;
  282.     new WeekNumber;
  283.  
  284.     if(DayOfYearNumber <= (8 - Jan1Weekday) && Jan1Weekday > 4) {
  285.         YearNumber = year - 1;
  286.         if (Jan1Weekday == 5 || (Jan1Weekday == 6 && isLeapYear)) {
  287.             WeekNumber = 53;
  288.         }
  289.         else {
  290.             WeekNumber = 52;
  291.         }
  292.     }
  293.     if(YearNumber == year) {
  294.         new I = 365;
  295.         if (isLeapYear) {
  296.             I = 366;
  297.         }
  298.         if (I - DayOfYearNumber < 4 - Weekday) {
  299.             YearNumber = year + 1;
  300.             WeekNumber = 1;
  301.         }
  302.     }
  303.     if(YearNumber == year) {
  304.         new J = DayOfYearNumber + (7 - Weekday) + (Jan1Weekday -1);
  305.         WeekNumber = J / 7;
  306.         if (Jan1Weekday > 4) {
  307.             WeekNumber--;
  308.         }
  309.     }
  310.     return (WeekNumber - 4);
  311. }
  312. /*------------------------------------------------------------------------------
  313.  *  Función TosSting(value,zeros=0,type[] = "0") by Daniel-92
  314.  *  Convierte un número entero a un número en forma de string
  315.  *  Parámetros
  316.  *  value = Número entero que se quiera convertir
  317.  *  zeros = Dígitos que serán comprobados
  318.  *  type  = Caracter que sera insertado si el valor no alcanza los digitos especificados en el parámetro zeros
  319.  *  Ejemplo: ToString(6,3," ") Retornará "  6" */
  320.  
  321. #define MAX_INTEGER_LEN 32
  322. stock ToString(value,zeros = 0,type[]="0") {
  323.     new
  324.         result[MAX_INTEGER_LEN],
  325.         pos = 0;
  326.     if(zeros > 0) {
  327.         new temp[MAX_INTEGER_LEN];
  328.         valstr(temp,value);
  329.         new len = strlen(temp);
  330.         for(new i = 0; i < zeros; i++) {
  331.             strcat(result,type);
  332.         }
  333.         pos = zeros - len;
  334.         if(pos < 0) {
  335.             pos = 0;
  336.         }
  337.         for(new i=0; i < len; i++) {
  338.             result[pos+i] = temp[i];
  339.         }
  340.     }
  341.     else {
  342.         valstr(result,value);
  343.     }
  344.     return result;
  345. }
  346.  
  347. /*------------------------------------------------------------------------------
  348.  * Función yearday(day,month,year) by Daniel-92
  349.  * Parámetros
  350.  * day      = dia del mes
  351.  * month    = mes
  352.  * year     = año
  353.  * Returns  = dia del año (1-365 o hasta 366 si el año es biciesto) */
  354.  
  355. stock yearday(day,month,year) {
  356.     new         //1  2  3  4  5  6  7  8  9 10 11 12
  357.         days[] = {31,0,31,30,31,30,31,31,30,31,30,31},
  358.         output = 0;
  359.     days[1] = IsLeapYear(year)?(29):(28);
  360.     for(new i=0; i < month-1; i++) {
  361.         output += days[i];
  362.     }
  363.     return output + day;
  364. }
  365.  
  366. /*------------------------------------------------------------------------------
  367.  * Función IsLeapYear(year) (Popular en intenet fuente desconocida)
  368.  * Parámetros
  369.  * year = año
  370.  * Returns: verdadero si el año es biciesto de lo contrario retornará falso */
  371.  
  372. #if !defined IsLeapYear
  373. stock IsLeapYear(year) {
  374.     return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
  375. }
  376. #endif
  377.  
  378. /*------------------------------------------------------------------------------
  379.  * Función weekday(day, month, year) By ITB CompuPhase (script weekday.pwn)
  380.  * Parámetros
  381.  * day  = dia
  382.  * month= mes
  383.  * year = año
  384.  * Returns: Retorna el dia de la semana como un número decimal (0-6) donde 0 es Domingo */
  385.  
  386. stock weekday(day, month, year) {
  387.     if (month <= 2) {
  388.         month += 12, --year;
  389.     }
  390.     new j = year % 100;
  391.     new e = year / 100;
  392.     return (day + (month+1)*26/10 + j + j/4 + e/4 - 2*e) % 7;
  393. }
  394.  
  395. /*------------------------------------------------------------------------------
  396.  * Funcion AddDay(new_days, day, month, year) by Daniel-92
  397.  * Parámetros
  398.  * new_days = dias que se le agregarán a una fecha
  399.  * day      = dia desde el cual se empezaran a sumar los dias.
  400.  * month    = mes desde el cual se empezaran a sumar los dias.
  401.  * year     = año desde el cual se empezaran a sumar los dias.
  402.  * returns: Retorna la nueva fecha como un array
  403.             array[0] = retorna el dia.
  404.             array[1] = retorna el mes.
  405.             array[0] = retorna el año.
  406.            
  407.  *Notas:    - La función SOLO FUNCIONA PARA AGREGAR DIAS POSITIVOS
  408.             - Los paramtros day, month y year son opcionales si no se colocan
  409.               la función tomará la fecha local como punto de partida.
  410.  */
  411. stock AddDay(new_days=1,day=0,month=0,year=0) {
  412.     if(day == 0 && month == 0 && year == 0) {
  413.         getdate(year,month,day);
  414.     }
  415.     new date[3],leapyear = IsLeapYear(year);
  416.     new days = yearday(day,month,year)+new_days;
  417.     if(days > 0) {
  418.         if(days <= (leapyear ? 366 : 365)) {
  419.             date = GetDateByYearDay(days,year);
  420.         }
  421.         else {
  422.             new total_days = 0;
  423.             while(total_days < days) {
  424.                 total_days += IsLeapYear(year) ? 366 : 365;
  425.                 year++;
  426.             }
  427.             year = year - 1;
  428.             days = total_days-days;
  429.             date = GetDateByYearDay((IsLeapYear(year) ? 366 : 365) - days,year);
  430.         }
  431.     }
  432.     return date;
  433. }
  434.  
  435. /* -----------------------------------------------------------------------------
  436.  * Funcion GetDateByYearDay by Daniel-92
  437.  * Parámetros
  438.  * _yearday = dia del año (0-365 o 0-366 si el año es biciesto)
  439.  * year     = año al cual se le quiere sacar la fecha
  440.  * Returns: Retorna la fecha según el dia del año que se ha pasado en los parámetros.
  441.             array[0] = retorna el dia.
  442.             array[1] = retorna el mes.
  443.             array[0] = retorna el año.
  444.   */
  445. stock GetDateByYearDay(_yearday,year=0) {
  446.     new         //1  2  3  4  5  6  7  8  9 10 11 12
  447.         days[] = {31,0,31,30,31,30,31,31,30,31,30,31},
  448.         date[] = {0 ,0, 0};
  449.     if(!year) getdate(year);
  450.     days[1] = IsLeapYear(year)?(29):(28);
  451.     for(new i=0,j,t_days; i < 12; i++) {
  452.         for(j=0; j < days[i]; j++) {
  453.             if(++t_days == _yearday) {
  454.                 date[0] = j+1;
  455.                 date[1] = i+1;
  456.                 date[2] = year;
  457.                 return date;
  458.             }
  459.         }
  460.     }
  461.     return date;
  462. }
  463. /*------------------------------------------------------------------------------
  464.  * Función GetDateFormat(parametros_1,parametro_2,parametro_3) by Daniel-92
  465.  * Parámetros
  466.  * 3 parámetros donde se pueden asignar 4 tipos de valores ('d','m','y',0)
  467.  * 'd' = devuelve el dia como un número decimal (1- (28,29,30,31))
  468.  * 'm' = devuelve el mes como un número decimal (1-12)
  469.  * 'y' = devuelve el año como un número decimal con siglo (2012)
  470.  ' 0   = no devuelve nada, se usa para retornar solamente 1 o 2 valores
  471.          GetDateFormat('d','0','0') retornará solamente el dia, sin embargo el especificador 0
  472.          es asignado internamente por la función cuando no se especifican los 3 parámetros
  473.          y no es necesario usarlo, pudiendose usar GetDateFormat('d') que seria lo mismo que GetDateFormat('d','0','0')
  474.  * Returns: (string) de fecha formateada por los parámetros de la función */
  475.  
  476.  
  477. stock GetDateFormat(pos_1,pos_2 = 0,pos_3 = 0) {
  478.     new
  479.         string_result[16],
  480.         value[4];
  481.     getdate(value[0],value[1],value[2]);
  482.     for(new i=0; i < 3; i++) {
  483.         if(!i) value[3] = pos_1; else if(i == 1) value[3] = pos_2; else value[3] = pos_3;
  484.         switch(value[3]) {
  485.             case 'y': strcat(string_result,ToString(value[0],2));
  486.             case 'm': strcat(string_result,ToString(value[1],2));
  487.             case 'd': strcat(string_result,ToString(value[2],2));
  488.         }
  489.         strcat(string_result,"-");
  490.     }
  491.     string_result[strlen(string_result)-1] = EOS;
  492.     return string_result;
  493. }
  494.  
  495. /*------------------------------------------------------------------------------
  496.  * GetTimeFormat(12_hours)  by Daniel-92
  497.  * Parámetros
  498.  * 12_hours = parametro opcional (true: devuelve la hora en formato H:M:S PM/AM)
  499.  * Returns: (string) Devuelve la hora con minutos y segundos como reloj de 24 horas
  500.             si se especifica el parámeto 12_hours como "true" devuelve la hora en
  501.             formato de 12 horas*/
  502.  
  503. stock GetTimeFormat(hours_12 = false) {
  504.     new hour,minute,secound,tiempo[16];
  505.     gettime(hour,minute,secound);
  506.     if(!hours_12) {
  507.         strcat(tiempo,ToString(hour,2));
  508.         strcat(tiempo,":");
  509.         strcat(tiempo,ToString(minute,2));
  510.         strcat(tiempo,":");
  511.         strcat(tiempo,ToString(secound,2));
  512.         //format(tiempo,sizeof(tiempo),"%02d:%02d:%02d",hour,minute,secound);
  513.     }
  514.     else {
  515.         new am = true;
  516.         if(hour >= 12) {
  517.              am = false;
  518.              if(hour != 12)
  519.                 hour = hour - 12;
  520.         }
  521.         else if(hour == 0) hour = 12;
  522.         strcat(tiempo,ToString(hour,2));
  523.         strcat(tiempo,":");
  524.         strcat(tiempo,ToString(minute,2));
  525.         strcat(tiempo,":");
  526.         strcat(tiempo,ToString(secound,2));
  527.         strcat(tiempo,(am)?(" AM"):(" PM"));
  528.         //format(tiempo,sizeof(tiempo),"%02d:%02d:%02d %s",hour,minute,secound,(am)?("AM"):("PM"));
  529.     }
  530.     return tiempo;
  531. }
  532.  
  533. #tryinclude getparams
  534.  
  535. #if defined _getparams_included
  536. /* Funcion DiferenciaFecha(date_1[],date_[]) by Daniel-92
  537.  * Parametros
  538.  * date_1[] - Primera fecha ala que se le restará la fecha 2
  539.  * date_2[] - segunda fecha que le resta a la primera fecha
  540.  * returns  - Diferencia en dias entre la primera fecha y la segunda fecha
  541.  * Ejemplo  - DiferenciaFecha("10/09/2011","10/12/11");
  542. */
  543.     stock DiferenciaFecha(date_1[],date_2[],separator = '/') {//By Lenin Ruiz
  544.         new
  545.             index[] = {0,1},
  546.             date[3][2],
  547.             days;
  548.  
  549.         GetParamsUseIndex(true);
  550.         GetParamsInt(date_1,1,date[0][index[0]],separator);
  551.         GetParamsInt(date_1,2,date[1][index[0]],separator,true);
  552.         GetParamsInt(date_1,3,date[2][index[0]],separator,true);
  553.         GetParamsInt(date_2,1,date[0][index[1]],separator,true);
  554.         GetParamsInt(date_2,2,date[1][index[1]],separator,true);
  555.         GetParamsInt(date_2,3,date[2][index[1]],separator,true);
  556.         GetParamsUseIndex(false);
  557.        
  558.         if(date[2][0]!=date[2][1]) {
  559.             if(date[2][0]>date[2][1]) {
  560.                 index[0] = 1;
  561.                 index[1] = 0;
  562.             }
  563.             for(new i=date[2][index[0]]; i<=date[2][index[1]]; i++) {
  564.                 switch(i==date[2][index[1]]) {
  565.                     case true:  days+=yearday(date[0][index[1]],date[1][index[1]],date[2][index[1]]);
  566.                     case false: days+=(IsLeapYear(i))?(366):365;
  567.                 }
  568.             }
  569.             return !index[0]?(days-yearday(date[0][index[0]],date[1][index[0]],date[2][index[0]])):
  570.                             -(days-yearday(date[0][index[0]],date[1][index[0]],date[2][index[0]]));
  571.         }
  572.         return  yearday(date[0][index[1]],date[1][index[1]],date[2][index[1]])
  573.                -yearday(date[0][index[0]],date[1][index[0]],date[2][index[0]]);
  574.     }
  575. #endif
Advertisement
Add Comment
Please, Sign In to add comment