/*************************************************************************************************************
This file contains time string function
2012/6 by Dlxko
**************************************************************************************************************/
#include "Time.h"

static int hour;
static int minute;
static int second;

static struct tm newtime;
static char timemsg[TIME_SIZE];
static std::string str;
static __time64_t long_time;
static errno_t err;

/**** Get time string ****/
std::string function_get_std_time()
{
	// Insert time data
	_time64( &long_time );

	// Get local time
	err = _localtime64_s( &newtime, &long_time );

	// If error print
	if (err)
		function_show_warning("Invalid argument to _localtime64_s.");

	// Get time datas
	hour = newtime.tm_hour;
	minute = newtime.tm_min;
	second = newtime.tm_sec;

	// Check values
	if (hour > 24 || minute > 59 || second > 59)
	{
		function_show_warning("Wrong time format returning zeroed data");
		return "00.00.00";
	}

	// Save datas
	sprintf_s(timemsg, "%d.%d.%d", hour, minute, second);

	// Create string
	str = std::string(timemsg);

	// Return it!
	return str;
}