예제 #1
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the extra minute difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the second is ahead</para>
        /// </summary>
        /// <returns>int MinuteDifferenc</returns>
        public int SecondsDifference(TimeStamp timeStamp)
        {
            int diff = 0;

            if (ToLong() > timeStamp.ToLong())
            {
                //time ago. first = this
                if (Second < timeStamp.Second)
                {
                    diff = timeStamp.Second - Second;
                    if (MilliSecond > timeStamp.MilliSecond)
                    {
                        diff -= 1;
                    }
                }
                else
                {
                    diff = (60 - timeStamp.Second) + Second;
                }
            }
            else
            {
                //time ahead. first = timeStamp
            }
            return(diff);
        }
예제 #2
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the extra minute difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the minute is ahead</para>
        /// </summary>
        /// <returns>int MinuteDifferenc</returns>
        public int MinuteDifferenc(TimeStamp timeStamp)
        {
            int diff = 0;

            if (ToLong() > timeStamp.ToLong())
            {
                //time ago. first = this
                if (Minute < timeStamp.Minute)
                {
                    diff = timeStamp.Minute - Minute;
                    if (Second > timeStamp.Second)
                    {
                        diff -= 1;
                    }
                }
                else
                {
                    diff = (60 - timeStamp.Minute) + Minute;
                }
            }
            else
            {
                //time ahead. first = timeStamp
            }
            return(diff);
        }
예제 #3
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the extra hour difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the hour is ahead</para>
        /// </summary>
        /// <returns>int HourDifference</returns>
        public int HourDifference(TimeStamp timeStamp)
        {
            int diff = 0;

            if (ToLong() > timeStamp.ToLong())
            {
                //time ago. first = this
                if (Hour < timeStamp.Hour)
                {
                    diff = timeStamp.Hour - Hour;
                    if (Minute > timeStamp.Minute)
                    {
                        diff -= 1;
                    }
                }
                else
                {
                    diff = (24 - timeStamp.Hour) + Hour;
                }
            }
            else
            {
                //time ahead. first = timeStamp
            }
            return(diff);
        }
예제 #4
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the exta day difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the day is ahead</para>
        /// </summary>
        /// <returns>int DaysDifference</returns>
        public int DaysDifference(TimeStamp timeStamp)
        {
            int diff = 0;

            TimeStamp t1, t2;

            if (ToLong() > timeStamp.ToLong())
            {
                t1 = this;
                t2 = timeStamp;
            }
            else
            {
                t1 = timeStamp;
                t2 = this;
            }

            if (t1.Month == t2.Month)
            {
                diff = t1.Day - t2.Day;
            }
            else
            {
                diff = (DateTime.DaysInMonth(t2.Year, t2.Month) - t2.Day) + t1.Day;
            }

            return(diff);
        }
예제 #5
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the extra month difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the month is ahead</para>
        /// </summary>
        /// <returns>int MonthDifference</returns>
        public int MonthDifference(TimeStamp timeStamp)
        {
            int diff = 0;

            if (ToLong() > timeStamp.ToLong())
            {
                //time ago. first = this
                if (Month < timeStamp.Month)
                {
                    diff = timeStamp.Month - Month;
                    if (Day > timeStamp.Day)
                    {
                        diff -= 1;
                    }
                }
                else
                {
                    diff = (12 - timeStamp.Month) + Month;
                }
            }
            else
            {
                //time ahead. first = timeStamp
            }
            return(diff);
        }
예제 #6
0
 //from time stamp
 /// <summary>
 /// <para>Initialize a new instance of TimeStamp class of a specified long timeStamp</para>
 /// </summary>
 /// <returns>TimeStamp timeStamp</returns>
 public TimeStamp(long timeStamp, bool earliest = false)
 {
     if (!earliest)
     {
         _timeStamp = timeStamp;
         _date = GetDate(_timeStamp);
     }
     else
     {
         var dt = GetDate(timeStamp);
         var ts = new TimeStamp(dt, true);
         _timeStamp = ts.ToLong();
         _date = ts.Date;
     }
 }
예제 #7
0
 //from time stamp
 /// <summary>
 /// <para>Initialize a new instance of TimeStamp class of a specified long timeStamp</para>
 /// </summary>
 /// <returns>TimeStamp timeStamp</returns>
 public TimeStamp(long timeStamp, bool earliest = false)
 {
     if (!earliest)
     {
         _timeStamp = timeStamp;
         _date      = GetDate(_timeStamp);
     }
     else
     {
         var dt = GetDate(timeStamp);
         var ts = new TimeStamp(dt, true);
         _timeStamp = ts.ToLong();
         _date      = ts.Date;
     }
 }
예제 #8
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the extra minute difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the second is ahead</para>
        /// </summary>
        /// <returns>int MinuteDifferenc</returns>
        public int SecondsDifference(TimeStamp timeStamp)
        {
            int diff = 0;
            if (ToLong() > timeStamp.ToLong())
            {
                //time ago. first = this
                if (Second < timeStamp.Second)
                {
                    diff = timeStamp.Second - Second;
                    if (MilliSecond > timeStamp.MilliSecond)
                        diff -= 1;
                }
                else
                {
                    diff = (60 - timeStamp.Second) + Second;
                }

            }
            else
            {
                //time ahead. first = timeStamp
            }
            return diff;
        }
예제 #9
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the extra month difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the month is ahead</para>
        /// </summary>
        /// <returns>int MonthDifference</returns>
        public int MonthDifference(TimeStamp timeStamp)
        {
            int diff = 0;
            if (ToLong() > timeStamp.ToLong())
            {
                //time ago. first = this
                if (Month < timeStamp.Month)
                {
                    diff = timeStamp.Month - Month;
                    if (Day > timeStamp.Day)
                        diff -= 1;
                }
                else
                {
                    diff = (12 - timeStamp.Month) + Month;
                }

            }
            else
            {
                //time ahead. first = timeStamp
            }
            return diff;
        }
예제 #10
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the extra minute difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the minute is ahead</para>
        /// </summary>
        /// <returns>int MinuteDifferenc</returns>
        public int MinuteDifferenc(TimeStamp timeStamp)
        {
            int diff = 0;
            if (ToLong() > timeStamp.ToLong())
            {
                //time ago. first = this
                if (Minute < timeStamp.Minute)
                {
                    diff = timeStamp.Minute - Minute;
                    if (Second > timeStamp.Second)
                        diff -= 1;
                }
                else
                {
                    diff = (60 - timeStamp.Minute) + Minute;
                }

            }
            else
            {
                //time ahead. first = timeStamp
            }
            return diff;
        }
예제 #11
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the minute difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the second is ahead</para>
        /// </summary>
        /// <returns>int MinuteDifferenc</returns>
        public int MilliSecondsDifference(TimeStamp timeStamp)
        {
            int diff = 0;
            if (ToLong() > timeStamp.ToLong())
            {
                //time ago. first = this
                if (MilliSecond < timeStamp.MilliSecond)
                    diff = timeStamp.MilliSecond - MilliSecond;
                else
                {
                    diff = (1000 - timeStamp.MilliSecond) + MilliSecond;
                }

            }
            else
            {
                //time ahead. first = timeStamp
            }
            return diff;
        }
예제 #12
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the extra hour difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the hour is ahead</para>
        /// </summary>
        /// <returns>int HourDifference</returns>
        public int HourDifference(TimeStamp timeStamp)
        {
            int diff = 0;
            if (ToLong() > timeStamp.ToLong())
            {
                //time ago. first = this
                if (Hour < timeStamp.Hour)
                {
                    diff = timeStamp.Hour - Hour;
                    if (Minute > timeStamp.Minute)
                        diff -= 1;
                }
                else
                {
                    diff = (24 - timeStamp.Hour) + Hour;
                }

            }
            else
            {
                //time ahead. first = timeStamp
            }
            return diff;
        }
예제 #13
0
        /// <summary>
        /// <para>Returns the value of an int representing the value of the exta day difference</para>
        /// <para> between this instance and the timeStamp. -ve return means the day is ahead</para>
        /// </summary>
        /// <returns>int DaysDifference</returns>
        public int DaysDifference(TimeStamp timeStamp)
        {
            int diff = 0;

            TimeStamp t1, t2;
            if (ToLong() > timeStamp.ToLong())
            {
                t1 = this;
                t2 = timeStamp;
            }
            else
            {
                t1 = timeStamp;
                t2 = this;
            }

            if (t1.Month == t2.Month)
                diff = t1.Day - t2.Day;
            else
                diff = (DateTime.DaysInMonth(t2.Year, t2.Month) - t2.Day) + t1.Day;

            return diff;
        }