| 395 | { |
| 396 | QiFunc_time_set_ms() : QiFunc(0, 7) {} |
| 397 | QiVar exec(const std::vector<QiVar>& args, QiScriptInterpreter*) const override |
| 398 | { |
| 399 | std::unique_lock<std::mutex> lock(sys_last_mutex); |
| 400 | time_t msec; |
| 401 | if (args.empty()) |
| 402 | { |
| 403 | if (sys_last_time) msec = sys_last_time + clock() - sys_last_clock; |
| 404 | else return true; |
| 405 | } |
| 406 | else |
| 407 | { |
| 408 | if (args.size() > 1) |
| 409 | { |
| 410 | msec = DateTimeToUnixMs(args[0].toInteger(), |
| 411 | args.size() > 1 ? args[1].toInteger() : 0, |
| 412 | args.size() > 2 ? args[2].toInteger() : 0, |
| 413 | args.size() > 3 ? args[3].toInteger() : 0, |
| 414 | args.size() > 4 ? args[4].toInteger() : 0, |
| 415 | args.size() > 5 ? args[5].toInteger() : 0, |
| 416 | args.size() > 6 ? args[6].toInteger() : 0 |
| 417 | ); |
| 418 | } |
| 419 | else |
| 420 | { |
| 421 | msec = args[0].toInteger(); |
| 422 | } |
| 423 | if (!sys_last_time) sys_last_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), sys_last_clock = clock(); |
| 424 | } |
| 425 | return SetSystemTime_UnixMs(msec); |
| 426 | } |
| 427 | }; |
| 428 | |
| 429 | const char* ntp_servers[] = { "ntp.aliyun.com", "ntp.tencent.com", "ntp.ntsc.ac.cn", "pool.ntp.org" }; |
nothing calls this directly
no test coverage detected