Raised This Month: $7 Target: $400
 1% 

[STOCK] DateToTimeStamp converter


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 02-27-2013 , 12:24   [STOCK] DateToTimeStamp converter
Reply With Quote #1

provides stock to convert a date to seconds since Unix Epoch (01.01.1970)

attached test plugin
command to test "date_test" - only from server console or rcon

PHP Code:
stock DateToTimeStamp(daymonthyearhourminuteseconds)
{
    return 
YearToSeconds(year) + MonthToSeconds(yearmonth) + DaysToSeconds(day) + TimeToSeconds(hourminuteseconds) - 21600// Why it returns more by 21600?
}

stock YearToSeconds(year)
{
    new 
var1 year 4;
    new 
var2 year var1;
    
    new 
var3 var1 492;
    new 
var4 var2 1478;
    
    
var3 *= 31622400;
    
var4 *= 31536000;
    
    return 
var3 var4;
}

// 31 days = 2678400 seconds
// 30 days = 2592000
// 29 days = 2505600
// 28 days = 2419200

stock MonthToSeconds(yearmonth)
{
    
month -= 1;
    
    new 
result;
    
    switch (
month)
    {
        case 
1357810 :
        {
            
result 2678400;
        }
        case 
:
        {
            if (
year == 0)
            {
                
result 2505600;
            }
            else
            {
                
result 2419200;
            }
        }
        case 
46911 :
        {
            
result 2592000;
        }
    }
    
    if (
month 1)
    {
        
result += MonthToSeconds(yearmonth);
    }
    
    return 
result;
}

stock DaysToSeconds(days)
{
    
days-=1;
    return 
days 86400;
}

stock TimeToSeconds(hourminuteseconds)
{
    return 
hour 3600 minute 60 seconds;

Attached Files
File Type: inc date.inc (1.1 KB, 260 views)
File Type: sp Get Plugin or Get Source (test.sp - 268 views - 1.3 KB)

Last edited by Despirator; 02-27-2013 at 12:26.
Despirator is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-27-2013 , 16:36   Re: [STOCK] DateToTimeStamp converter
Reply With Quote #2

It'd be better if SourceMod just had a native to call the C library's strptime function much like FormatTime calls the C library's strftime function.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 02-27-2013 at 16:37.
Powerlord is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 02-27-2013 , 23:25   Re: [STOCK] DateToTimeStamp converter
Reply With Quote #3

i have already requested it yesterday https://bugs.alliedmods.net/show_bug.cgi?id=5635
Despirator is offline
Reply


Thread Tools
Display Modes

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 07:36.


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