Ejemplo n.º 1
0
        /// <summary>
        /// Returns the local time that corresponds to a specified coordinated universal
        /// time (UTC).
        /// </summary>
        public override System.DateTime ToLocalTime(System.DateTime time)
        {
            // Add the UTC offset

            System.TimeSpan offsetBefore = GetUtcOffset(time);
            System.DateTime local        = time.Add(offsetBefore);

            DaylightTime daylight = GetDaylightChanges(time.Year);

            // Check whether the new time falls into the changeover period between
            // standard time and daylight savings time and adjust accordingly.

            if (local >= daylight.Start && local <= daylight.Start + daylight.Delta)
            {
                return(local.Add(daylight.Delta));
            }
            else
            {
                // Get the new offset and if it's different from the original one
                // (which would happen when going from daylight savings time to
                // standard time) adjust accordingly.

                System.TimeSpan offsetAfter = GetUtcOffset(local);
                return(local.Add(offsetAfter - offsetBefore));
            }
        }
        public static System.DateTime ToDateTimeFromJavaTime(this long _time)
        {
            System.TimeSpan _timeSpanned = System.TimeSpan.FromMilliseconds(_time);
            System.DateTime _startDate   = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
            System.DateTime _dateTime    = _startDate.Add(_timeSpanned);

            return(_dateTime);
        }
		public static System.DateTime ToDateTimeFromJavaTime(this long _time)
		{
			System.TimeSpan _timeSpanned 	= System.TimeSpan.FromMilliseconds(_time);
			System.DateTime _startDate		= new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
			System.DateTime _dateTime 		= _startDate.Add(_timeSpanned);
			
			return _dateTime;
		}
Ejemplo n.º 4
0
        /// <summary>Update current time, and try to trigger event.</summary>
        /// <param name="newCurrent"></param>
        private void TriggerEventIfCrossSession(DateTime newCurrent)
        {
            if (newCurrent == m_Current)
            {
                return;
            }

            DateTime oldCurrent = m_Current;

            m_Current = newCurrent;
            if (lastSession < newCurrent && newCurrent < nextSession)
            {
                // Debug.Log("Within session");
            }
            else if (newCurrent >= nextSession)
            {
                // Debug.Log("Pass session detected.");
                int      diff           = 0;
                DateTime oldNextSession = nextSession;
                CalculateSession();
                while (m_Current > oldNextSession && diff < int.MaxValue)
                {
                    oldNextSession = oldNextSession.Add(oneSession);
                    diff++;
                }

                Debug.LogFormat("Session updated: <color=green>Diff {0}</color>\n\rLast Current {1:G}\n\rCurrent {2:G}, \n\n\rLast Session {3:G}\n\rNext Session {4:G}\n\n\rOne Session {5:c}\n", diff, oldCurrent, m_Current, lastSession, nextSession, oneSession);
                if (EVENT_SessionChanged != null)
                {
                    EVENT_SessionChanged(oldCurrent, m_Current, diff);
                }
            }
            // The latest time(newCurrent) are smaller than the record that we had, back to the future.
            else             // if (newCurrent < oldCurrent)
            {
                CalculateSession();
                if (newCurrent < lastSession)
                {
                    Debug.LogErrorFormat("Time traveler detected := Session Jumpped.\ncurrent : {0:G} -> {1:G},\nLast session : {2:G}\nNext Session : {3:G}\nOne session : {4:c}", m_Current, newCurrent, lastSession, nextSession, oneSession);
                }
                else
                {
                    Debug.LogWarningFormat("Time traveler detected := within session.\ncurrent : {0:G} -> {1:G},\nLast session : {2:G}\nNext Session : {3:G}\nOne session : {4:c}", m_Current, newCurrent, lastSession, nextSession, oneSession);
                }

                if (EVENT_SessionChanged != null)
                {
                    EVENT_SessionChanged(oldCurrent, m_Current, -1);
                }
            }
        }
        public void Add_ShouldMimicSystem()
        {
            var anyTimeSpanTicks = 100;
            var anyDateTimeTicks = 200;

            var anyTimeSpan = new Abstractions.TimeSpan(anyTimeSpanTicks);
            var sut = new Abstractions.DateTime(anyDateTimeTicks);

            var anySystemTimeSpan = new System.TimeSpan(anyTimeSpanTicks);
            var anySystemDateTime = new System.DateTime(anyDateTimeTicks);
            var expectedResult = anySystemDateTime.Add(anySystemTimeSpan); ;

            //  Act.
            var res = sut.Add(anyTimeSpan);

            //  Assert.
            AssertEquals(expectedResult, res);
        }
 public static IEnumerable <System.DateTime> Range(this System.DateTime startDate, System.TimeSpan duration, System.TimeSpan interval)
 {
     return(startDate.Range(startDate.Add(duration), interval));
 }