Problem with timestamp.
#1

Hello !

In my script, if I use the TimestampToDate function for command, the command return "Unknown command".

pawn Код:
stock TimestampToDate(Timestamp, &year, &month, &day, &hour, &minute, &second, HourGMT, MinuteGMT = 0)
{
    new tmp = 2;
    year = 1970;
    month = 1;
    Timestamp -= 172800; // Delete two days from the current timestamp. This is necessary, because the timestamp retrieved using gettime() includes two too many days.
    for(;;)
    {
        if(Timestamp >= 31536000)
        {
            year ++;
            Timestamp -= 31536000;
            tmp ++;
            if(tmp == 4)
            {
                if(Timestamp >= 31622400)
                {
                    tmp = 0;
                    year ++;
                    Timestamp -= 31622400;
                }
                else break;
            }
        }
        else break;
    }
   
    for(new i = 0; i < 12; i ++)
    {
        if(Timestamp >= MonthTimes[i][2 + IsLeapYear(year)])
        {
            month ++;
            Timestamp -= MonthTimes[i][2 + IsLeapYear(year)];
        }
        else break;
    }
    day = 1 + (Timestamp / 86400);
    Timestamp %= 86400;
    hour = HourGMT + (Timestamp / 3600);
    Timestamp %= 3600;
    minute = MinuteGMT + (Timestamp / 60);
    second = (Timestamp % 60);
    if(minute > 59)
    {
        minute = 0;
        hour ++;
    }
    if(hour > 23)
    {
        hour -= 24;
        day ++;
    }
    if(day > MonthTimes[month][IsLeapYear(year)])
    {
        day = 1;
        month ++;
    }
    if(month > 12)
    {
        month = 1;
        year ++;
    }
    return 1;
}

stock DateToTimestamp(str[11])
{
    new date[3]; // date[0] = day           date[1] = month                 date[2] = year
    if(!sscanf(str,"p<"#SPLITTER">ddd",date[0],date[1],date[2]))
    {
        new total = 0,
            tmp = 0;
           
        total += date[0] * 86400;
        if(date[1] == 2 && date[0] < 29) tmp = ((date[2] - 1968) / 4 - 2);
        else tmp = ((date[2] - 1968) / 4 - 1);
           
        total += tmp * 31622400;
        total += (date[2] - 1970 - tmp) * 31536000;
       
        for(new i = 1; i < date[1]; i ++) total += MonthTimes[i][0 + IsLeapYear(date[2])] * 86400;
        return total;
    }
    else return -1;
}
Reply
#2

Код:
cmd:timestamp
stock TimestampToDate(Timestamp, &year, &month, &day, &hour, &minute, &second, HourGMT, MinuteGMT = 0)
{
    new tmp = 2;
    year = 1970;
    month = 1;
    Timestamp -= 172800; // Delete two days from the current timestamp. This is necessary, because the timestamp retrieved using gettime() includes two too many days.
    for(;;)
    {
        if(Timestamp >= 31536000)
        {
            year ++;
            Timestamp -= 31536000;
            tmp ++;
            if(tmp == 4)
            {
                if(Timestamp >= 31622400)
                {
                    tmp = 0;
                    year ++;
                    Timestamp -= 31622400;
                }
                else break;
            }
        }
        else break;
    }
    
    for(new i = 0; i < 12; i ++)
    {
        if(Timestamp >= MonthTimes[i][2 + IsLeapYear(year)])
        {
            month ++;
            Timestamp -= MonthTimes[i][2 + IsLeapYear(year)];
        }
        else break;
    }
    day = 1 + (Timestamp / 86400);
    Timestamp %= 86400;
    hour = HourGMT + (Timestamp / 3600);
    Timestamp %= 3600;
    minute = MinuteGMT + (Timestamp / 60);
    second = (Timestamp % 60);
    if(minute > 59)
    {
        minute = 0;
        hour ++;
    }
    if(hour > 23)
    {
        hour -= 24;
        day ++;
    }
    if(day > MonthTimes[month][IsLeapYear(year)])
    {
        day = 1;
        month ++;
    }
    if(month > 12)
    {
        month = 1;
        year ++;
    }
    return 1;
}

stock DateToTimestamp(str[11])
{
    new date[3]; // date[0] = day           date[1] = month                 date[2] = year
    if(!sscanf(str,"p<"#SPLITTER">ddd",date[0],date[1],date[2]))
    {
        new total = 0,
            tmp = 0;
            
        total += date[0] * 86400;
        if(date[1] == 2 && date[0] < 29) tmp = ((date[2] - 1968) / 4 - 2);
        else tmp = ((date[2] - 1968) / 4 - 1);
            
        total += tmp * 31622400;
        total += (date[2] - 1970 - tmp) * 31536000;
        
        for(new i = 1; i < date[1]; i ++) total += MonthTimes[i][0 + IsLeapYear(date[2])] * 86400;
        return total;
    }
    else return -1;
}
Reply
#3

Not work
Reply
#4

pawn Код:
COMMAND:test(playerid, params[])
{
    new date[6],
        string[144],
        Timestamp = gettime();

    TimestampToDate(Timestamp, date[0], date[1], date[2], date[3], date[4], date[5], 1);

    format(string, sizeof(string), "Date: %d/%d/%d %d:%d:%d", date[0], date[1], date[2], date[3], date[4], date[5]);
    return SendClientMessage(playerid, -1, string);
}
= Unknown command, why?
Reply
#5

Try this:

pawn Код:
COMMAND:test(playerid, params[])
{
    new date[6], string[144], Timestamp = gettime();
    TimestampToDate(Timestamp, date[0], date[1], date[2], date[3], date[4], date[5], 1);
    format(string, sizeof(string), "Date: %d/%d/%d %d:%d:%d", date[0], date[1], date[2], date[3], date[4], date[5]);
    SendClientMessage(playerid, -1, string);
    return 1;
}
Reply
#6

Quote:
Originally Posted by Translator
Посмотреть сообщение
Try this:

pawn Код:
COMMAND:test(playerid, params[])
{
    new date[6], string[144], Timestamp = gettime();
    TimestampToDate(Timestamp, date[0], date[1], date[2], date[3], date[4], date[5], 1);
    format(string, sizeof(string), "Date: %d/%d/%d %d:%d:%d", date[0], date[1], date[2], date[3], date[4], date[5]);
    SendClientMessage(playerid, -1, string);
    return 1;
}
Unknown command
Reply
#7

The problem might not be in your code but in TimestampToDate instead. I just told the creator of that function to take a look at your problem.
Reply
#8

up please
Reply
#9

help please.
Reply
#10

I think error is this line -
Quote:

if(!sscanf(str,"p<"#SPLITTER">ddd",date[0],date[1],date[2]))

it should be
Quote:

if(!sscanf(str,"p<\"#SPLITTER\">ddd",date[0],date[1],date[2]))

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)