Created
March 16, 2011 17:48
-
-
Save pilcrow/872933 to your computer and use it in GitHub Desktop.
Firebird 2.1 GETTIMEOFDAY UDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Quick GETTIMEOFDAY() UDF, because FB TIMESTAMPs are not TIME ZONE aware */ | |
/* Mike Pomraning 2011 for FB 2.1; this code is in the Public Domain */ | |
#include <sys/time.h> | |
/* | |
DECLARE EXTERNAL FUNCTION gettimeofday | |
RETURNS DOUBLE PRECISION BY VALUE | |
ENTRY_POINT 'UDF_gettimeofday' MODULE_NAME 'udf_gettimeofday'; | |
-- SET TERM !!; | |
-- CREATE PROCEDURE epoch | |
-- RETURNS (time_t INTEGER, timeval DOUBLE PRECISION) AS BEGIN | |
-- SELECT timeval, CAST(FLOOR(timeval) AS INTEGER) | |
-- FROM (SELECT gettimeofday() AS timeval FROM rdb$database) d | |
-- INTO :timeval, :time_t; | |
-- SUSPEND; | |
-- END !! | |
-- SET TERM ;!! | |
*/ | |
double UDF_gettimeofday(void) | |
{ | |
struct timeval tv; | |
gettimeofday(&tv, (struct timezone *)0); | |
return (double)tv.tv_sec + tv.tv_usec / 1000000.0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment