zoukankan      html  css  js  c++  java
  • 查找正序排列的List中缺失的日期数据的一个算法

    Code:

            public List<DateTime> getMissDateData()
            {
    
                DateTime[] keys = { DateTime.Now.AddDays(-5), DateTime.Now.AddDays(-3), DateTime.Now.AddDays(-1), };
                List<DateTime> missingDate = new List<DateTime>();
                for (int i = 0; i < keys.Length; i++)
                {
                    logger.Info("Orginal data:"+keys[i]);
                }
    
                if (keys.Length > 0)
                {
                    DateTime firstDate = keys[0];
                    if (firstDate.Day > 1)
                    {
                        int missingDateInt = firstDate.Day - 1;
                        for (int i = missingDateInt; i > 0; i--)
                        {
                            missingDate.Add(firstDate.AddDays(-i));
                        }
                    }
                    int keysLength = (keys[keys.Length - 1] - keys[0]).Days;
    
                    DateTime dtTemp = keys[0];
                    // firstDate = keys[0];
                    int count = keys.Length;
                    for (int i = 0; i < count; i++)
                    {
                        Console.WriteLine(dtTemp.ToString(keys[i].ToString("yyyy-MM-dd HH:mm:ss")));
                        while (DateTime.Compare(keys[i], dtTemp) != 0)
                        {
                            logger.InfoFormat("Actual Date:{0};  The date of the cumulative:{1}", keys[i].ToShortDateString(), dtTemp.ToShortDateString());
                            logger.InfoFormat("{0}", DateTime.Compare(keys[i], dtTemp));
                            //Console.WriteLine(String.Format("Actual Date:{0};  The date of the cumulative:{1}", keys[i].ToShortDateString(), dtTemp.ToShortDateString()));
                           // Console.WriteLine(String.Format("{0}", DateTime.Compare(keys[i], dtTemp)));
                            missingDate.Add(dtTemp);
                            dtTemp = dtTemp.AddDays(1);
                        }
                        dtTemp = dtTemp.AddDays(1);
                    }
                }
                else
                {
                    logger.InfoFormat("Has no new data:{0}", keys.Length);
                   // Console.WriteLine(String.Format("Has no new data:{0}", keys.Length));
                }
    
                for (int i = 0; i < missingDate.Count; i++)
                {
                    logger.Info("Missing data:" + missingDate[i].ToShortDateString());
                    //Console.WriteLine("Missing data:" + missingDate[i].ToShortDateString());
                }
                return missingDate;
            }
    欢迎大家吐槽。
  • 相关阅读:
    HAProxy、Keepalived 在 Ocatvia 的应用实现与分析
    Octavia 的 HTTPS 与自建、签发 CA 证书
    Octavia 创建 loadbalancer 的实现与分析
    OpenStack Rally 质量评估与自动化测试利器
    自建 CA 中心并签发 CA 证书
    Failed building wheel for netifaces
    通过 vSphere WS API 获取 vCenter Datastore Provisioned Space 置备空间
    OpenStack Placement Project
    我们建了一个 Golang 硬核技术交流群(内含视频福利)
    没有图形界面的软件有什么用?
  • 原文地址:https://www.cnblogs.com/softidea/p/3425628.html
Copyright © 2011-2022 走看看