Skip to content

Commit 95cb30b

Browse files
author
KevinVenclovas
committed
FIXED CRITICAL ISSUE!
Function returned emty array when datetime difference under MaxDays
1 parent a6b17ae commit 95cb30b

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

Source/FikaAmazonAPI/ReportGeneration/ReportDateRange.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,30 @@ public class ReportDateRange
1010
public ReportDateRange(DateTime startDate, DateTime endDate) { StartDate = startDate; EndDate = endDate;}
1111

1212

13-
public static IList<ReportDateRange> GetDateRange(DateTime startDate,DateTime endDate,int MaxDays)
14-
{
15-
List<ReportDateRange> list=new List<ReportDateRange>();
13+
public static IList<ReportDateRange> GetDateRange(DateTime startDate, DateTime endDate, int MaxDays)
14+
{
15+
List<ReportDateRange> list = new List<ReportDateRange>();
16+
DateTime tempEnd = startDate;
17+
DateTime start = startDate;
1618

17-
double totalDays = (endDate - startDate).TotalDays;
18-
int range = (int)(totalDays / MaxDays);
19-
int remind = (int)(totalDays % MaxDays);
20-
if (remind > 0)
21-
range++;
19+
while (true)
20+
{
21+
tempEnd = tempEnd.AddDays(MaxDays);
22+
if (tempEnd > endDate)
23+
{
24+
tempEnd = endDate;
25+
list.Add(new ReportDateRange(start, tempEnd));
26+
break;
27+
}
28+
else
29+
{
30+
list.Add(new ReportDateRange(start, tempEnd));
31+
start = tempEnd.AddSeconds(1);
32+
}
2233

23-
for (int i = 0; i < range; i++)
24-
{
25-
var newStartDate = startDate.AddDays(i * MaxDays);
26-
var newEndDate = newStartDate.AddDays(MaxDays);
27-
if (i == range - 1)
28-
newEndDate = endDate;
34+
}
2935

30-
list.Add(new ReportDateRange(newStartDate, newEndDate));
31-
}
32-
33-
return list;
36+
return list;
3437
}
3538
}
3639
}

0 commit comments

Comments
 (0)