[Plugin] FTime - Unix timestamp conversions and more!
#1

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 2015month 1day 5dName[10];
getdayname(yearmonthdaydName);
printf("%d/%d/%d was %s."daymonthyeardName); 
Outputs:
Code:
5/1/2015 was Monday.
cvstamp2datetime

PHP Code:
new timestamp 1445842664yearmonthdayhourminutesecond;
cvstamp2datetime(timestampyearmonthdayhourminutesecond, -5);
printf("[Time] %d:%d:%d | [Date] %d/%d/%d"hourminuteseconddaymonthyear); 
Outputs:
Code:
[Time] 1:57:44 | [Date] 26/10/2015
cvdatetime2stamp


PHP Code:
new timestampyear 2015month 10day 26hour 1minute 57second 44;
    
cvdatetime2stamp(timestampyearmonthdayhourminutesecond, -5);
    
printf("[Time] %d:%d:%d | [Date] %d/%d/%d outputs %d as an unix timestamp."hourminuteseconddaymonthyeartimestamp); 
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:
  • ThePhenix
  • Crayder
  • Compuphase
Download:

Release + Source code
Github
Reply
#2

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

+6 reps
Reply
#3

Nice job, keep it up
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)