Skip to content

Instantly share code, notes, and snippets.

@pilcrow
Created March 16, 2011 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilcrow/872933 to your computer and use it in GitHub Desktop.
Save pilcrow/872933 to your computer and use it in GitHub Desktop.
Firebird 2.1 GETTIMEOFDAY UDF
/* 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