Zuff

Zuff

  • NA
  • 2
  • 0

What's wrong with my sorting?

Aug 5 2008 12:10 AM
Hi all,

    I can't really figure out what wrong with my sorting.

        private void SortGraph(ABPMBPResult value)
        {           
            if (value == null)
                return;
            List<BPData> data = value.ToList<BPData>();
            data.Sort(delegate(BPData bp1, BPData bp2)
            {
                return ConvertX(bp1).CompareTo(ConvertX(bp2));
            }
            );
        }


         private int ConvertX(BPData value) {
            DateTime dt = value.DateTime;
            if (dt.Hour >= 0 &&
                dt.Hour < 12)
            {
              
                return (dt.Hour + 12) * 300 + dt.Minute * 5 + 700;
            }
            else
            {              
                return (dt.Hour - 12) * 300 + dt.Minute * 5 + 700;
            }
        }


"All work well" if my (ABPMBPResult value) starts after 12 noon, however, if it starts in the morning, then the sorting is wrong. I presume that my sorting is not really sorting in the ascending order. 12noon, 1pm, .... 12 midnight,  1am .... 6am .... 9, ... 1159am

Thanks and Best Regards,
Zuff