- moved date code to its own file.
This commit is contained in:
parent
6336e0e168
commit
504f85e6d4
5 changed files with 249 additions and 208 deletions
|
|
@ -2669,84 +2669,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, setFrozen, setFrozen)
|
|||
//
|
||||
//=====================================================================================
|
||||
|
||||
extern time_t epochoffset;
|
||||
|
||||
static int GetEpochTime()
|
||||
{
|
||||
time_t now;
|
||||
time(&now);
|
||||
return now != (time_t)(-1) ? int(now + epochoffset) : -1;
|
||||
}
|
||||
|
||||
//Returns an empty string if the Strf tokens are valid, otherwise returns the problematic token
|
||||
static FString CheckStrfString(FString timeForm)
|
||||
{
|
||||
// Valid Characters after %
|
||||
const char validSingles[] = { 'a','A','b','B','c','C','d','D','e','F','g','G','h','H','I','j','m','M','n','p','r','R','S','t','T','u','U','V','w','W','x','X','y','Y','z','Z' };
|
||||
|
||||
timeForm.Substitute("%%", "%a"); //Prevent %% from causing tokenizing problems
|
||||
timeForm = "a" + timeForm; //Prevent %* at the beginning from causing a false error from tokenizing
|
||||
|
||||
auto tokens = timeForm.Split("%");
|
||||
for (auto t : tokens)
|
||||
{
|
||||
bool found = false;
|
||||
// % at end
|
||||
if (t.Len() == 0) return FString("%");
|
||||
|
||||
// Single Character
|
||||
for (size_t i = 0; i < sizeof(validSingles)/sizeof(validSingles[0]); i++)
|
||||
{
|
||||
if (t[0] == validSingles[i])
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) continue;
|
||||
return FString("%") + t[0];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static void FormatTime(const FString& timeForm, int timeVal, FString* result)
|
||||
{
|
||||
FString error = CheckStrfString(timeForm);
|
||||
if (!error.IsEmpty())
|
||||
ThrowAbortException(X_FORMAT_ERROR, "'%s' is not a valid format specifier of SystemTime.Format()", error.GetChars());
|
||||
|
||||
time_t val = timeVal;
|
||||
struct tm* timeinfo = localtime(&val);
|
||||
if (timeinfo != nullptr)
|
||||
{
|
||||
char timeString[1024];
|
||||
if (strftime(timeString, sizeof(timeString), timeForm, timeinfo))
|
||||
*result = timeString;
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_SystemTime, Now, GetEpochTime)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
ACTION_RETURN_INT(GetEpochTime());
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_SystemTime, Format, FormatTime)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_STRING(timeForm);
|
||||
PARAM_INT(timeVal);
|
||||
FString result;
|
||||
FormatTime(timeForm, timeVal, &result);
|
||||
ACTION_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//=====================================================================================
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(_AltHUD, GetLatency, Net_GetLatency)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue