需求:消费者投诉企业,企业在2个工作日之内做出应答。

分析:1.工作日要刨去周末和法定节假日,而且每年的节假日不一样。

2.消费者可以在任意时间发起投诉,如果在非工作日发起了投诉,那么计算时间应该从工作日开始计算,就要刨去当日的时和分。

以下是代码:

public class HolidayHelper

    {

        /// <summary>

        /// 判断法定工作日

        /// </summary>

        /// <param name="dt">时间</param>

        /// <returns>0上班,1不需要上班的周末(也包括节假日),2法定节假日</returns>

        public static int IsHolidayOrWeek(DateTime dt)

        {

            //特殊的周末(周末却上班)

            string[] specalWeek2009 = { "0104", "0124", "0201", "0531", "0927", "1010" };

            string[] specalWeek2010 = { "0220", "0221", "0612", "0613", "0919", "0925", "0926", "1009" };

            string[] specalWeek2011 = { "0130", "0212", "0402", "1008", "1009" };

            string[] specalWeek2012 = { "0129", "0331", "0401", "0428", "0929" };

            string[] specalWeek2013 = { "0105", "0106", "0216", "0217", "0407", "0427", "0428", "0608", "0609", "0922", "0929", "1012" };

            string[] specalWeek2014 = { "0126", "0208", "0504", "0928", "1011" };

            string[] specalWeek2015 = { "0104", "0215", "0228", "0906", "1010" };

            string[] specalWeek2016 = { "0206", "0214", "0612", "0918", "1008", "1009" };

            string[] specalWeek2017 = { "0122", "0204", "0401", "0527", "0930" };

            //法定假日

            string[] holiday2009 = { "0101", "0102", "0103", "0125", "0126", "0127", "0128", "0129", "0130", "0131", "0404", "0405", "0406", "0501", "0502", "0503", "0528", "0529", "0530", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", };

            string[] holiday2010 = { "0101", "0102", "0103", "0213", "0214", "0215", "0216", "0217", "0218", "0219", "0403", "0404", "0405", "0501", "0502", "0503", "0614", "0615", "0616", "0922", "0923", "0924", "1001", "1002", "1003", "1004", "1005", "1006", "1007" };

            string[] holiday2011 = { "0101", "0102", "0103", "0202", "0203", "0204", "0205", "0206", "0207", "0208", "0403", "0404", "0405", "0430", "0501", "0502", "0604", "0605", "0606", "0910", "0911", "0912", "1001", "1002", "1003", "1004", "1005", "1006", "1007", };

            string[] holiday2012 = { "0101", "0102", "0103", "0122", "0123", "0124", "0125", "0126", "0127", "0128", "0402", "0403", "0404", "0429", "0430", "0501", "0622", "0623", "0624", "0930", "1001", "1002", "1003", "1004", "1005", "1006", "1007", };

            string[] holiday2013 = { "0101", "0102", "0103", "0209", "0210", "0211", "0212", "0213", "0214", "0215", "0404", "0405", "0406", "0429", "0430", "0501", "0610", "0611", "0612", "0919", "0920", "0921", "1001", "1002", "1003", "1004", "1005", "1006", "1007", };

            string[] holiday2014 = { "0101", "0131", "0201", "0202", "0203", "0204", "0205", "0206", "0405", "0406", "0407", "0501", "0502", "0503", "0602", "0908", "1001", "1002", "1003", "1004", "1005", "1006", "1007", };

            string[] holiday2015 = { "0101", "0102", "0103", "0218", "0219", "0220", "0221", "0222", "0223", "0224", "0404", "0405", "0406", "0501", "0502", "0503", "0620", "0621", "0622", "0903", "0904", "0905", "0927", "1001", "1002", "1003", "1004", "1005", "1006", "1007", };

            string[] holiday2016 = { "0101", "0207", "0208", "0209", "0210", "0211", "0212", "0213", "0404", "0501", "0502", "0609", "0610", "0611", "0915", "0916", "0917", "1001", "1002", "1003", "1004", "1005", "1006", "1007", };

            string[] holiday2017 = { "0101", "0102", "0127", "0128", "0129", "0130", "0131", "0201", "0202", "0403", "0404", "0501", "0529", "0530", "1001", "1002", "1003", "1004", "1005", "1006", };

            bool isHoildayOrWeek = false;

            //取年

            string weekYear = dt.Year.ToString();

            //取月日

            string[] weekDate = { dt.ToString("MMdd") };

            //判断周末

            if ((int)dt.DayOfWeek == 0 || (int)dt.DayOfWeek == 6)

            {

                //周末是否需要上班

                switch (weekYear)

                {

                    case "2009":

                        isHoildayOrWeek = specalWeek2009.Intersect(weekDate).Count() == 0;

                        break;

                    case "2010":

                        isHoildayOrWeek = specalWeek2010.Intersect(weekDate).Count() == 0;

                        break;

                    case "2011":

                        isHoildayOrWeek = specalWeek2011.Intersect(weekDate).Count() == 0;

                        break;

                    case "2012":

                        isHoildayOrWeek = specalWeek2012.Intersect(weekDate).Count() == 0;

                        break;

                    case "2013":

                        isHoildayOrWeek = specalWeek2013.Intersect(weekDate).Count() == 0;

                        break;

                    case "2014":

                        isHoildayOrWeek = specalWeek2014.Intersect(weekDate).Count() == 0;

                        break;

                    case "2015":

                        isHoildayOrWeek = specalWeek2015.Intersect(weekDate).Count() == 0;

                        break;

                    case "2016":

                        isHoildayOrWeek = specalWeek2016.Intersect(weekDate).Count() == 0;

                        break;

                    case "2017":

                        isHoildayOrWeek = specalWeek2017.Intersect(weekDate).Count() == 0;

                        break;

                }

            }

            if (isHoildayOrWeek)

            {

                return 1;

            }

            //判断法定节假日

            switch (weekYear)

            {

                case "2009":

                    isHoildayOrWeek = holiday2009.Intersect(weekDate).Count() > 0;

                    break;

                case "2010":

                    isHoildayOrWeek = holiday2010.Intersect(weekDate).Count() > 0;

                    break;

                case "2011":

                    isHoildayOrWeek = holiday2011.Intersect(weekDate).Count() > 0;

                    break;

                case "2012":

                    isHoildayOrWeek = holiday2012.Intersect(weekDate).Count() > 0;

                    break;

                case "2013":

                    isHoildayOrWeek = holiday2013.Intersect(weekDate).Count() > 0;

                    break;

                case "2014":

                    isHoildayOrWeek = holiday2014.Intersect(weekDate).Count() > 0;

                    break;

                case "2015":

                    isHoildayOrWeek = holiday2015.Intersect(weekDate).Count() > 0;

                    break;

                case "2016":

                    isHoildayOrWeek = holiday2016.Intersect(weekDate).Count() > 0;

                    break;

                case "2017":

                    isHoildayOrWeek = holiday2017.Intersect(weekDate).Count() > 0;

                    break;

            }

            if (isHoildayOrWeek)

            {

                return 2;

            }

            return 0;

        }

        /// <summary>

        /// 工作日时间差

        /// </summary>

        /// <param name="days">几个工作日后</param>

        /// <returns>延迟毫秒数</returns>

        public static double GetDelpyTime(int days)

        {

            int sign = 0;

            for (int i = 0; i < days; i++)

            {

                if (i == 0 && IsHolidayOrWeek(DateTime.Now.AddDays(i)) > 0)

                {

                    //非工作日发起的投诉,要抹掉小时和分钟                   

                    sign = 1;

                }

                if (IsHolidayOrWeek(DateTime.Now.AddDays(i)) > 0)

                {

                    days = days + 1;

                };

            }

            TimeSpan ts = new TimeSpan();

            if (sign == 1)

            {

                ts = (DateTime.Now.AddDays(days) - DateTime.Now.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute));

            }

            else

            {

                ts = DateTime.Now.AddDays(days) - DateTime.Now;

            }

            return ts.TotalMilliseconds;

        }

    }

C#跳过工作日,计算几个工作日之后到期的方法的更多相关文章

  1. Flink实时计算pv、uv的几种方法

    本文首发于:Java大数据与数据仓库,Flink实时计算pv.uv的几种方法 实时统计pv.uv是再常见不过的大数据统计需求了,前面出过一篇SparkStreaming实时统计pv,uv的案例,这里用 ...

  2. C++11用于计算函数对象返回类型的统一方法

    [C++11用于计算函数对象返回类型的统一方法] 模板 std::result_of 被TR1 引进且被 C++11 所采纳,可允许我们决定和使用一个仿函数其回返值的类别.底下,CalculusVer ...

  3. Java日期时间API系列38-----一种高效的工作日计算计算方法

    如果没有节日放假调休的话,工作日很好计算,周一到周五就是工作日,但因为有节日放假调休,使得这个计算需要外部放假安排数据来支持.计算原理: 先按照放假安排数据计算,再按照周一周五计算. 下面以Local ...

  4. PostgreSQL 当月最后一天的工作日 , 计算日期是星期几

    可以用pg自带函数select extract(dow from current_date),之所以没用主要是展示一下通过数学方法计算日期的原理. drop function if exists ge ...

  5. Servlet3.0 jsp跳转到Servlet 出现404错误的路径设置方法

    最近又遇到了这种问题,百度了好久,发现有人说要在action的路径里面写Servlet文件的绝对路径,比如说,单独打开servlet的地址为http://localhost:8080/TomcatTe ...

  6. form表单action提交表单,页面不跳转且表单数据含文件的处理方法

    在最近的项目中需要将含 input[type='file']的表单提交给后台 ,并且后台需要将文件存储在数据库中.之前所用的方法都是先将文件上传到七牛服务器上,然后七牛会返回文件的下载地址,在提交表单 ...

  7. iOS从App跳转至系统设置菜单各功能项的编写方法讲解

    跳到系统设置里的WiFi界面 info里面设置: 在项目中的info.plist中添加 URL types 并设置一项URL Schemes为prefs,如下图 代码: 复制代码 代码如下: NSUR ...

  8. 用Regex类计算一个字符串出现次数是最好方法【转载】

    我的一个朋友问我,怎么在c#或vb.net中,计算一个字符串中查找另一个字符串中出现的次数,他说在网上打了好多方法,我看了一下,有的是用replace的方法去实现,这种方法不是太好,占资源太大了.其实 ...

  9. 实现js浮点数加、减、乘、除的精确计算(网上很多文章里的方法是不能解决所有js浮点数计算误差的)

    最近做项目,要用到js的加.减.乘.除的计算,发现js浮点数计算会有一些误差. 网上有很多文章都有js浮点数计算误差的解决方法,说能解决这个问题,But…….比如一个加法函数,如下: function ...

随机推荐

  1. [原题复现]ByteCTF 2019 –WEB- Boring-Code[无参数rce、绕过filter_var(),等]

    简介  原题复现:  考察知识点:无参数命令执行.绕过filter_var(), preg_match()  线上平台:https://buuoj.cn(北京联合大学公开的CTF平台) 榆林学院内可使 ...

  2. Docker学习第三天(Docker数据卷管理)

    1.Docker数据卷管理 在Docker中,要想实现数据的持久化(所谓Docker的数据持久化即数据不随着Container的结束而结束),需要将数据从宿主机挂载到容器中.目前Docker提供了三种 ...

  3. go编译成exe后,打开出现闪退问题

    今天博主编译了一个go小脚本,编译完成后用自己电脑试了一下没有问题 然而,当换了一台电脑后,一样是win7系统64位,出现了闪退 于是乎博主疯狂百度 看到网上说   入口文件 的顶部改成  packa ...

  4. Vegas实战——如何导入导出视频

    Vegas作为一款专业的视频非编软件,在国内受到了很多用户的喜爱.小编认为,对于很多用户来说,他们选择sony vegas的一个原因是vegas在不论是从产品性能,还是使用效果上,都很容易被用户接受. ...

  5. 在CorelDRAW2019创建对称绘图模式

    对称绘图模式是CorelDRAW 2018推出的全新功能,在2019的版本中又得到了极大的完善,通过对称绘图模式可以创建平衡.和谐.独一无二的效果,对称在大自然中随处可见,因此设计元素很可能将依靠于它 ...

  6. EasyRecovery扫描预览功能,助你选择需要的数据恢复

    说到数据恢复,很多人都会选择EasyRecovery,EasyRecovery作为一个功能性还不错的数据恢复软件,能够帮你恢复丢失的数据以及重建文件系统. 在数据恢复的同时,EasyRecovery还 ...

  7. 视频剪辑软件Camtasia的快捷键大全

    今天来给大家介绍一下Camtasia快捷键的相关内容,Camtasia也是一个十分好用的电脑屏幕录制与视频剪辑制作软件了,可能有些朋友用过,毕竟它在视频录制与制作上确实比较好用. 首先在菜单栏中点击& ...

  8. python selenium 时间搜索框查询和日期大小比较

    在做selenium自动化的时候遇到 时间搜索框查询(如下图)并比较查询结果是否在输入的时间之类. 首先,第一步要做的就是选择时间,并获取到所选时间的文本信息 如上图所示,获取到的时间搜索框并没有文本 ...

  9. J2EE基本概念

    XO POJO:Plain Ordinary Java Object,简单java对象 PO:Persistant Object,持久层对象(对应数据库中一条记录) BO:Business Objec ...

  10. java实验作业类的定义与描述

    1 //1三角形的定义与描述 2 package test; 3 4 public class sjx { 5 private double a,b,c; 6 7 public sjx(double ...