c# - 使用 c# 计算开始和停止时钟的总计数
问题描述
在我的应用程序中,我有一个用于发送剩余部分的开始和停止时钟。每当时钟开始和停止时,它将识别开始和停止日期,并将消除所有公共假期和周末。我成功地消除了公共假期和周末。现在我的问题是我需要遍历所有工作日,并且应该确定时钟是从上午还是下午开始,以确定时钟是覆盖一整天还是半天。有一个 Count 变量,初始化为 0.5,每半天后递增(每个 AM 和 PM 之后)。不知道如何在工作日的每半天循环并找到总数。
删除了所有周末和节假日。
public double ElapseDays(string caseNo, string DatePart)
{
double count = 0;
double weekEndsCount;
Boolean excludeWeekends = true;
using (var db = new EMSDEntities())
{
var q = (from a in db.SY_HOLIDAYS
orderby a.HLD_DATE
select new HolidayListViewModel
{
HolidayDate = a.HLD_DATE,
}).ToList();
for (DateTime index = '01/07/2019'; index <= '03/07/2019'; index = index.AddDays(1))
{
bool excluded = false;
if (excludeWeekends && index.DayOfWeek != DayOfWeek.Sunday && index.DayOfWeek != DayOfWeek.Saturday)
{
for (int i = 0; i < q.Count; i++)
{
if (index.Date.CompareTo(q[i].HolidayDate) == 0)
{
excluded = true;
break;
}
}
}
if (!excluded)
{
count = count + 0.5;
}
}
}
}
预期产出
<!DOCTYPE html>
<html>
<body>
<h2>Basic HTML Table</h2>
<table style="width:100%">
<tr>
<th>start_date</th>
<th>end_date</th>
</tr>
<tr>
<td>01/07/2019 PM</td>
<td>03/07/2019 PM</td>
</tr>
</table>
</body>
</html>
计数应为 2.5,因为时钟开始于 (01/07/2019) 下午(半天)。因此它将初始化计数为 0.5 并在 (03/07/2019)PM(full day) 停止
解决方案
推荐阅读
- c# - C# 如何更改程序中的分组?(初学者)
- reactjs - 如何在 Cloud Firestore 中的数组内增加地图中的值?
- c# - 从 DB 读取的变量名称而不是地址(偏移量)
- python - 如何在 Python 中显示最大列宽并写入具有最大宽度的文件?
- javascript - 这个 JS 对象声明语法是什么意思?
- reactjs - 警告应在箭头函数的末尾返回一个值
- amazon-web-services - AWS S3 DeletionPolicy - 创建后添加并验证设置
- matlab - 编程新手,需要一些帮助来理解向量背后的概念
- questdb - 如何通过 REST 对 QuestDB 运行 SQL 查询?
- javascript - 为什么 JavaScript 不能提升初始化?