SA-MP Forums Archive
[Plugin] FTime - Unix timestamp conversions and more! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: [Plugin] FTime - Unix timestamp conversions and more! (/showthread.php?tid=592570)



FTime - Unix timestamp conversions and more! - ThePhenix - 26.10.2015

Ftime


Overview:

I was searching through the forum and I didn't see any include or plugin to perform conversions between unix timestamps efficiently, so I was checking the time library made by compuphase and decided to implement their code into a plugin adding the GMT parameter.

This plugin allows you to perform conversions between unix timestamps, it means that if you have a date and time you can convert that to a unix timestamp and vice versa.

Functions:

Code:
native getdayname(year, month, day, string[], len = sizeof(string));
native cvstamp2datetime(timestamp, &year, &month, &day, &hour, &minute, &second, GMT);
native cvdatetime2stamp(&timestamp, year, month, day, hour, minute, second, GMT);
getdayname example:

PHP Code:
new year = 2015, month = 1, day = 5, dName[10];
getdayname(year, month, day, dName);
printf("%d/%d/%d was %s.", day, month, year, dName); 
Outputs:
Code:
5/1/2015 was Monday.
cvstamp2datetime

PHP Code:
new timestamp = 1445842664, year, month, day, hour, minute, second;
cvstamp2datetime(timestamp, year, month, day, hour, minute, second, -5);
printf("[Time] %d:%d:%d | [Date] %d/%d/%d", hour, minute, second, day, month, year); 
Outputs:
Code:
[Time] 1:57:44 | [Date] 26/10/2015
cvdatetime2stamp


PHP Code:
new timestamp, year = 2015, month = 10, day = 26, hour = 1, minute = 57, second = 44;
    
cvdatetime2stamp(timestamp, year, month, day, hour, minute, second, -5);
    
printf("[Time] %d:%d:%d | [Date] %d/%d/%d outputs %d as an unix timestamp.", hour, minute, second, day, month, year, timestamp); 
Outputs:
Code:
[Time] 1:57:44 | [Date] 26/10/2015 outputs 1445842664 as an unix timestamp.
Benchmarks:

Using Slice's benchmark macros I got the following results.

Code:
Bench for cvstamp2datetime: executes, by average, 1516.13 times/ms.
Bench for cvdatetime2stamp: executes, by average, 1684.50 times/ms.
Bench for getdayname: executes, by average, 1730.83 times/ms.
Credits:
Download:

Release + Source code
Github


Re: FTime - Unix timestamp conversions and more! - n0minal - 27.10.2015

Nice, I would use it but I already use CTime plugin, good job anyways

+6 reps


Re: FTime - Unix timestamp conversions and more! - SecretBoss - 27.10.2015

Nice job, keep it up