#include "TimeUtil.h"


TimeUtil::TimeUtil()
{
}

TimeUtil::~TimeUtil()
{
}


// codigo extraido da JVM (para fazer um sysTimeMillis da mesma forma
#ifdef WINDOWS
#define FT2INT64(ft) ((jlong)(ft).dwHighDateTime << 32 | (jlong)(ft).dwLowDateTime)

	void TimeUtil::sysTimeMillis(jlong &currentTime)
	{
	    static jlong fileTime_1_1_70 = 0;

	    if (fileTime_1_1_70 == 0) {
			/* Initialize fileTime_1_1_70 -- the Win32 file time of midnight
			 * 1/1/70.
			 */
			memset(&st0, 0, sizeof(st0));
			st0.wYear  = 1970;
			st0.wMonth = 1;
			st0.wDay   = 1;
			SystemTimeToFileTime(&st0, &ft0);
			fileTime_1_1_70 = FT2INT64(ft0);
	    }

	    GetSystemTime(&st0);
	    SystemTimeToFileTime(&st0, &ft0);

	    currentTime = (FT2INT64(ft0) - fileTime_1_1_70) / 10000;
	}
#else
	void TimeUtil::
	sysTimeMillis(long & currentTime)
	{
	    gettimeofday(&t, 0);
	    currentTime = ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
	}

#endif
