示例#1
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;
     }
 }
示例#2
0
 //getting date difference in second, menute, hours, days, months, and years
 //this will serve for time ago
 /// <summary>
 /// <para>Returns the value of an int representing the value of the year difference between</para>
 /// <para>this instance and the timeStamp. -ve returns means the timeStamp is ahead of this</para>
 /// </summary>
 /// <returns>int YearsDifference</returns>
 public int YearsDifference(TimeStamp timeStamp)
 {
     return Math.Abs(Year - timeStamp.Year);
 }
示例#3
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;
        }
示例#4
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;
        }
示例#5
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;
        }
示例#6
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;
        }
示例#7
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;
        }
示例#8
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;
        }
示例#9
0
 /// <summary>
 /// <para>Returns a new value of TimeStamp that add the specified TimeStamp to this instance(which will not be changed)</para>
 /// </summary>
 /// <returns>TimeStamp timeStamp</returns>
 /// 
 public TimeStamp Add(TimeStamp timeStamp)
 {
     return addTimeUnits(timeStamp.Year, timeStamp.Month, timeStamp.Day, timeStamp.Hour, timeStamp.Minute, timeStamp.Second, timeStamp.MilliSecond);
 }