using System;

namespace ScrewsMaster
{
    public sealed class DateTimeManager : BaseInterfaceManager<DateTimeManager>
    {
        public static DateTime StartTimestampDT = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
        private long HeartBeatInterval = 7;
        public int ServerRTTOneWayTimeOffset { get; private set; }

        public long GetCurrTimestamp()
        {
            long timestamp = (long)(DateTime.Now - StartTimestampDT).TotalSeconds;
            return timestamp;
        }

        public long GetServerCurrTimestamp()
        {
            return GetCurrTimestamp() - ServerRTTOneWayTimeOffset;
        }

        public DateTime GetCurrDateTime()
        {
            return DateTime.Now;
        }

        public DateTime GetDateTime(long timestamp)
        {
            DateTime dt = StartTimestampDT.AddSeconds(timestamp);
            return dt;
        }

        public string DateTimeToYYYYMMDD(DateTime time)
        {
            return time.ToString("yyyyMMdd");
        }

        public string DateTimeToString(DateTime time)
        {
            return time.ToString("yyyy/MM/dd HH:mm:ss");
        }

        public string TimestampToString(long endTimestamp)
        {
            return DateTimeToString(GetDateTime(endTimestamp));
        }
                public long GetCurrTimesTampByMillisecond()
        {
            long time = (long)(DateTime.Now - StartTimestampDT).TotalMilliseconds;
            return time;
        }
        public string DateTimeToFFFString(DateTime time)
        {
            return time.ToString("HH:mm:ss ff");
        }
        public long GetServerCurrTimestampByMillisecond()
        {
            return GetCurrTimesTampByMillisecond() - ServerRTTOneWayTimeOffset * 1000;
        }
    }
}