namespace Zncy.CloudCar.WeChat.Service.Utilities
{
///
/// 微信日期处理帮助类
///
public class DateTimeHelper
{
/// Unix起始时间
public static readonly DateTimeOffset BaseTime = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
/// 转换微信DateTime时间到C#时间
/// 微信DateTime
///
public static DateTime GetDateTimeFromXml(long dateTimeFromXml) => GetDateTimeOffsetFromXml(dateTimeFromXml).LocalDateTime;
/// 转换微信DateTime时间到C#时间
/// 微信DateTime
///
public static DateTime GetDateTimeFromXml(string dateTimeFromXml) => GetDateTimeFromXml(long.Parse(dateTimeFromXml));
/// 转换微信DateTimeOffset时间到C#时间
/// 微信DateTime
///
public static DateTimeOffset GetDateTimeOffsetFromXml(long dateTimeFromXml) => BaseTime.AddSeconds(dateTimeFromXml).ToLocalTime();
/// 转换微信DateTimeOffset时间到C#时间
/// 微信DateTime
///
public static DateTimeOffset GetDateTimeOffsetFromXml(string dateTimeFromXml) => GetDateTimeFromXml(long.Parse(dateTimeFromXml));
/// 获取微信DateTime(UNIX时间戳)
/// 时间
///
[Obsolete("请使用 GetUnixDateTime(dateTime) 方法")]
public static long GetWeixinDateTime(DateTime dateTime) => GetUnixDateTime(dateTime);
/// 获取Unix时间戳
///
///
public static long GetUnixDateTime(DateTimeOffset dateTime) => (long)(dateTime - BaseTime).TotalSeconds;
/// 获取Unix时间戳
///
///
public static long GetUnixDateTime(DateTime dateTime) => (long)(dateTime.ToUniversalTime() - BaseTime).TotalSeconds;
}
}