Exemple #1
0
        /// <summary>
        /// Compares two <c>Period</c> values and returns an integer that indicates their relationship
        /// </summary>
        /// <param name="p1">The first period</param>
        /// <param name="p2">The second period</param>
        /// <returns>Returns -1 if the first instance is less than the second, 0 if they are equal, or 1 if the
        /// first instance is greater than the second.</returns>
        public static int Compare(Period p1, Period p2)
        {
            // Cast as object for null checks or it goes recursive
            if((object)p1 == null && (object)p2 == null)
                return 0;

            if((object)p1 != null && (object)p2 == null)
                return 1;

            if((object)p1 == null && (object)p2 != null)
                return -1;

            if(p1.StartDateTime > p2.StartDateTime)
                return 1;

            if(p1.StartDateTime < p2.StartDateTime)
                return -1;

            if(p1.EndDateTime > p2.EndDateTime)
                return 1;

            if(p1.EndDateTime < p2.EndDateTime)
                return -1;

            return 0;
        }
Exemple #2
0
        //=====================================================================

        /// <summary>
        /// Construct a new <c>Period</c> object from a period specified in a string. Parameters specify the
        /// period and the variable where the new <c>Period</c> object is returned.
        /// </summary>
        /// <param name="period">The string that specifies the period.</param>
        /// <param name="result">When this method returns, this contains an object that represents the period
        /// specified by s, or an empty period object if the conversion failed. This parameter is passed in
        /// uninitialized.</param>
        /// <returns>True if successfully parsed or false if the value could not be parsed</returns>
        public static bool TryParse(string period, out Period result)
        {
            try
            {
                result = new Period(period);
            }
            catch(ArgumentException )
            {
                result = new Period();
                return false;
            }
            catch(OverflowException )
            {
                result = new Period();
                return false;
            }

            return true;
        }
Exemple #3
0
        //=====================================================================

        /// <summary>
        /// Returns a value indicating whether two specified instances of <c>Period</c> are equal
        /// </summary>
        /// <param name="p1">The first period to compare</param>
        /// <param name="p2">The second period to compare</param>
        /// <returns>Returns true if the periods are equal, false if they are not</returns>
        public static bool Equals(Period p1, Period p2)
        {
            if((object)p1 == null && (object)p2 == null)
                return true;

            if((object)p1 == null)
                return false;

            return p1.Equals(p2);
        }
Exemple #4
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="period">The period to copy</param>
 public Period(Period period)
 {
     if(period != null)
     {
         this.StartDateTime = period.StartDateTime;
         this.EndDateTime = period.EndDateTime;
         this.Format = period.Format;
     }
 }