예제 #1
0
        }         // ElapsedSeconds

        // ----------------------------------------------------------------------
        public string GetDescription(int precision = int.MaxValue, ITimeFormatter formatter = null)
        {
            if (precision < 1)
            {
                throw new ArgumentOutOfRangeException("precision");
            }

            formatter = formatter ?? TimeFormatter.Instance;

            int[] elapsedItems = new int[6];
            elapsedItems[0] = ElapsedYears;
            elapsedItems[1] = ElapsedMonths;
            elapsedItems[2] = ElapsedDays;
            elapsedItems[3] = ElapsedHours;
            elapsedItems[4] = ElapsedMinutes;
            elapsedItems[5] = ElapsedSeconds;

            if (precision <= elapsedItems.Length - 1)
            {
                for (int i = precision; i < elapsedItems.Length; i++)
                {
                    elapsedItems[i] = 0;
                }
            }

            return(formatter.GetDuration(
                       elapsedItems[0],
                       elapsedItems[1],
                       elapsedItems[2],
                       elapsedItems[3],
                       elapsedItems[4],
                       elapsedItems[5]));
        }         // GetDescription
예제 #2
0
        public string GetDiscription(int?precision = null, ITimeFormatter formatter = null)
        {
            precision = precision ?? int.MaxValue;
            formatter = formatter ?? TimeFormatter.Instance;

            precision.Value.ShouldBePositive("precision");

            var elapsedTimes = new[]
            {
                ElapsedYears,
                ElapsedMonths,
                ElapsedDays,
                ElapsedHours,
                ElapsedMinutes,
                ElapsedSeconds
            };

            if (precision <= elapsedTimes.Length - 1)
            {
                for (var i = precision.Value; i < elapsedTimes.Length; i++)
                {
                    elapsedTimes[i] = 0;
                }
            }

            return(formatter.GetDuration(elapsedTimes[0],
                                         elapsedTimes[1],
                                         elapsedTimes[2],
                                         elapsedTimes[3],
                                         elapsedTimes[4],
                                         elapsedTimes[5]));
        }
예제 #3
0
        // ----------------------------------------------------------------------
        public string GetDescription( int precision = int.MaxValue, ITimeFormatter formatter = null )
        {
            if ( precision < 1 )
            {
                throw new ArgumentOutOfRangeException( "precision" );
            }

            formatter = formatter ?? TimeFormatter.Instance;

            int[] elapsedItems = new int[ 6 ];
            elapsedItems[ 0 ] = ElapsedYears;
            elapsedItems[ 1 ] = ElapsedMonths;
            elapsedItems[ 2 ] = ElapsedDays;
            elapsedItems[ 3 ] = ElapsedHours;
            elapsedItems[ 4 ] = ElapsedMinutes;
            elapsedItems[ 5 ] = ElapsedSeconds;

            if ( precision <= elapsedItems.Length - 1 )
            {
                for ( int i = precision; i < elapsedItems.Length; i++ )
                {
                    elapsedItems[ i ] = 0;
                }
            }

            return formatter.GetDuration(
                elapsedItems[ 0 ],
                elapsedItems[ 1 ],
                elapsedItems[ 2 ],
                elapsedItems[ 3 ],
                elapsedItems[ 4 ],
                elapsedItems[ 5 ] );
        }