mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2026-01-20 02:10:10 +03:00
Implementation of the JSON-RPC API and the Web Admin interface. (dnobori's internal note: 7579 - 7682)
This commit is contained in:
@ -1408,11 +1408,103 @@ void GetDateTimeStrMilli(char *str, UINT size, SYSTEMTIME *st)
|
||||
st->wMilliseconds);
|
||||
}
|
||||
|
||||
|
||||
// Convert string RFC3339 format (example: 2017-09-27T18:25:55.434-9:00) to UINT64
|
||||
UINT64 DateTimeStrRFC3339ToSystemTime64(char *str)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
if (DateTimeStrRFC3339ToSystemTime(&st, str))
|
||||
{
|
||||
return SystemToUINT64(&st);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert string RFC3339 format (example: 2017-09-27T18:25:55.434-9:00) to SYSTEMTIME
|
||||
bool DateTimeStrRFC3339ToSystemTime(SYSTEMTIME *st, char *str)
|
||||
{
|
||||
bool ok = false;
|
||||
UINT index_plus;
|
||||
char tmp[MAX_PATH];
|
||||
Zero(st, sizeof(SYSTEMTIME));
|
||||
if (st == NULL || str == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
StrCpy(tmp, sizeof(tmp), str);
|
||||
|
||||
index_plus = SearchStrEx(tmp, "+", 0, false);
|
||||
if (index_plus != INFINITE)
|
||||
{
|
||||
tmp[index_plus] = 0;
|
||||
}
|
||||
|
||||
if (StrLen(tmp) >= 19)
|
||||
{
|
||||
if (tmp[4] == '-' && tmp[7] == '-' && tmp[10] == 'T' && tmp[13] == ':' &&
|
||||
tmp[16] == ':')
|
||||
{
|
||||
char str_year[16], str_month[16], str_day[16], str_hour[16], str_minute[16],
|
||||
str_second[16], str_msec[16];
|
||||
|
||||
StrCpy(str_year, sizeof(str_year), tmp + 0);
|
||||
str_year[4] = 0;
|
||||
|
||||
StrCpy(str_month, sizeof(str_month), tmp + 5);
|
||||
str_month[2] = 0;
|
||||
|
||||
StrCpy(str_day, sizeof(str_day), tmp + 8);
|
||||
str_day[2] = 0;
|
||||
|
||||
StrCpy(str_hour, sizeof(str_hour), tmp + 11);
|
||||
str_hour[2] = 0;
|
||||
|
||||
StrCpy(str_minute, sizeof(str_minute), tmp + 14);
|
||||
str_minute[2] = 0;
|
||||
|
||||
StrCpy(str_second, sizeof(str_second), tmp + 17);
|
||||
str_second[2] = 0;
|
||||
|
||||
str_msec[0] = 0;
|
||||
|
||||
if (StrLen(tmp) >= 21 && tmp[19] == '.')
|
||||
{
|
||||
StrCpy(str_msec, sizeof(str_msec), tmp + 20);
|
||||
str_msec[StrLen(tmp) - 21] = 0;
|
||||
while (StrLen(str_msec) < 3)
|
||||
{
|
||||
StrCat(str_msec, sizeof(str_msec), "0");
|
||||
}
|
||||
str_msec[3] = 0;
|
||||
}
|
||||
|
||||
st->wYear = ToInt(str_year);
|
||||
st->wMonth = ToInt(str_month);
|
||||
st->wDay = ToInt(str_day);
|
||||
st->wHour = ToInt(str_hour);
|
||||
st->wMinute = ToInt(str_minute);
|
||||
st->wSecond = ToInt(str_second);
|
||||
st->wMilliseconds = ToInt(str_msec);
|
||||
|
||||
NormalizeSystem(st);
|
||||
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
// Get the date and time string in RFC3339 format (example: 2017-09-27T18:25:55.434-9:00)
|
||||
void GetDateTimeStrRFC3339(char *str, UINT size, SYSTEMTIME *st, int timezone_min){
|
||||
// Validate arguments
|
||||
if (str == NULL || st == NULL)
|
||||
{
|
||||
ClearStr(str, size);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user