Пример #1
0
        /// <summary>
        /// Converts the value of the current <see cref="Date"/> object to its equivalent string representation.
        /// </summary>
        /// <returns> A string representation of the value of the current <see cref="Date"/> object.</returns>
        public readonly override string ToString()
        {
            switch (Format)
            {
            case DateFormat.Day:
                return(Day?.ToString());

            case DateFormat.Month:
                return(Month?.ToString());

            case DateFormat.Quarter:
                return(Quarter?.ToString());

            case DateFormat.SemiAnnual:
                return(SemiAnnual?.ToString());

            case DateFormat.Tertiary:
                return(Tertiary?.ToString());

            case DateFormat.Week:
                return(Week?.ToString());

            case DateFormat.Year:
                return(Year.ToString());

            default:
                Debug.Fail($"Unknown {nameof(DateFormat)}.");
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>A 32-bit signed integer hash code.</returns>
        public readonly override int GetHashCode()
        {
            switch (Format)
            {
            case DateFormat.Day:
                return(Day.GetHashCode());

            case DateFormat.Month:
                return(Month.GetHashCode());

            case DateFormat.Quarter:
                return(Quarter.GetHashCode());

            case DateFormat.SemiAnnual:
                return(SemiAnnual.GetHashCode());

            case DateFormat.Tertiary:
                return(Tertiary.GetHashCode());

            case DateFormat.Week:
                return(Week.GetHashCode());

            case DateFormat.Year:
                return(Year.GetHashCode());

            default:
                Debug.Fail($"Unknown {nameof(DateFormat)}.");
                return(0);
            }
        }
Пример #3
0
 /// <summary>
 /// Creates an instance of a <see cref="Date"/> with a format of YYYY-Hx (<see cref="DateFormat.SemiAnnual"/>) where x is a semi-annual between 1 and 2.
 /// </summary>
 /// <param name="semiAnnual">A specific semi-annual of a specific year.</param>
 public Date(SemiAnnual semiAnnual)
 {
     Day        = default;
     Month      = default;
     Quarter    = default;
     SemiAnnual = semiAnnual;
     Tertiary   = default;
     Year       = semiAnnual.Year;
     Week       = default;
     Format     = DateFormat.SemiAnnual;
 }