Raised This Month: $12 Target: $400
 3% 

Stock: IsDateInPast


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 03-09-2012 , 23:29   Stock: IsDateInPast
Reply With Quote #1

I just wrote this stock for an upcoming thing I'm about to release (I love the feeling when you're so close to releasing a big project you can taste it! ).

It accepts a single parameter, a date string formatted as YYYY-MM-DD, and compare it to the current server date. If the date is in the past, it returns true. Otherwise, it returns false (also returns false if the dates are identical).

I haven't tested it yet, but it should work fine. Let me know if there's a problem with it.

PHP Code:
stock bool:IsDateInPast(const String:date[]) {
    
decl String:curYear[4], String:curMonth[2], String:curDay[2], String:oldDate[3][4];
    
FormatTime(curYearsizeof(curYear), "Y");
    
FormatTime(curMonthsizeof(curMonth), "m");
    
FormatTime(curDaysizeof(curDay), "d");
    
ExplodeString(date"-"oldDate34);
    new 
cy StringToInt(curYear);
    new 
cm StringToInt(curMonth);
    new 
cd StringToInt(curDay);
    new 
oy StringToInt(oldDate[0]);
    new 
om StringToInt(oldDate[1]);
    new 
od StringToInt(oldDate[2]);
    if(
oy cy) {
        return 
true// the year we're comparing to is less than the current, it's in the past
    
}
    if(
oy cy) {
        return 
false// the year we're comparing to is greater than the current, it's in the future
    
}
    
// at this point the years must be identical
    
if(om cm) {
        return 
true// the month we're comparing to is less than the current, it's in the past
    
}
    if(
om cm) {
        return 
false// you get the drift
    
}
    
// at this point the months must be identical
    
if(od cd) {
        return 
true;
    }
    if(
od cd) {
        return 
false;
    }
    
// at this point the days are identical
    // identical days is not the past, so return false
    
return false;

__________________
Dr. McKay is offline
mcpan313
Senior Member
Join Date: Mar 2010
Old 03-11-2012 , 10:11   Re: Stock: IsDateInPast
Reply With Quote #2

PHP Code:
// GET GMT TIME

public OnSocketConnected(Handle:socketany:arg)
{
    
decl String:requestStr[100];
    
Format(requestStrsizeof(requestStr), "GET /%s HTTP/1.0\r\nHost: %s\r\nConnection: Close\r\n\r\n""index.php""www.baidu.com");
    
SocketSend(socketrequestStr);
}

public 
OnSocketReceive(Handle:socketString:receiveData[], const dataSizeany:arg)
{
    
decl String:buffer[2][40];
    
ExplodeString(receiveData"\r\n"buffersizeof(buffer), sizeof(buffer[]));
    if (
StrContains(buffer[1], "Date:"false) != -1)
    {
        
decl String:date[5][5];
        
ExplodeString(buffer[1], " "datesizeof(date), sizeof(date[]));
        static 
String:month[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
        
        for (new 
isizeof(month); i++)
        {
            if (
StrEqual(date[3], month[i], false))
            {
                new 
current[3];
                
current[0] = StringToInt(date[4]);
                
current[1] = i+1;
                
current[2] = StringToInt(date[2]);
                
                static 
expires[3]={2011,4,8};
                new 
bool:available = (expires[0] > current[0] || (expires[0] == current[0] && expires[1] > current[1] || (expires[1] == current[1] && expires[2] >= current[2])));
                
                
PrintToServer("Current : %d-%02d-%02d"current[0], current[1], current[2]);
                
PrintToServer("Expires : %d-%02d-%02d"expires[0], expires[1], expires[2]);
                
PrintToServer("Status  : %s"available "正常" "已过期");
            }
        }
    }

PHP Code:
GET /index.php HTTP/1.0
Host
www.baidu.com
Connection
Close

HTTP
/1.1 200 OK
Date
Thu08 Mar 2012 08:29:07 GMT
Server
BWS/1.0
Content
-Length7909
Content
-Typetext/html;charset=gb2312
Cache
-Control: private
ExpiresThu08 Mar 2012 08:29:07 GMT
Set
-CookieBAIDUID=7ABE9EC447428E163F78633173D8425B:FG=1expires=Thu08-Mar-42 08:29:07 GMTpath=/; domain=.baidu.com
P3P
CP=" OTI DSP COR IVA OUR IND COM "
ConnectionClose 
__________________
sorry, for my poor english.

Last edited by mcpan313; 03-11-2012 at 10:18.
mcpan313 is offline
Send a message via MSN to mcpan313
robin123
Junior Member
Join Date: Mar 2012
Old 03-12-2012 , 15:34   Re: Stock: IsDateInPast
Reply With Quote #3

Nice code, it looks clean and easy to implement. Thanks for sharing we have been working on an extended project that calculates time, cost, and too much more to get into.
robin123 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode