Parse common UTC timestamps in process
This commit is contained in:
parent
7789385ef5
commit
03ffeeb0da
@ -195,11 +195,22 @@ RENDER(Request& context)
|
||||
}
|
||||
check("request_perf() stages stable repeated snapshots", perf_stable, json_encode(perf));
|
||||
|
||||
u64 shell_exec_before_time_parse = 0;
|
||||
request_perf()["hostcall_operations"].each([&](DValue operation, String key) {
|
||||
if(operation["name"].to_string() == "shell_exec")
|
||||
shell_exec_before_time_parse = operation["count"].to_u64();
|
||||
});
|
||||
u64 parsed_epoch = time_parse("1970-01-01 00:00:05 UTC");
|
||||
u64 parsed_iso_epoch = time_parse("1970-01-01T00:00:05Z");
|
||||
u64 shell_exec_after_time_parse = 0;
|
||||
request_perf()["hostcall_operations"].each([&](DValue operation, String key) {
|
||||
if(operation["name"].to_string() == "shell_exec")
|
||||
shell_exec_after_time_parse = operation["count"].to_u64();
|
||||
});
|
||||
String utc_year = time_format_utc("%Y", parsed_epoch);
|
||||
String local_year = time_format_local("%Y", parsed_epoch);
|
||||
String relative = time_format_relative(time() - 120, "recent %deltaS", 1, "medium %deltaM", 3600, "old %deltaH");
|
||||
check("time_format_local() / time_format_relative() / time_parse()", parsed_epoch == 5 && time_parse("") == 0 && time_parse(" ") == 0 && utc_year == "1970" && local_year != "" && contains(relative, "medium"), "parsed=" + std::to_string(parsed_epoch) + " empty=" + std::to_string(time_parse("")) + " utc=" + utc_year + " local=" + local_year + " rel=" + relative);
|
||||
check("time_format_local() / time_format_relative() / time_parse()", parsed_epoch == 5 && parsed_iso_epoch == 5 && shell_exec_after_time_parse == shell_exec_before_time_parse && time_parse("") == 0 && time_parse(" ") == 0 && utc_year == "1970" && local_year != "" && contains(relative, "medium"), "parsed=" + std::to_string(parsed_epoch) + " iso=" + std::to_string(parsed_iso_epoch) + " shell=" + std::to_string(shell_exec_before_time_parse) + "/" + std::to_string(shell_exec_after_time_parse) + " empty=" + std::to_string(time_parse("")) + " utc=" + utc_year + " local=" + local_year + " rel=" + relative);
|
||||
|
||||
String crypto_random = random_bytes(16);
|
||||
String crypto_b64 = base64_encode("hello");
|
||||
|
||||
@ -462,6 +462,24 @@ u64 time_parse(String time_String)
|
||||
time_String = trim(time_String);
|
||||
if(time_String == "")
|
||||
return(0);
|
||||
if(time_String.size() == 19 || (time_String.size() == 20 && time_String[19] == 'Z') || (time_String.size() == 23 && time_String.substr(19) == " UTC"))
|
||||
{
|
||||
struct tm parsed = {};
|
||||
String calendar = time_String.substr(0, 19);
|
||||
const char* end = strptime(calendar.c_str(), calendar[10] == 'T' ? "%Y-%m-%dT%H:%M:%S" : "%Y-%m-%d %H:%M:%S", &parsed);
|
||||
if(end && *end == 0)
|
||||
{
|
||||
char normalized[20];
|
||||
strftime(normalized, sizeof(normalized), "%Y-%m-%d %H:%M:%S", &parsed);
|
||||
calendar[10] = ' ';
|
||||
if(calendar == normalized)
|
||||
{
|
||||
time_t timestamp = timegm(&parsed);
|
||||
if(timestamp >= 0)
|
||||
return((u64)timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(int_val(trim(shell_exec("date -u -d " + shell_escape(time_String) + " +'%s'"))));
|
||||
}
|
||||
u64 socket_connect(String host, u16 port)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user