ReturnDate => Transfer time stamp to date
Hi, I'd like to introduce my version of the timestamp to date - ReturnDate.
I would like to thank in advance for your attention and patience in reading this long post, I tried to shorten it as much as possible so it was understandable and it had a head and a heel....
Why did I make my own version?
I'm developing my own mode, where I do not use foreign features other than plugins, I always try to do everything in my own right so that it is faster and, if possible, less burdensome than RAM or CPU than Internet versions.
While it is true that I test the cycle functions repeating 1,000,000x (to ensure the differences) and in practice they are triggered so they go, maybe 2x 3x, but it does not change that the code must be unclear and unnecessarily complicated when it It's easy....
In this case, after the experience and use of the TimestampToDate and 'date' functions, which often showed me a slightly different date than I had, I would make my own conversion to date...
What is the difference between the original and this version?
This version does not use unnecessarily two-dimensional variables (which store 12 months, for every 2 possible days of the month and a time stamp) as in the original versions.
The other and major difference is that the time stamp does not take place from January 1, 1970 00:00:00, but from the pre-set beginning of the year.
For example, the first registered X player will be on January 12, 2017 (time is not important) and I know that the server will no longer store any older data but always newer (later registered, timeban, ...).
That's why we set the FYear in 2017; FStamp as a time stamp for midnight 1.1.2017 (possible to get HERE, it is necessary to add 7200 -> 2 hours, CET) to the resulting timestamp.
When invoking the function, it will skip to the specified part, which is the beginning of 2017, and the calculation of the remaining time stamp continues.
First, the subtraction cycle of the year starts (if at least 1 year is available), then continues to find the months (at this step there is no cycle but as we know that there are 12 months remaining, then we will examine them once if it is found that No more available, jumps to classic cycles that count days, hours, minutes, and the rest are seconds.
Advantages and disadvantages?
The benefits of this release are faster execution and less RAM usage.
The disadvantage is that the function does not detect older data than the one defined in the block (which actually ensures faster execution).
Speed test.
I compared the speed of all 3 functions in the 1.000.000 cycle - ReturnDate, TimestampToDate, and Date.
The boys of my English are not so much so I use a translator
Hi, I'd like to introduce my version of the timestamp to date - ReturnDate.
I would like to thank in advance for your attention and patience in reading this long post, I tried to shorten it as much as possible so it was understandable and it had a head and a heel....
Why did I make my own version?
I'm developing my own mode, where I do not use foreign features other than plugins, I always try to do everything in my own right so that it is faster and, if possible, less burdensome than RAM or CPU than Internet versions.
While it is true that I test the cycle functions repeating 1,000,000x (to ensure the differences) and in practice they are triggered so they go, maybe 2x 3x, but it does not change that the code must be unclear and unnecessarily complicated when it It's easy....
In this case, after the experience and use of the TimestampToDate and 'date' functions, which often showed me a slightly different date than I had, I would make my own conversion to date...
What is the difference between the original and this version?
This version does not use unnecessarily two-dimensional variables (which store 12 months, for every 2 possible days of the month and a time stamp) as in the original versions.
The other and major difference is that the time stamp does not take place from January 1, 1970 00:00:00, but from the pre-set beginning of the year.
For example, the first registered X player will be on January 12, 2017 (time is not important) and I know that the server will no longer store any older data but always newer (later registered, timeban, ...).
That's why we set the FYear in 2017; FStamp as a time stamp for midnight 1.1.2017 (possible to get HERE, it is necessary to add 7200 -> 2 hours, CET) to the resulting timestamp.
When invoking the function, it will skip to the specified part, which is the beginning of 2017, and the calculation of the remaining time stamp continues.
First, the subtraction cycle of the year starts (if at least 1 year is available), then continues to find the months (at this step there is no cycle but as we know that there are 12 months remaining, then we will examine them once if it is found that No more available, jumps to classic cycles that count days, hours, minutes, and the rest are seconds.
Advantages and disadvantages?
The benefits of this release are faster execution and less RAM usage.
The disadvantage is that the function does not detect older data than the one defined in the block (which actually ensures faster execution).
Speed test.
I compared the speed of all 3 functions in the 1.000.000 cycle - ReturnDate, TimestampToDate, and Date.
PHP Code:
ReturnDate: 1749 | 709 | 1809 ms (average: 1423 ms)
TimestampToDate: 3568 | 2167 | 3454 ms (average: 3063 ms)
date: 37637 | 9752 | 37344 ms (average: 28245 ms)
PHP Code:
#define FYear 2017
#define FStamp 1483221600 //01.01.2017 00:00:00 (1483228800) - 7200 (2 Hours = CET)
stock ReturnDate(ts, &rday, &rmonth, &ryear, &rhour, &rminute, &rsecond)
{
rday = 1, rmonth = 1, ryear = FYear;
ts -= FStamp;
new bool:lp = false;
if((ryear % 4 == 0 && ( ryear % 100 != 0 || ryear % 400 == 0 ))) rday = 0;
while(ts > 31535999)
{
ryear++;
if((ryear % 4 == 0 && ( ryear % 100 != 0 || ryear % 400 == 0 ))) { ts -= 31622400; lp = true; }
else { ts -= 31536000; lp = false; }
}
if(ts < 2678400) goto next;
ts -= 2678400;
rmonth++;
if(lp == true)
{
if(ts < 2505600) goto next;
ts -= 2505600;
}
else
{
if(ts < 2419200) goto next;
ts -= 2419200;
}
rmonth++;
if(ts < 2678400) goto next;
ts -= 2678400;
rmonth++;
if(ts < 2592000) goto next;
ts -= 2592000;
rmonth++;
if(ts < 2678400) goto next;
ts -= 2678400;
rmonth++;
if(ts < 2592000) goto next;
ts -= 2592000;
rmonth++;
if(ts < 2678400) goto next;
ts -= 2678400;
rmonth++;
if(ts < 2678400) goto next;
ts -= 2678400;
rmonth++;
if(ts < 2592000) goto next;
ts -= 2592000;
rmonth++;
if(ts < 2678400) goto next;
ts -= 2678400;
rmonth++;
if(ts < 2592000) goto next;
ts -= 2592000;
rmonth++;
if(ts < 2678400) goto next;
ts -= 2678400;
rmonth++;
next:
rday += ts / 86400;
rhour = (ts % 86400) / 3600;
rminute = (ts % 86400 % 3600) / 60;
rsecond = (ts % 86400 % 3600 % 60);
}
The boys of my English are not so much so I use a translator