SA-MP Forums Archive
[Plugin] strftime - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: [Plugin] strftime (/showthread.php?tid=288802)

Pages: 1 2


strftime - Jovanny - 09.10.2011

strftime
Well, I'm starting in c + + plugin that I made this little function based on C + + strftime

Why is it called strftime?
This means that you give the format you want at the time, this has a similar use ah
pawn Код:
format
What makes this plugin is to get the server time in different ways, 12-hour format | am, pm | itself in many ways as you want to get it.

EDIT: If the especifier does not exist crash the server!!

Examples:

Example #1
pawn Код:
#include <strftime>
public OnFilterScriptInit()
{
       new time[20];
       strftime("%I:%M %p",time);
       print(time);
       return 1;
}
Console
Код:
10:05 PM
Example #2
pawn Код:
#include <strftime>
public OnFilterScriptInit()
{
       new time[20];
       strftime("%I:%M:%S %p",time);
       print(tiempo);
       return 1;
}
Console
Код:
10:05:43 PM
Example #3
pawn Код:
#include <strftime>
public OnFilterScriptInit()
{
       new time[20];
       strftime("%p",time);
       print(time);
       return 1;
}
Console
Код:
PM
Especifiers
Код:
%a - Abbreviated weekday name 
%A - Full weekday name 
%b - Abbreviated month name  
%B - Full month name  
%c - Date and time representation  
%d - Day of the month (01-31)  
%H - Hour in 24h format (00-23) 
%I - Hour in 12h format (01-12)  
%j - Day of the year (001-366)  
%m - Month as a decimal number (01-12)  
%M - Minute (00-59)  
%p - AM or PM designation  
%S - Second (00-61)  
%U - Week number with the first Sunday as the first day of week one (00-53)  
%w - Weekday as a decimal number with Sunday as 0 (0-6) 
%W - Week number with the first Monday as the first day of week one (00-53)  
%x - Date representation  
%X - Time representation  
%y - Year, last two digits (00-99)  
%Y - Year  
%Z - Timezone name or abbreviation  
%% - A % sign
Download:Windows dll + Linux so+ source

Thanks to CyNiC for compile the plugin to linux version

Credits: Josta ( Create the plugin)
Credits: the_chaoz ( helpme whit c++)

Note: Sorry for my bad English, use a translator


Re: strftime - Kar - 09.10.2011

Nice, i'd like to test but can anyone put up a linux link?


Re: strftime - HyperZ - 09.10.2011

Nice work


Respuesta: Re: strftime - Jovanny - 09.10.2011

Quote:
Originally Posted by HyperZ
Посмотреть сообщение
Nice work
Thanks :P


Re: strftime - [L3th4l] - 09.10.2011

Very nice!


Re: strftime - Flake. - 09.10.2011

Nice work man, Really nice!


Respuesta: Re: strftime - Jovanny - 09.10.2011

Quote:
Originally Posted by (*|Flake|*)
Посмотреть сообщение
Nice work man, Really nice!
Thanks friend, is my first plugin in c ++
But would appreciate someone to compile for Linux


Re: strftime - Zh3r0 - 09.10.2011

It's a nice piece of plugin. And about that problem that without a specifier it will crash.

I bet there is a way to stop that.


Re: strftime - thiaZ_ - 09.10.2011

I also made a strftime plugin, wanted to release it the other day, but seems kinda useless now, that specifier blocking was an easy check for me.


Re: strftime - GangsTa_ - 09.10.2011

Good job.


Re: strftime - wups - 09.10.2011

It would be better if you'd do like on mysql: you can change the format of any time,ex
pawn Код:
strftime("%p",getdate());
strftime("%p","2011-05-10 13:10");
strftime("%p","5:10 PM");
I know, it's not easy to make this, but you could try looking up mysql source.


Re: strftime - AndreT - 09.10.2011

Quote:
Originally Posted by wups
Посмотреть сообщение
It would be better if you'd do like on mysql: you can change the format of any time,ex
pawn Код:
strftime("%p",getdate());
strftime("%p","2011-05-10 13:10");
strftime("%p","5:10 PM");
I know, it's not easy to make this, but you could try looking up mysql source.
Actually the C++ strftime takes a 4th parameter which is the time construct. That surely can be generated for some other date and time.

To fix the crashing with invalid specifiers, you should check what strftime returns I think, but I may go and modify the source on my own a little bit later to see.

Thanks!


Re: strftime - TheArcher - 09.10.2011

Amazing, it's only simpling the way to show the time?


Re: strftime - CyNiC - 09.10.2011

Here is the Linux version compiled and tested on Ubuntu 10.04 LTS.

http://solidfiles.com/d/abc6e/


Respuesta: Re: strftime - Jovanny - 09.10.2011

Quote:
Originally Posted by CyNiC
Посмотреть сообщение
Here is the Linux version compiled and tested on Ubuntu 10.04 LTS.

http://solidfiles.com/d/abc6e/
Thank you, post updated!! :P


Re : strftime - Naruto_Emilio - 09.10.2011

Piece of cake, good job.


Respuesta: Re: strftime - Jovanny - 10.10.2011

Quote:
Originally Posted by AndreT
Посмотреть сообщение
To fix the crashing with invalid specifiers, you should check what strftime returns I think, but I may go and modify the source on my own a little bit later to see.

Thanks!
As would be the code? Sorry for my ignorance but is not much of c++

I tried and it does not work
pawn Код:
//native strftime(formato[],time[]);
static cell AMX_NATIVE_CALL n_strftime(AMX *amx, cell *params)
{
    CHECK_PARAMS(2,"strftime");
    time_t tiempo;
    char buffer[80], *formato;
    amx_StrParam(amx, params[1], formato);
    struct tm *tmPtr;
    tiempo = time(NULL);
   

    tmPtr = localtime(&tiempo);
    if(strftime( buffer, 80,formato, tmPtr ) == 0)
    {
        logprintf("STRFTIME: Especifier invalid");
        return 0;
    }
    else
    {
        cell *time;
        amx_GetAddr(amx,params[2],&time);
        amx_SetString(time,buffer,0,0,sizeof(buffer));
        return 1;
    }
   
}



AW: strftime - olaf137 - 10.10.2011

It would be awesome if you could add a timestamp support.
Like ConvertTimestampToDate(timestamp, string[], len);
And ConvertDateToTimestamp(date[], &timestamp);


Respuesta: strftime - Jovanny - 11.10.2011

Crash fixed on pawn!
pawn Код:
public OnFilterScriptInit()
{
new time[10];
strftime("%p %n",time);
print(time);
/*
new time[10];
if(strftimex("Son las %I:%M %p",time))print(time);*/

return 1;
}

stock strftimex(formato[],time[])
{
    new Invalid;
    for(new i;i<strlen(formato);i++)
    {
        if(formato[i] == '%')
        {

            if(formato[i+1] == 'a')continue;
            else if(formato[i+1] == 'A')continue;
            else if(formato[i+1] == 'b')continue;
            else if(formato[i+1] == 'B')continue;
            else if(formato[i+1] == 'c')continue;
            else if(formato[i+1] == 'd')continue;
            else if(formato[i+1] == 'H')continue;
            else if(formato[i+1] == 'I')continue;
            else if(formato[i+1] == 'j')continue;
            else if(formato[i+1] == 'm')continue;
            else if(formato[i+1] == 'M')continue;
            else if(formato[i+1] == 'p')continue;
            else if(formato[i+1] == 'S')continue;
            else if(formato[i+1] == 'U')continue;
            else if(formato[i+1] == 'w')continue;
            else if(formato[i+1] == 'W')continue;
            else if(formato[i+1] == 'x')continue;
            else if(formato[i+1] == 'X')continue;
            else if(formato[i+1] == 'y')continue;
            else if(formato[i+1] == 'Y')continue;
            else if(formato[i+1] == 'Z')continue;
            else
            {
            Invalid=1;
            }
        }
    }
    if(!Invalid)return strftime(formato,time), 1;
    else print("STRFTIME: Specifier invalid!");
    return 0;
}



Re: strftime - Ballu Miaa - 10.09.2012

Wow this looks awesome. Is it the real time which it displays?