﻿using System;

namespace Eve.Core.Extensions
{
    public static class DateTimeExtensions
    {
        private static DateTime SpecifyKind(DateTime dt)
        {
            return DateTime.SpecifyKind(dt, DateTimeKind.Utc);
        }


        /// <summary>
        /// copy-paste from DateTimeOffset .net 4.6
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static long ToUnixTimeSeconds(this DateTime dateTime)
        {
            return SpecifyKind(dateTime).Ticks / 10000000L - 62135596800L;
        }

        /// <summary>
        /// copy-paste from DateTimeOffset .net 4.6
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static long ToUnixTimeMilliseconds(this DateTime dateTime)
        {
            return SpecifyKind(dateTime).Ticks / 10000L - 62135596800000L;
        }
    }
}
