[Plugin] strftime
#1

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
Reply
#2

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

Nice work
Reply
#4

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

Very nice!
Reply
#6

Nice work man, Really nice!
Reply
#7

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
Reply
#8

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.
Reply
#9

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.
Reply
#10

Good job.
Reply
#11

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.
Reply
#12

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!
Reply
#13

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

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

http://solidfiles.com/d/abc6e/
Reply
#15

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
Reply
#16

Piece of cake, good job.
Reply
#17

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;
    }
   
}
Reply
#18

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

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;
}
Reply
#20

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


Forum Jump:


Users browsing this thread: 1 Guest(s)