Skip to content

Instantly share code, notes, and snippets.

@fsans
Last active November 9, 2018 08:55
Show Gist options
  • Save fsans/3303058 to your computer and use it in GitHub Desktop.
Save fsans/3303058 to your computer and use it in GitHub Desktop.
FMTimeHiRes() plugin función
/*
* FMTimeHiRes.cpp
* PlugInTemplate
*
* Created by Francesc Sans on 16/07/12.
* Copyright 2012 Network BCN Software. All rights reserved.
*
* FMTimeHiRes({format})
*
* Returns Timestamp to microseconds precisión
*
*
*/
#include <time.h>
#pragma mark DCBox_GetTimeHiRes
FMX_PROC(fmx::errcode) DCBox_GetTimeHiRes(short funcId, const fmx::ExprEnv& environment, const fmx::DataVect& dataVect, fmx::Data& result)
{
#pragma unused(funcId,environment)
fmx::errcode err = 0;
fmx::FixPtAutoPtr epoch;
fmx::TextAutoPtr tempText;
fmx::TextAutoPtr resultText;
struct timeval tv;
gettimeofday(&tv, NULL);
if( dataVect.Size() > 0 )
{
//We have at least one parameter. Read it and return correct information.
const fmx::Text& parameter1 = dataVect.AtAsText(0);
if( tempText->Assign(""), *tempText == parameter1 )
{
// defaul format option
epoch->AssignDouble ( double(tv.tv_sec + tv.tv_usec/1000000.0) );
result.SetAsNumber( *epoch );
}
else if( tempText->Assign("epoch"), *tempText == parameter1 )
{
// epoch format option, same as default
epoch->AssignDouble ( double(tv.tv_sec + tv.tv_usec/1000000.0) );
result.SetAsNumber( *epoch );
}
else if( tempText->Assign("UTC"), *tempText == parameter1 )
{
// ( TO DO ) UTC format option
epoch->AssignDouble ( double(tv.tv_sec + tv.tv_usec/1000000.0) );
result.SetAsNumber( *epoch );
}
else if( tempText->Assign("local"), *tempText == parameter1 )
{
// ( TO DO ) Local format option
epoch->AssignDouble ( double(tv.tv_sec + tv.tv_usec/1000000.0) );
result.SetAsNumber( *epoch );
}
}
return err;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment