/// <summary>
        /// Articulates a given TimeSpan with a given accuracy
        /// </summary>
        /// <param name="span">The TimeSpan to articulate</param>
        /// <param name="accuracy">Accuracy Flags</param>
        public static String Articulate(TimeSpan span, ETemporalGroupFlag accuracy)
        {
            // populate a list with temporalgroupings. Each temporal grouping
            // represents a particular element of the articulation, ordered
            // according to the temporal duration of each element.

            List <TemporalGrouping> lGroupingCollection = new List <TemporalGrouping>(4);

            // foreach possible temporal type (day/hour/minute etc.)
            foreach (ETemporalGroupFlag lType in _mGroupTypes)
            {
                // if the temporal type isn't specified in the accuracy, skip.
                if ((accuracy & lType) != lType)
                {
                    continue;
                }

                // get the timespan for this temporal type
                TimeSpan lTimeSpan = TimeSpanAttribute.RetrieveAttribute(lType).GetTimeSpan();

                if (span.Ticks >= lTimeSpan.Ticks)
                {
                    // divide the current timespan with the temporal group span
                    Int32 magnitude = (Int32)(span.Ticks / lTimeSpan.Ticks);

                    lGroupingCollection.Add(new TemporalGrouping(lType, magnitude));

                    span = new TimeSpan(span.Ticks % lTimeSpan.Ticks);
                }
            }

            return(Textify(lGroupingCollection));
        }
 internal TemporalGrouping(ETemporalGroupFlag type, Int32 magnitude)
 {
     this.Type      = type;
     this.Magnitude = magnitude;
 }
Example #3
0
 public static String ToDescription(this TimeSpan value, ETemporalGroupFlag accuracy)
 {
     Contract.Requires(value != null);
     return(TimeSpanArticulator.Articulate(value, accuracy));
 }