/// <param name="span">The TimeSpan to articulate</param> /// <param name="accuracy">Accuracy Flags</param> public static string Articulate(TimeSpan span, TemporalGroupType accuracy) { // populate a list with temporalgroupings. Each temporal grouping // represents a particular element of the articulation, ordered // accoring to the temporal duration of each element. List<TemporalGrouping> groupings = new List<TemporalGrouping>(4); // foreach possible temporal type (day/hour/minute etc.) foreach (TemporalGroupType type in groupTypes) { // if the temporal type isn't specified in the accuracy, skip. if ((accuracy & type) != type) continue; // get the timespan for this temporal type TimeSpan ts = TimeSpanAttribute.RetrieveAttribute(type).GetTimeSpan(); if (span.Ticks >= ts.Ticks) { // divide the current timespan with the temporal group span int magnitude = (int)(span.Ticks / ts.Ticks); groupings.Add(new TemporalGrouping(type, magnitude)); span = new TimeSpan(span.Ticks % ts.Ticks); } } return Textify(groupings); }
internal TemporalGrouping( TemporalGroupType type, int magnitude ) { this.Type = type; this.Magnitude = magnitude; }