42 lines
1005 B
C
42 lines
1005 B
C
|
#pragma once
|
|||
|
|
|||
|
#include "XNCore_global.h"
|
|||
|
#include "XNString.h"
|
|||
|
#include "XNType.h"
|
|||
|
#include <chrono>
|
|||
|
#include <iomanip>
|
|||
|
#include <sstream>
|
|||
|
#include <time.h>
|
|||
|
|
|||
|
namespace XNSim {
|
|||
|
/**
|
|||
|
* @brief 纳秒睡眠相关时间结构体
|
|||
|
* @details 用于线程睡眠时间控制
|
|||
|
*/
|
|||
|
struct PERIOD_INFO {
|
|||
|
/**
|
|||
|
* @brief 系统提供的时间记录结构体,精确到纳秒
|
|||
|
*/
|
|||
|
timespec next_period;
|
|||
|
/**
|
|||
|
* @brief 睡眠时长,单位纳秒
|
|||
|
*/
|
|||
|
XN_INT64 period_ns;
|
|||
|
};
|
|||
|
|
|||
|
// 系统时间点类型别名
|
|||
|
using XNTimePoint = std::chrono::system_clock::time_point;
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 将ISO格式的时间字符串转换为系统时间点
|
|||
|
* @param timeStr ISO格式的时间字符串 (YYYY-MM-DDTHH:mm:ss)
|
|||
|
* @return 系统时间点
|
|||
|
*/
|
|||
|
FORCEINLINE XNTimePoint parseISOTime(const XN_STRING &timeStr) {
|
|||
|
std::tm tm = {};
|
|||
|
std::istringstream ss(timeStr);
|
|||
|
ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%S");
|
|||
|
auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
|||
|
return tp;
|
|||
|
}
|
|||
|
} // namespace XNSim
|