using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace JiShe.CollectBus.Common.Extensions
{
    public static class DateTimeOffsetExtensions
    {
         
        /// <summary>
        /// 获取当前时间毫秒级时间戳
        /// </summary>
        /// <returns></returns>
        public static long GetCurrentTimeMillis()
        {
            return DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
        }

        /// <summary>
        /// 将Unix时间戳转换为日期时间
        /// </summary>
        /// <param name="millis"></param>
        /// <returns></returns>
        public static DateTime FromUnixMillis(long millis)
        {
            return DateTimeOffset.FromUnixTimeMilliseconds(millis).DateTime;
        }
         
        /// <summary>
        /// 将 DateTime 时间转换为 DateTimeOffset 时间
        /// </summary>
        /// <param name="rawDateTime"></param>
        /// <returns></returns>
        public static DateTimeOffset GetDateTimeOffset(this DateTime rawDateTime)
        {
            //确保 Kind 为 Local（如果是 Unspecified）
            DateTime localDateTime = rawDateTime.Kind == DateTimeKind.Unspecified
                ? DateTime.SpecifyKind(rawDateTime, DateTimeKind.Local)
                : rawDateTime;

            // 转换为 DateTimeOffset（自动应用本地时区偏移）
            return new DateTimeOffset(localDateTime);
        } 
    }
}
