我正在计算TAT。我有3个参数,例如foreach (DataPoint item in p)
{
if ((xValue < item.XValue) && ((item.XValue - xValue) <= 0.0000009) || (xValue > item.XValue) && ((xValue - item.XValue) <= 0.0000009))
{
sp = DateTime.FromOADate(item.XValue).ToString();
y1 = (int)item.YValues[0];
break;
}
}
,Current Date
和TAT period
List of Holidays(Date).
static List<DateTime> Holidates = new List<DateTime>();
static DateTime StartDate = DateTime.Now;
static void Main(string[] args)
{
Holidates.Add(DateTime.Now.AddDays(20));
Holidates.Add(DateTime.Now.AddDays(10));
Holidates.Add(DateTime.Now.AddDays(3));
TatDueDateCalculator(DateTime.Now, 10, Holidates);
}
private static DateTime TatDueDateCalculator(DateTime AssignDate, int TatPeriod, List<DateTime> Holidays)
{
DateTime dueDate = AssignDate.AddDays(TatPeriod);
int holiDayCount = Holidays.FindAll(x => x >= AssignDate && x <= AssignDate.AddDays(30)).Where(y => dueDate >= AssignDate && dueDate <= y).Count();
if (holiDayCount > 0)
dueDate = dueDate.AddDays(holiDayCount);
return dueDate;
}
需要返回TatDueDateCalculator()
。
以下是几种情况:
dueDate
Holidays
仅包含一个匹配的List<DateTime>Holiday
,但在List中具有更大的值。 例如
dueDate
是DueDate
,“假期列表”包含以下日期。
"2019-05-13"
,"2019-05-10"
,"2019-05-13"
。在这种情况下,我将获得"2019-05-12"
TAT。但预期2
答案 0 :(得分:0)
以下代码产生预期的结果(根据您在注释中的示例)。它还会计算最初在第一个到期日之后的假期。
static void Main(string[] args)
{
var holidays = new List<DateTime>()
{
new DateTime(2019,05,03),
new DateTime(2019,05,04),
new DateTime(2019,05,06),
new DateTime(2019,05,10),
};
int tatPeriod = 5;
var assignDate = new DateTime(2019, 05, 01);
var dueDate = Enumerable.Range(0, tatPeriod + holidays.Count)
.Select(offset => assignDate.AddDays(offset))
.Except(holidays)
.ElementAt(tatPeriod - 1);
Console.WriteLine(dueDate);
Console.Read();
}
答案 1 :(得分:0)
LasseVågsætherKarlsen的回答对我来说很好。
链接: gist.github.com/lassevk/bbee7a626b3126ebb8e59a21ebdcb15b
代码:
nodeForAnchor