Exemple #1
0
        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (format == null || format == "")
            {
                return(ToString());
            }

            if (char.IsNumber(format, format.Length - 1))
            {
                string lastChar = format.Substring(format.Length - 1, 1);
                switch (format.Substring(0, format.Length - 1))
                {
                case "D":
                    return(String.Format(formatProvider, "{0}{1}°", (IsPositive ? '+' : '-'), AbsDegrees.ToString("F" + lastChar, formatProvider)));

                case "DM":
                    return(String.Format(formatProvider, "{0}{1}°{2}\'", (IsPositive ? '+' : '-'),
                                         Hour, DecimalMinutes.ToString("F" + lastChar, formatProvider)));

                case "DMS":
                    return(String.Format(formatProvider, "{0}{1}°{2}\'{3}\"", (IsPositive ? '+' : '-'),
                                         Hour, Minute, Seconds.ToString("F" + lastChar, formatProvider)));

                case "M":
                    return(String.Format(formatProvider, "{0}\'", TotalMinutes.ToString("F" + lastChar, formatProvider)));

                case "MS":
                    return(String.Format(formatProvider, "{0}\'{1}\"", Minute, Seconds.ToString("F" + lastChar, formatProvider)));

                case "S":
                    return(String.Format(formatProvider, "{0}\"", totalSeconds.ToString("F" + lastChar, formatProvider)));

                default:
                    throw new FormatException("Format Exception of Angle.ToString(): " + format);
                }
            }
            else
            {
                if (format == "DMs")
                {
                    return(String.Format(formatProvider, "{0}{1:D2}°{2:D2}\'{3,2:F0}\"", IsPositive ? '+' : '-', Hour, Minute, Seconds));
                }
                else
                {
                    return(ToString(format + "2", formatProvider));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// フォーマットに基づいて文字列を生成する
        /// </summary>
        /// <param name="format">
        /// フォーマット
        /// %h 時
        /// %m 分
        /// %s 秒
        /// %d 日
        /// %w 週の文字(例:Mon)
        /// %S 秒の通算
        /// %M 分の通算
        /// %H 時の通算
        /// %D 日の通算
        /// %DI 日の通算(整数部のみ)
        /// </param>
        /// <returns></returns>
        //
        public string ToString(string format)
        {
            format = format.Replace("%h", Hour.ToString("00"));
            format = format.Replace("%m", Minute.ToString("00"));
            format = format.Replace("%s", Second.ToString("00"));
            format = format.Replace("%d", Day.ToString());
            var day = Day;

            if (day < 0)
            {
                day = (day % DateTimeEx._dayStrings.Length) + 7;
            }
            format = format.Replace("%w", DateTimeEx._dayStrings[day % DateTimeEx._dayStrings.Length]);
            format = format.Replace("%H", TotalHours.ToString());
            format = format.Replace("%S", TotalSeconds.ToString());
            format = format.Replace("%M", TotalMinutes.ToString());
            format = format.Replace("%DI", ((int)TotalDays).ToString());    // 日を整数化(切り捨て)
            format = format.Replace("%D", TotalDays.ToString());
            return(format);
        }
Exemple #3
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + Years.GetHashCode();

                hashCode = hashCode * 59 + Months.GetHashCode();

                hashCode = hashCode * 59 + Days.GetHashCode();

                hashCode = hashCode * 59 + Hours.GetHashCode();

                hashCode = hashCode * 59 + Minutes.GetHashCode();

                hashCode = hashCode * 59 + Milliseconds.GetHashCode();

                hashCode = hashCode * 59 + TotalYears.GetHashCode();

                hashCode = hashCode * 59 + TotalMonths.GetHashCode();

                hashCode = hashCode * 59 + TotalDays.GetHashCode();

                hashCode = hashCode * 59 + TotalHours.GetHashCode();

                hashCode = hashCode * 59 + TotalMinutes.GetHashCode();

                hashCode = hashCode * 59 + TotalSeconds.GetHashCode();

                hashCode = hashCode * 59 + TotalMilliseconds.GetHashCode();

                hashCode = hashCode * 59 + Ticks.GetHashCode();
                return(hashCode);
            }
        }
Exemple #4
0
        /// <summary>
        /// Returns true if OutputDateDifference instances are equal
        /// </summary>
        /// <param name="other">Instance of OutputDateDifference to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(OutputDateDifference other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Years == other.Years ||

                     Years.Equals(other.Years)
                     ) &&
                 (
                     Months == other.Months ||

                     Months.Equals(other.Months)
                 ) &&
                 (
                     Days == other.Days ||

                     Days.Equals(other.Days)
                 ) &&
                 (
                     Hours == other.Hours ||

                     Hours.Equals(other.Hours)
                 ) &&
                 (
                     Minutes == other.Minutes ||

                     Minutes.Equals(other.Minutes)
                 ) &&
                 (
                     Milliseconds == other.Milliseconds ||

                     Milliseconds.Equals(other.Milliseconds)
                 ) &&
                 (
                     TotalYears == other.TotalYears ||

                     TotalYears.Equals(other.TotalYears)
                 ) &&
                 (
                     TotalMonths == other.TotalMonths ||

                     TotalMonths.Equals(other.TotalMonths)
                 ) &&
                 (
                     TotalDays == other.TotalDays ||

                     TotalDays.Equals(other.TotalDays)
                 ) &&
                 (
                     TotalHours == other.TotalHours ||

                     TotalHours.Equals(other.TotalHours)
                 ) &&
                 (
                     TotalMinutes == other.TotalMinutes ||

                     TotalMinutes.Equals(other.TotalMinutes)
                 ) &&
                 (
                     TotalSeconds == other.TotalSeconds ||

                     TotalSeconds.Equals(other.TotalSeconds)
                 ) &&
                 (
                     TotalMilliseconds == other.TotalMilliseconds ||

                     TotalMilliseconds.Equals(other.TotalMilliseconds)
                 ) &&
                 (
                     Ticks == other.Ticks ||

                     Ticks.Equals(other.Ticks)
                 ));
        }